Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
sort(a,a+n);
int ma=0;
for(int i=0;i<n;++i){
ma=max(ma,a[i]+a[n-i-1]);
}
cout<<ma;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the function <code>countBy</code>
Such that it takes a initial number which is the defualt value of out counter. And returns
a function which also takes a number and returns the initialCount + number supplied to second function.
Ex:-
<code>
const count = countBy(4) // initial value of counter 4, returns a function <br>
console. log(count(2)) // prints 6 because 4 + 2 <br>
console. log(count(-4)) // prints 2 because 6 - 4 <br>
console. log(count(8)) // prints 10 because 2 + 8 <br>
</code>
You have to return implement countBy function such that it can be run like that.<code>countBy</code> will take one number as input which will be the initial count.<code>countBy</code> will return a function which can be run many times and takes a number as input and returns the sum of it with previously maintained counter values<code>
const count = countBy(4) // initial value of counter 4, returns a function <br>
console. log(count(2)) // prints 6 because 4 + 2 <br>
console. log(count(-4)) // prints 2 because 6 - 4 <br>
console. log(count(8)) // prints 10 because 2 + 8 <br>
</code>, I have written this Solution Code: function countBy(initial){
let copy = initial
return (y)=>{
copy += y
return copy
}
// return the output using return keyword
// do not console.log it
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N.
Second line of input contains N space seperated integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000
N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1
2
1 2
Sample Output 1
1
Sample Input 2
4
1 4 2 4
Sample Output 2
5
Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws IOException {
BufferedReader inputMachine = new BufferedReader(new InputStreamReader(System.in));
int length = Integer.parseInt(inputMachine.readLine());
String[] arrText = inputMachine.readLine().trim().split(" ");
int[] nums = new int[length];
for (int i = 0; i < nums.length; i++) {
nums[i] = Integer.parseInt(arrText[i]);
}
Arrays.sort(nums);
int i = 0;
int j = length - 1;
long sum = 0;
while (i < j) {
sum += nums[j] - nums[i];
i++;
j--;
}
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N.
Second line of input contains N space seperated integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000
N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1
2
1 2
Sample Output 1
1
Sample Input 2
4
1 4 2 4
Sample Output 2
5
Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: n = int(input())
arr = list(map(int,input().split()))
arr.sort()
s = 0
for i in range(n//2):
s += arr[n-i-1]-arr[i]
print(s), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N.
Second line of input contains N space seperated integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000
N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1
2
1 2
Sample Output 1
1
Sample Input 2
4
1 4 2 4
Sample Output 2
5
Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
sort(a,a+n);
int ans=0;
for(int i=0;i<n/2;++i){
ans+=abs(a[i]-a[n-i-1]);
}
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: def inv(a,b,m):
res = 1
while(b):
if b&1:
res = (res*a)%m
a = (a*a)%m
b >>= 1
return res
n,x = map(int,input().split())
a = list(map(int,input().split()))
m = 1000000007
for i in a:
x = (x*inv(i,m-2,m))%m
print(x), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
int power_mod(int a,int b,int mod){
int ans = 1;
while(b){
if(b&1)
ans = (ans*a)%mod;
b = b/2;
a = (a*a)%mod;
}
return ans;
}
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int x;
cin>>x;
int mo=1000000007;
int mu=1;
for(int i=0;i<n;++i){
int d;
cin>>d;
mu=(mu*d)%mo;
}
cout<<(x*power_mod(mu,mo-2,mo))%mo;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: import java.io.*;import java.util.*;import java.math.*;
public class Main
{
long mod=1000000007l;int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;
long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;StringBuilder sb;
public void tq()throws Exception
{
st=new StringTokenizer(br.readLine());
int tq=1;
o:
while(tq-->0)
{
int n=i();
long k=l();
long ar[]=arl(n);
long v=1l;
for(long x:ar)v=(v*x)%mod;
v=(k*(mul(v,mod-2,mod)))%mod;
pl(v);
}
}
public static void main(String[] a)throws Exception{new Main().tq();}
int[] so(int ar[]){Integer r[]=new Integer[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
long[] so(long ar[]){Long r[]=new Long[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
char[] so(char ar[])
{Character r[]=new Character[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
void s(String s){sb.append(s);}void s(int s){sb.append(s);}void s(long s){sb.append(s);}
void s(char s){sb.append(s);}void s(double s){sb.append(s);}
void ss(){sb.append(' ');}void sl(String s){sb.append(s);sb.append("\n");}
void sl(int s){sb.append(s);sb.append("\n");}
void sl(long s){sb.append(s);sb.append("\n");}void sl(char s){sb.append(s);sb.append("\n");}
void sl(double s){sb.append(s);sb.append("\n");}void sl(){sb.append("\n");}
int min(int a,int b){return a<b?a:b;}
int min(int a,int b,int c){return a<b?a<c?a:c:b<c?b:c;}
int max(int a,int b){return a>b?a:b;}
int max(int a,int b,int c){return a>b?a>c?a:c:b>c?b:c;}
long min(long a,long b){return a<b?a:b;}
long min(long a,long b,long c){return a<b?a<c?a:c:b<c?b:c;}
long max(long a,long b){return a>b?a:b;}
long max(long a,long b,long c){return a>b?a>c?a:c:b>c?b:c;}
int abs(int a){return Math.abs(a);}
long abs(long a){return Math.abs(a);}
int sq(int a){return (int)Math.sqrt(a);}long sq(long a){return (long)Math.sqrt(a);}
long gcd(long a,long b){return b==0l?a:gcd(b,a%b);}
boolean pa(String s,int i,int j){while(i<j)if(s.charAt(i++)!=s.charAt(j--))return false;return true;}
boolean[] si(int n)
{boolean bo[]=new boolean[n+1];bo[0]=true;bo[1]=true;for(int x=4;x<=n;x+=2)bo[x]=true;
for(int x=3;x*x<=n;x+=2){if(!bo[x]){int vv=(x<<1);for(int y=x*x;y<=n;y+=vv)bo[y]=true;}}
return bo;}long mul(long a,long b,long m)
{long r=1l;a%=m;while(b>0){if((b&1)==1)r=(r*a)%m;b>>=1;a=(a*a)%m;}return r;}
int i()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Integer.parseInt(st.nextToken());}
long l()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Long.parseLong(st.nextToken());}String s()throws IOException
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());return st.nextToken();}
double d()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Double.parseDouble(st.nextToken());}void p(Object p){System.out.print(p);}
void p(String p){System.out.print(p);}void p(int p){System.out.print(p);}
void p(double p){System.out.print(p);}void p(long p){System.out.print(p);}
void p(char p){System.out.print(p);}void p(boolean p){System.out.print(p);}
void pl(Object p){System.out.println(p);}void pl(String p){System.out.println(p);}
void pl(int p){System.out.println(p);}void pl(char p){System.out.println(p);}
void pl(double p){System.out.println(p);}void pl(long p){System.out.println(p);}
void pl(boolean p){System.out.println(p);}void pl(){System.out.println();}
void s(int a[]){for(int e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(long a[]){for(long e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(int ar[][]){for(int a[]:ar){for(int e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}
void s(char a[]){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(char ar[][]){for(char a[]:ar){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}
int[] ari(int n)throws IOException
{int ar[]=new int[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=Integer.parseInt(st.nextToken());return ar;}
int[][] ari(int n,int m)throws IOException
{int ar[][]=new int[n][m];for(int x=0;x<n;x++){if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());}return ar;}
long[] arl(int n)throws IOException
{long ar[]=new long[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++) ar[x]=Long.parseLong(st.nextToken());return ar;}
long[][] arl(int n,int m)throws IOException
{long ar[][]=new long[n][m];for(int x=0;x<n;x++)
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());}return ar;}
String[] ars(int n)throws IOException
{String ar[]=new String[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++) ar[x]=st.nextToken();return ar;}
double[] ard(int n)throws IOException
{double ar[]=new double[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());return ar;}
double[][] ard(int n,int m)throws IOException
{double ar[][]=new double[n][m];for(int x=0;x<n;x++)
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Double.parseDouble(st.nextToken());}return ar;}
char[] arc(int n)throws IOException{char ar[]=new char[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);return ar;}
char[][] arc(int n,int m)throws IOException{char ar[][]=new char[n][m];
for(int x=0;x<n;x++){String s=br.readLine();for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);}return ar;}
void p(int ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(int a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(int ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(int a[]:ar){for(int aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(long ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(long a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(long ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(long a[]:ar){for(long aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(String ar[]){int c=0;for(String s:ar)c+=s.length()+1;StringBuilder sb=new StringBuilder(c);
for(String a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(double ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(double a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(double ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(double a[]:ar){for(double aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(char ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(char aa:ar){sb.append(aa);sb.append(' ');}System.out.println(sb);}
void p(char ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(char a[]:ar){for(char aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: m,n = map(int , input().split())
if (m%n==0):
print("Yes")
else:
print("No");, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,m;
cin>>n>>m;
if(n%m==0)
cout<<"Yes";
else
cout<<"No";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
Long m = sc.nextLong();
if(n%m==0){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc =new Scanner(System.in);
int T= sc.nextInt();
for(int i=0;i<T;i++){
int arrsize=sc.nextInt();
int max=0,secmax=0,thirdmax=0,j;
for(int k=0;k<arrsize;k++){
j=sc.nextInt();
if(j>max){
thirdmax=secmax;
secmax=max;
max=j;
}
else if(j>secmax){
thirdmax=secmax;
secmax=j;
}
else if(j>thirdmax){
thirdmax=j;
}
if(k%10000==0){
System.gc();
}
}
System.out.println(max+" "+secmax+" "+thirdmax+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: t=int(input())
while t>0:
t-=1
n=int(input())
l=list(map(int,input().strip().split()))
li=[0,0,0]
for i in l:
x=i
for j in range(0,3):
y=min(x,li[j])
li[j]=max(x,li[j])
x=y
print(li[0],end=" ")
print(li[1],end=" ")
print(li[2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
vector<long> a(n);
long ans[3]={0};
long x,y;
for(int i=0;i<n;i++){
cin>>a[i];
x=a[i];
for(int j=0;j<3;j++){
y=min(x,ans[j]);
ans[j]=max(x,ans[j]);
// cout<<ans[j]<<" ";
x=y;
}
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
if(ans[2]<ans[1]){
swap(ans[1],ans[2]);
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: function maxNumbers(arr,n) {
// write code here
// do not console.log the answer
// return the answer as an array of 3 numbers
return arr.sort((a,b)=>b-a).slice(0,3)
};
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given is a positive integer N, where none of the digits is 0. Let k be the number of digits in N. We want to make a multiple of 3 by erasing at least 0 and at most k−1 digits from N and concatenating the remaining digits without changing the order. Determine whether it is possible to make a multiple of 3 in this way. If it is possible, find the minimum number of digits that must be erased to make such a number.The input consists of a single integer N.
<b>Constraints</b>
1≤N≤10^18
None of the digits in N is 0.If it is impossible to make a multiple of 3, print -1; otherwise, print the minimum number of digits that must be erased to make such a number.<b>Sample Input 1</b>
35
<b>Sample Output 1</b>
1
<b>Sample Input 2</b>
369
<b>Sample Output 2</b>
0
<b>Sample Input 3</b>
6227384
<b>Sample Output 3</b>
1
<b>Sample Input 4</b>
11
<b>Sample Output 4</b>
-1, I have written this Solution Code: #include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
int main() {
int64_t n;
scanf("%" SCNd64, &n);
int cnt[3] = { 0 };
while (n) {
cnt[n % 10 % 3]++;
n /= 10;
}
int cur = (cnt[1] + 2 * cnt[2]) % 3;
int k = cnt[0] + cnt[1] + cnt[2];
int res;
if (!cur) res = 0;
else if (cur == 1) {
if (cnt[1]) {
if (k == 1) res = -1;
else res = 1;
} else {
if (k == 2) res = -1;
else res = 2;
}
} else {
if (cnt[2]) {
if (k == 1) res = -1;
else res = 1;
} else {
if (k == 2) res = -1;
else res = 2;
}
}
printf("%d\n", res);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, I have written this Solution Code: import java.util.InputMismatchException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
int MAX = (int) 1e5, MOD = (int)1e9+7;
void solve(int TC) {
long n = nl();
long k = nl();
int p = 0;
while(n>0 && n%2==0) {
n/=2;
++p;
}
if(p>=k) {pn(0);return;}
k -= p;
long ans = (k+3L)/4L;
pn(ans);
}
boolean TestCases = false;
public static void main(String[] args) throws Exception { new Main().run(); }
long pow(long a, long b) {
if(b==0 || a==1) return 1;
long o = 1;
for(long p = b; p > 0; p>>=1) {
if((p&1)==1) o = (o*a) % MOD;
a = (a*a) % MOD;
} return o;
}
long inv(long x) {
long o = 1;
for(long p = MOD-2; p > 0; p>>=1) {
if((p&1)==1)o = (o*x)%MOD;
x = (x*x)%MOD;
} return o;
}
long gcd(long a, long b) { return (b==0) ? a : gcd(b,a%b); }
int gcd(int a, int b) { return (b==0) ? a : gcd(b,a%b); }
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
int T = TestCases ? ni() : 1;
for(int t=1;t<=T;t++) solve(t);
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
void p(Object o) { out.print(o); }
void pn(Object o) { out.println(o); }
void pni(Object o) { out.println(o);out.flush(); }
double PI = 3.141592653589793238462643383279502884197169399;
int ni() {
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-') {
minus = true;
b = readByte();
}
while(true) {
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
long nl() {
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-') {
minus = true;
b = readByte();
}
while(true) {
if(b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
double nd() { return Double.parseDouble(ns()); }
char nc() { return (char)skip(); }
int BUF_SIZE = 1024 * 8;
byte[] inbuf = new byte[BUF_SIZE];
int lenbuf = 0, ptrbuf = 0;
int readByte() {
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
} return inbuf[ptrbuf++];
}
boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))) {
sb.appendCodePoint(b); b = readByte();
} return sb.toString();
}
char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
} return n == p ? buf : Arrays.copyOf(buf, p);
}
void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, I have written this Solution Code: [n,k]=[int(j) for j in input().split()]
a=0
while n%2==0:
a+=1
n=n//2
if k>a:
print((k-a-1)//4+1)
else:
print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,k;
cin>>n>>k;
while(k&&n%2==0){
n/=2;
--k;
}
cout<<(k+3)/4;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. The task is to find the square root of N. If N is not a perfect square, then return floor(√N). Try to solve the problem using Binary Search.The first line of input contains the number of test cases T. For each test case, the only line contains the number N.
<b>Constraints:</b>
1 ≤ T ≤ 10000
0 ≤ x ≤ 10<sup>8</sup>For each testcase, print square root of given integer.Sample Input:
2
5
4
Sample Output:
2
2
<b>Explanation:</b.
Testcase 1: Since, 5 is not a perfect square, the floor of square_root of 5 is 2.
Testcase 2: Since 4 is a perfect square, its square root is 2., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int binarySearch( int k,int start,int end) {
int mid = start + (end - start)/2;
if (mid * mid == k) {
return (int) mid;
}
else if ((mid*mid) > end) {
return binarySearch( k, 0, mid - 1);
}
else if ((mid * mid < end)) {
return binarySearch( k, mid + 1, end);
}
else {
mid = (int) Math.sqrt(k);
}
return mid;
}
public static void main (String[] args) throws IOException{
InputStreamReader st = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(st);
int T = Integer.parseInt(br.readLine());
while (T-- > 0) {
int n = Integer.parseInt(br.readLine());
int k = n;
System.out.println(binarySearch( k, 0, n - 1));
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. The task is to find the square root of N. If N is not a perfect square, then return floor(√N). Try to solve the problem using Binary Search.The first line of input contains the number of test cases T. For each test case, the only line contains the number N.
<b>Constraints:</b>
1 ≤ T ≤ 10000
0 ≤ x ≤ 10<sup>8</sup>For each testcase, print square root of given integer.Sample Input:
2
5
4
Sample Output:
2
2
<b>Explanation:</b.
Testcase 1: Since, 5 is not a perfect square, the floor of square_root of 5 is 2.
Testcase 2: Since 4 is a perfect square, its square root is 2., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define ll long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
int sqr(int a) {
int A=a;
if(A<2) return A;
ll l=1,r=A;
ll k=1;
while(l<=r)
{
ll mid=(l+r)/2;
ll u=mid*mid;
if(u<=A)
{
k=max(mid,k);
l=mid+1;
}else
{
r=mid-1;
}
}
return k;
}
signed main()
{
int t;
cin>>t;
while(t>0)
{
t--;
long a;
cin>>a;
long x = sqrt(a);
cout<<x<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. The task is to find the square root of N. If N is not a perfect square, then return floor(√N). Try to solve the problem using Binary Search.The first line of input contains the number of test cases T. For each test case, the only line contains the number N.
<b>Constraints:</b>
1 ≤ T ≤ 10000
0 ≤ x ≤ 10<sup>8</sup>For each testcase, print square root of given integer.Sample Input:
2
5
4
Sample Output:
2
2
<b>Explanation:</b.
Testcase 1: Since, 5 is not a perfect square, the floor of square_root of 5 is 2.
Testcase 2: Since 4 is a perfect square, its square root is 2., I have written this Solution Code: N=int(input())
for i in range(0,N):
M=int(input())
s=M**0.5
print(int(s)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. The task is to find the square root of N. If N is not a perfect square, then return floor(√N). Try to solve the problem using Binary Search.The first line of input contains the number of test cases T. For each test case, the only line contains the number N.
<b>Constraints:</b>
1 ≤ T ≤ 10000
0 ≤ x ≤ 10<sup>8</sup>For each testcase, print square root of given integer.Sample Input:
2
5
4
Sample Output:
2
2
<b>Explanation:</b.
Testcase 1: Since, 5 is not a perfect square, the floor of square_root of 5 is 2.
Testcase 2: Since 4 is a perfect square, its square root is 2., I have written this Solution Code: // n is the input number
function sqrt(n) {
// write code here
// do not console.log
// return the number
return Math.floor(Math.sqrt(n))
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Your task is to implement a stack using an array and perform given queries
<b>Note</b>: Description of each query is given in the <b>input and output format</b>User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>push()</b>:- that takes the integer to be added and the maximum size of the array as a parameter.
<b>pop()</b>:- that takes no parameter.
<b>top()</b> :- that takes no parameter.
Constraints:
1 <= N(number of queries) <= 10<sup>3</sup>During a <b>pop</b> operation if the stack is empty you need to print "<b>Stack underflow</b>",
during <b>push</b> operation, if the maximum size of the array is reached you need to print "<b>Stack overflow</b>", <br> during <b>top</b> operation, you need to print the element which is at the top
if the stack is empty you need to print "<b>Empty stack</b>".
<b>Note</b>:- Each message or element is to be printed on a new line
Sample Input:-
6 3
pop
push 3
push 2
push 4
push 6
top
Sample Output:-
Stack underflow
Stack overflow
4
Explanation:-
Here maximum size of the array is 3, so element 6 can not be added to stack
Sample input:-
8 4
push 2
top
push 4
top
push 6
top
push 8
top
Sample Output:-
2
4
6
8
, I have written this Solution Code: void push(int x,int k)
{
if (top >= k-1) {
System.out.println("Stack overflow");
}
else {
a[++top] = x;
}
}
void pop()
{
if (top < 0) {
System.out.println("Stack underflow");
}
else {
int x = a[top--];
}
}
void top()
{
if (top < 0) {
System.out.println("Empty stack");
}
else {
int x = a[top];
System.out.println(x);
}
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] st = bf.readLine().split(" ");
if(Integer.parseInt(st[1])==0)
System.out.print(-1);
else {
int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1]));
System.out.print(f);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split()
D = int(D)
Q = int(Q)
if(0<=D and Q<=100 and Q >0):
print(int(D/Q))
else:
print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
if(m==0){cout<<-1;return 0;}
cout<<n/m;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a doubly linked list consisting of N nodes and two integers <b>P</b> and <b>K</b>. Your task is to add an element K at the Pth position from the start of the linked list<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>insertnew()</b>. The description of parameters are mentioned below:
<b>head</b>: head node of the double linked list
<b>K</b>: the element which you have to insert
<b>P</b>: the position at which you have insert
Constraints:
1 <= P <=N <= 1000
1 <=K, Node.data<= 1000
In the sample Input N, P and K are in the order as mentioned below:
<b>N P K</b>Return the head of the modified linked list.Sample Input:-
5 3 2
1 3 2 4 5
Sample Output:-
1 3 2 2 4 5, I have written this Solution Code: public static Node insertnew(Node head, int k,int pos) {
int cnt=1;
if(pos==1){Node temp=new Node(k);
temp.next=head;
head.prev=temp;
return temp;}
Node temp=head;
while(cnt!=pos-1){
temp=temp.next;
cnt++;
}
Node x= new Node(k);
x.next=temp.next;
temp.next.prev=x;
temp.next=x;
x.prev=temp;
return head;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string S of length N consisting of lowercase characters 'a' and 'b'. In one operation, you can select a character and make it equal to one of its adjacent characters. For example, if S = "aab", in one operation you can convert it to any of the following:
1. "aab": By changing the 1<sup>st</sup> character to the 2<sup>nd</sup> character.
2. "aab": By changing the 2<sup>nd</sup> character to the 1<sup>st</sup> character.
3. "abb": By changing the 2<sup>nd</sup> character to the 3<sup>rd</sup> character.
4. "aaa": By changing the 3<sup>rd</sup> character to the 2<sup>nd</sup> character.
Find the minimum number of operations to make all the characters in the string equal.The first line of the input contains a single integer N.
The second line contains a string S of length N consisting of only 'a' and 'b'.
<b> Constraints: </b>
1 ≤ N ≤ 5000Print the minimum number of operations to make all the characters in the string equal.Sample Input 1:
4
abaa
Sample Output 1:
1
Sample Explanation 1:
You can replace the 'b' at the second position by the 'a' at the first position. Now the string becomes "aaaa".
Sample Input 2:
5
bbbaa
Sample Output 2:
2
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int c = 0;
String str = br.readLine();
for(int i=0;i<n;i++){
if(str.charAt(i) == 'a'){
c++;
}
}
if((n-c)<c){
System.out.println(n-c);
}else{
System.out.println(c);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string S of length N consisting of lowercase characters 'a' and 'b'. In one operation, you can select a character and make it equal to one of its adjacent characters. For example, if S = "aab", in one operation you can convert it to any of the following:
1. "aab": By changing the 1<sup>st</sup> character to the 2<sup>nd</sup> character.
2. "aab": By changing the 2<sup>nd</sup> character to the 1<sup>st</sup> character.
3. "abb": By changing the 2<sup>nd</sup> character to the 3<sup>rd</sup> character.
4. "aaa": By changing the 3<sup>rd</sup> character to the 2<sup>nd</sup> character.
Find the minimum number of operations to make all the characters in the string equal.The first line of the input contains a single integer N.
The second line contains a string S of length N consisting of only 'a' and 'b'.
<b> Constraints: </b>
1 ≤ N ≤ 5000Print the minimum number of operations to make all the characters in the string equal.Sample Input 1:
4
abaa
Sample Output 1:
1
Sample Explanation 1:
You can replace the 'b' at the second position by the 'a' at the first position. Now the string becomes "aaaa".
Sample Input 2:
5
bbbaa
Sample Output 2:
2
, I have written this Solution Code: input()
s = input()
a = s.count("a")
b = s.count("b")
print(a if a<b else b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string S of length N consisting of lowercase characters 'a' and 'b'. In one operation, you can select a character and make it equal to one of its adjacent characters. For example, if S = "aab", in one operation you can convert it to any of the following:
1. "aab": By changing the 1<sup>st</sup> character to the 2<sup>nd</sup> character.
2. "aab": By changing the 2<sup>nd</sup> character to the 1<sup>st</sup> character.
3. "abb": By changing the 2<sup>nd</sup> character to the 3<sup>rd</sup> character.
4. "aaa": By changing the 3<sup>rd</sup> character to the 2<sup>nd</sup> character.
Find the minimum number of operations to make all the characters in the string equal.The first line of the input contains a single integer N.
The second line contains a string S of length N consisting of only 'a' and 'b'.
<b> Constraints: </b>
1 ≤ N ≤ 5000Print the minimum number of operations to make all the characters in the string equal.Sample Input 1:
4
abaa
Sample Output 1:
1
Sample Explanation 1:
You can replace the 'b' at the second position by the 'a' at the first position. Now the string becomes "aaaa".
Sample Input 2:
5
bbbaa
Sample Output 2:
2
, I have written this Solution Code: //Author: Xzirium
//Time and Date: 03:04:29 27 December 2021
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t clk;
clk = clock();
//-----------------------------------------------------------------------------------------------------------//
READV(N);
string S;
cin>>S;
ll a=0,b=0;
FORI(i,0,N)
{
if(S[i]=='a')
{
a++;
}
else
{
b++;
}
}
cout<<min(a,b)<<endl;
//-----------------------------------------------------------------------------------------------------------//
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code:
function mul (x) {
return function (y) { // anonymous function
return function (z) { // anonymous function
console.log(x*y*z);
};
};
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.println(a*b*c);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code: x,y,z= map(int,input().split())
print(x*y*z), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a series and a number N, your task is to print the Nth number of the given series.
Series:- 24, 37, 50, 63, 76,. .. .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>NthNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the Nth number.Sample Input:-
1
Sample Output:-
24
Sample Input:-
3
Sample Output:-
50, I have written this Solution Code: int NthNumber(int N){
return 24+(N-1)*13;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a series and a number N, your task is to print the Nth number of the given series.
Series:- 24, 37, 50, 63, 76,. .. .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>NthNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the Nth number.Sample Input:-
1
Sample Output:-
24
Sample Input:-
3
Sample Output:-
50, I have written this Solution Code: int NthNumber(int N){
return 24+(N-1)*13;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a series and a number N, your task is to print the Nth number of the given series.
Series:- 24, 37, 50, 63, 76,. .. .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>NthNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the Nth number.Sample Input:-
1
Sample Output:-
24
Sample Input:-
3
Sample Output:-
50, I have written this Solution Code: def NthNumber(N):
return 24+(N-1)*13
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a series and a number N, your task is to print the Nth number of the given series.
Series:- 24, 37, 50, 63, 76,. .. .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>NthNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the Nth number.Sample Input:-
1
Sample Output:-
24
Sample Input:-
3
Sample Output:-
50, I have written this Solution Code: static int NthNumber(int N){
return 24+(N-1)*13;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones.
Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy.
The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items
<b>Constraints:</b>
1 <= N <= 100000
1 <= K <= N - 2
1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input:
5 2
4 1 2 3 5
Sample Output:
7
Explanation:
Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3.
Sample Input:
10 8
99 56 50 93 47 36 65 25 87 16
Sample Output:
533, I have written this Solution Code: function supermarket(prices, n, k) {
// write code here
// do not console.log the answer
// return sorted array
const newPrices = prices.sort((a, b) => a - b).slice(2)
let kk = k
let price = 0;
let i = 0
while (kk-- && i < newPrices.length) {
price += newPrices[i]
i += 1
}
return price
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones.
Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy.
The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items
<b>Constraints:</b>
1 <= N <= 100000
1 <= K <= N - 2
1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input:
5 2
4 1 2 3 5
Sample Output:
7
Explanation:
Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3.
Sample Input:
10 8
99 56 50 93 47 36 65 25 87 16
Sample Output:
533, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str[]= br.readLine().trim().split(" ");
int n=Integer.parseInt(str[0]);
int k=Integer.parseInt(str[1]);
str= br.readLine().trim().split(" ");
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=Integer.parseInt(str[i]);
Arrays.sort(arr);
long sum=0;
for(int i=2;i<k+2;i++)
sum+=arr[i];
System.out.print(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones.
Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy.
The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items
<b>Constraints:</b>
1 <= N <= 100000
1 <= K <= N - 2
1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input:
5 2
4 1 2 3 5
Sample Output:
7
Explanation:
Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3.
Sample Input:
10 8
99 56 50 93 47 36 65 25 87 16
Sample Output:
533, I have written this Solution Code: a=input().split()
for i in range(len(a)):
a[i]=int(a[i])
b=input().split()
for i in range(len(b)):
b[i]=int(b[i])
b.sort()
b.reverse()
b.pop()
b.pop()
s=0
while a[1]>0:
s+=b.pop()
a[1]-=1
print(s), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones.
Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy.
The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items
<b>Constraints:</b>
1 <= N <= 100000
1 <= K <= N - 2
1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input:
5 2
4 1 2 3 5
Sample Output:
7
Explanation:
Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3.
Sample Input:
10 8
99 56 50 93 47 36 65 25 87 16
Sample Output:
533, I have written this Solution Code: #include<bits/stdc++.h>
#define int long long
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<int,int>
#define vi vector<int>
#define all(a) (a).begin(),(a).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define hell 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
void solve(){
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
int ans = 0;
for(int i = 3; i <= 2 + k; i++)
ans += a[i];
cout << ans << endl;
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: ";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: n = int(input())
if (n%4==0 and n%100!=0 or n%400==0):
print("YES")
elif n==0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int n = scanner.nextInt();
LeapYear(n);
}
static void LeapYear(int year){
if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");}
else {
System.out.println("NO");}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: def compound_interest(principle, rate, time):
Amount = principle * (pow((1 + rate / 100), time))
CI = Amount - principle
print( '%.2f'%CI)
principle,rate,time=map(int, input().split())
compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: function calculateCI(P, R, T)
{
let interest = P * (Math.pow(1.0 + R/100.0, T) - 1);
return interest.toFixed(2);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int p,r,t;
cin>>p>>r>>t;
double rate= (float)r/100;
double amt = (float)p*(pow(1+rate,t));
cout << fixed << setprecision(2) << (amt - p);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s= br.readLine().split(" ");
double[] darr = new double[s.length];
for(int i=0;i<s.length;i++){
darr[i] = Double.parseDouble(s[i]);
}
double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0];
System.out.printf("%.2f",ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: str1 = input()
str2 = ''
for i in range(len(str1)):
if(i % 2 == 0):
str2 = str2 + str1[i]+" "
print(str2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String s = sc.next();
for(int i = 0;i<s.length();i++){
if(i%2==0){
System.out.print(s.charAt(i)+" ");
}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: // str is input
function oddChars(str) {
// write code here
// do not console.log
// return the output as a string
return str.split('').filter((v,idx)=> idx % 2 === 0).join(' ')
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
for(int i=0;i<s.length();i++){
if(!(i&1)){cout<<s[i]<<" ";}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: a="Hello World"
print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
System.out.println("Hello World");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to find the count of repeated elements. Print the repeated elements in ascending order along with their frequency.
Have a look at the example for more understanding.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000For each duplicate element in sorted order in a new line, First, print the duplicate element and then print its number of occurence space- separated.
Note:- It is guaranteed that at least one duplicate element will exist in the given array.Sample Input:-
5
3 2 1 1 2
Sample Output:-
1 2
2 2
Sample Input:-
5
1 1 1 1 5
Sample Output:-
1 4
Explaination:
test 1: Only 1 and 2 are repeated. Both are repeated twice. So, we print:
1 -> frequency of 1
2 -> frequency of 2
1 is printed before 2 as it is smaller than 2, I have written this Solution Code: import numpy as np
from collections import defaultdict
n=int(input())
a=np.array([input().strip().split()],int).flatten()
d=defaultdict(int)
for i in a:
d[i]+=1
d=sorted(d.items())
for i in d:
if(i[1]>1):
print(i[0],end=" ")
print(i[1])
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to find the count of repeated elements. Print the repeated elements in ascending order along with their frequency.
Have a look at the example for more understanding.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000For each duplicate element in sorted order in a new line, First, print the duplicate element and then print its number of occurence space- separated.
Note:- It is guaranteed that at least one duplicate element will exist in the given array.Sample Input:-
5
3 2 1 1 2
Sample Output:-
1 2
2 2
Sample Input:-
5
1 1 1 1 5
Sample Output:-
1 4
Explaination:
test 1: Only 1 and 2 are repeated. Both are repeated twice. So, we print:
1 -> frequency of 1
2 -> frequency of 2
1 is printed before 2 as it is smaller than 2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int noOfElements = Integer.parseInt(in.readLine());
String [] elem = in.readLine().trim().split(" ");
int [] elements = new int [noOfElements];
for(int i=0 ; i< noOfElements; i++){
elements[i] = Integer.parseInt(elem[i]);
}
Arrays.sort(elements);
int count =0;
for(int i = 0 ; i < noOfElements-1 ; i++){
if(elements[i] == elements[i+1]){
count ++;
}
else if(count != 0){
System.out.print(elements[i]+" "+(count+1));
count =0;
System.out.println();
}
}
if(count != 0)
System.out.print(elements[noOfElements-1]+" "+(count+1));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to find the count of repeated elements. Print the repeated elements in ascending order along with their frequency.
Have a look at the example for more understanding.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000For each duplicate element in sorted order in a new line, First, print the duplicate element and then print its number of occurence space- separated.
Note:- It is guaranteed that at least one duplicate element will exist in the given array.Sample Input:-
5
3 2 1 1 2
Sample Output:-
1 2
2 2
Sample Input:-
5
1 1 1 1 5
Sample Output:-
1 4
Explaination:
test 1: Only 1 and 2 are repeated. Both are repeated twice. So, we print:
1 -> frequency of 1
2 -> frequency of 2
1 is printed before 2 as it is smaller than 2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin>>n;
int a[n];
map<int,int> m;
for(int i=0;i<n;i++){
cin>>a[i];
m[a[i]]++;
}
for(auto it = m.begin();it!=m.end();it++){
if(it->second>1){
cout<<it->first<<" "<<it->second<<'\n';
}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: def firstTwo(N):
while(N>99):
N=N//10
return (N%10)*10 + N//10
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: static int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a doubly linked list consisting of N nodes and two integers <b>P</b> and <b>K</b>. Your task is to add an element K at the Pth position from the start of the linked list<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>insertnew()</b>. The description of parameters are mentioned below:
<b>head</b>: head node of the double linked list
<b>K</b>: the element which you have to insert
<b>P</b>: the position at which you have insert
Constraints:
1 <= P <=N <= 1000
1 <=K, Node.data<= 1000
In the sample Input N, P and K are in the order as mentioned below:
<b>N P K</b>Return the head of the modified linked list.Sample Input:-
5 3 2
1 3 2 4 5
Sample Output:-
1 3 2 2 4 5, I have written this Solution Code: public static Node insertnew(Node head, int k,int pos) {
int cnt=1;
if(pos==1){Node temp=new Node(k);
temp.next=head;
head.prev=temp;
return temp;}
Node temp=head;
while(cnt!=pos-1){
temp=temp.next;
cnt++;
}
Node x= new Node(k);
x.next=temp.next;
temp.next.prev=x;
temp.next=x;
x.prev=temp;
return head;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A (distinct integers) of size N, and you are also given a sum. You need to find if two numbers in A exists that have sum equal to the given sum.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains N denoting the size of the array A and target sum. The second line contains N elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= sum <= 10^5
1 <= A[i] <= 10^4For each testcase, in a new line, print "1"(without quotes) if any pair found, othwerwise print "0"(without quotes) if not found.Sample Input
2
10 14
1 2 3 4 5 6 7 8 9 10
2 10
2 5
Sample Output
1
0
Explanation:
Testcase 1: arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and sum = 14. There is a pair {4, 10} with sum 14.
Testcase 2: arr[] = {2, 5} and sum = 10. There is no pair with sum 10., I have written this Solution Code: import numpy as np
from collections import defaultdict
t=int(input())
def solve():
d=defaultdict(int)
n,s=input().strip().split()
s=int(s)
a=np.array([input().strip().split()],int).flatten()
for i in a:
d[i]+=1
c=0
for i in a:
if(d[s-i]>0 and (s-i)!=i):
c=1
break
print(c)
while(t>0):
solve()
t-=1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A (distinct integers) of size N, and you are also given a sum. You need to find if two numbers in A exists that have sum equal to the given sum.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains N denoting the size of the array A and target sum. The second line contains N elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= sum <= 10^5
1 <= A[i] <= 10^4For each testcase, in a new line, print "1"(without quotes) if any pair found, othwerwise print "0"(without quotes) if not found.Sample Input
2
10 14
1 2 3 4 5 6 7 8 9 10
2 10
2 5
Sample Output
1
0
Explanation:
Testcase 1: arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and sum = 14. There is a pair {4, 10} with sum 14.
Testcase 2: arr[] = {2, 5} and sum = 10. There is no pair with sum 10., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
signed main()
{
int t;
cin>>t;
while(t>0)
{ t--;
int ch=0;
int n,sum;
cin>>n>>sum;
int A[n];
set<int> ss;
for(int i=0;i<n;i++)
{
cin>>A[i];
if(ss.find(sum-A[i])!=ss.end()) ch=1;
ss.insert(A[i]);
}
cout<<ch<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A (distinct integers) of size N, and you are also given a sum. You need to find if two numbers in A exists that have sum equal to the given sum.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains N denoting the size of the array A and target sum. The second line contains N elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= sum <= 10^5
1 <= A[i] <= 10^4For each testcase, in a new line, print "1"(without quotes) if any pair found, othwerwise print "0"(without quotes) if not found.Sample Input
2
10 14
1 2 3 4 5 6 7 8 9 10
2 10
2 5
Sample Output
1
0
Explanation:
Testcase 1: arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and sum = 14. There is a pair {4, 10} with sum 14.
Testcase 2: arr[] = {2, 5} and sum = 10. There is no pair with sum 10., I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt();
for(int i = 1; i <= testCases; i++)
{
int arrSize = sc.nextInt();
int sum = sc.nextInt();
int arr[] = new int[arrSize];
for(int j = 0; j < arrSize; j++)
arr[j] = sc.nextInt();
System.out.println(pairFound(arr, arrSize, sum));
}
}
static int pairFound(int arr[], int arrSize, int sum)
{
HashSet<Integer> hSet = new HashSet<>();
for(int i = 0; i < arrSize; i++)
{
if(hSet.contains(sum-arr[i]) == true)
return 1;
hSet.add(arr[i]);
}
return 0;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N in decimal form, you have to cyclically rotate left the binary representation of number N in 31 bit, you get the maximum number that can be formed.
Note:- All the leftover bits in binary representation of N are filled with zeroes i.e binary representation of 4 will be :- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0The input contains T, denoting the number of testcases. Each testcase contains a number <b>N</b>.
Constraints:
1 <= T <= 100
1 <= N <= (2^32)-1For each testcase in new line print the maximum number formed.Input:
2
1
0
Output:
2147483648
0
Explanation:
Test case 1:- The binary representation of 1 is 0 0 0 . . . . . 1 when we make a cyclic shift to the left the number will become 1 0 0 0 0.......... 0 0 0 0. which is the maximum number that can be formed.
Test case 2:- The binary representation of 0 is 0, even if we left shift its binary numbers we still get 0 for that., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static final int BITS =32;
public static void main (String[] args) {
Scanner sc =new Scanner(System.in);
int t = sc.nextInt();
for(int i=1;i<=t;i++){
int number = sc.nextInt();
long ans = shifted(number);
System.out.println(ans);
}
}
public static long shifted(int n){
long m =n;
long max = n;
for(int i=1;i<=32;i++){
m=(n << i) | (n >>(BITS-i));
if(m>max){
max = m;
}
}
return max*2;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N in decimal form, you have to cyclically rotate left the binary representation of number N in 31 bit, you get the maximum number that can be formed.
Note:- All the leftover bits in binary representation of N are filled with zeroes i.e binary representation of 4 will be :- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0The input contains T, denoting the number of testcases. Each testcase contains a number <b>N</b>.
Constraints:
1 <= T <= 100
1 <= N <= (2^32)-1For each testcase in new line print the maximum number formed.Input:
2
1
0
Output:
2147483648
0
Explanation:
Test case 1:- The binary representation of 1 is 0 0 0 . . . . . 1 when we make a cyclic shift to the left the number will become 1 0 0 0 0.......... 0 0 0 0. which is the maximum number that can be formed.
Test case 2:- The binary representation of 0 is 0, even if we left shift its binary numbers we still get 0 for that., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
signed main()
{
int t;
cin>>t;
int P[50];
P[0]=1;
for(int i=1;i<=35;i++)
{
P[i]=P[i-1]*2LL;
}
while(t>0)
{
t--;
deque<int> ss;
int n;
cin>>n;
for(int i=0;i<32;i++)
{
int p=n%2LL;
ss.pu(p);
n/=2LL;
}
int ans=0;
for(int i=0;i<32;i++)
{
int p=0;
for(int j=0;j<32;j++)
{
p+=P[j]*ss[j];
}
ans=max(ans,p);
ss.push_front(ss[31]);
ss.pop_back();
}
cout<<ans<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In a pascal triangle starting from top to bottom. Find the value of the element in a given row and column position i.e. ith row and at jth position.The first line of input contains an integer T denoting the number of test cases. Each test case will have two integers indexes of the ith row and jth column provided in the new line.
Constraints:
1 <= T <= 100
0 <= j <= i <= 500
Print the answer for each testcase in separated line. Since the output can be very large, mod your output by 10^9+7.Input:
2
0 0
2 1
Output:
1
2
Explanation: The Pascal Triangle has first value as 1. (0th row 0th element). The pascal triangle has next set of values as 1 1. (1th row). On the next level, pascal triangle has values 1 2 1. (2nd row). Its 1st element is 2. (0 based)., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
int T=Integer.parseInt(br.readLine());
for(int k=0;k<T;k++){
String[] str=br.readLine().split(" ");
int i=Integer.parseInt(str[0]);
int j=Integer.parseInt(str[1]);
System.out.print(nCr(i,j));
System.out.println();
}
}
public static long fact(int n){
long mul=1;
int m=1000000007;
for(int i=1;i<=n;i++){
mul=((mul%m)*i%m)%m;
}
return mul;
}
public static long nCr(int n,int r){
int m=1000000007;
long mul=(fact(r)%m*fact(n-r)%m)%m;
return ((long)((fact(n)%m)*(pow(mul,m-2,m)%m))%m);
}
public static long pow(long a,long b,long m){
long res=1;
while(b>0){
if(b%2!=0)
res=(long)((res*(a%m))%m);
a=((a%m)*(a%m))%m;
b=b>>1;
}
return res;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In a pascal triangle starting from top to bottom. Find the value of the element in a given row and column position i.e. ith row and at jth position.The first line of input contains an integer T denoting the number of test cases. Each test case will have two integers indexes of the ith row and jth column provided in the new line.
Constraints:
1 <= T <= 100
0 <= j <= i <= 500
Print the answer for each testcase in separated line. Since the output can be very large, mod your output by 10^9+7.Input:
2
0 0
2 1
Output:
1
2
Explanation: The Pascal Triangle has first value as 1. (0th row 0th element). The pascal triangle has next set of values as 1 1. (1th row). On the next level, pascal triangle has values 1 2 1. (2nd row). Its 1st element is 2. (0 based)., I have written this Solution Code:
t = int(input())
mod = 10**9 + 7
while (t > 0):
n,k = map(int,input().split())
factOfRow = 1
factOfCol = 1
factRowMinusCol = 1
for i in range(1,n+1):
factOfRow *= i
for i in range(1,k+1):
factOfCol *= i
for i in range(1,n - k+1):
factRowMinusCol *= i
fact = factOfRow // (factOfCol * factRowMinusCol)
print(fact %mod)
t = t -1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In a pascal triangle starting from top to bottom. Find the value of the element in a given row and column position i.e. ith row and at jth position.The first line of input contains an integer T denoting the number of test cases. Each test case will have two integers indexes of the ith row and jth column provided in the new line.
Constraints:
1 <= T <= 100
0 <= j <= i <= 500
Print the answer for each testcase in separated line. Since the output can be very large, mod your output by 10^9+7.Input:
2
0 0
2 1
Output:
1
2
Explanation: The Pascal Triangle has first value as 1. (0th row 0th element). The pascal triangle has next set of values as 1 1. (1th row). On the next level, pascal triangle has values 1 2 1. (2nd row). Its 1st element is 2. (0 based)., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int modInverse(long long a, long long m)
{
long m0 = m;
long y = 0, x = 1;
while (a > 1)
{
int q = a / m;
int t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x += m0;
return x;
}
int main()
{
long long mod=1000000007;
int t;
cin>>t;
while(t--){
int i,j;
cin>>i>>j;
i++;j++;
long long C=1;
long long x=1;
for (int p = 1; p < j; p++)
{
C = C * (i - p);
x=x*p;
C=C%mod;
x=x%mod;
}
C=C*modInverse(x,mod);
C=C%mod;
cout<<C<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character ‘*’ draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int M=sc.nextInt();
int N=sc.nextInt();
for(int col=0;col<N;col++){
System.out.print("*");
}
System.out.println();
for(int row=0;row<M-2;row++){
System.out.print("*");
for(int col=0;col<N-2;col++){
System.out.print(" ");
}
System.out.print("*");
System.out.println();
}
for(int col=0;col<N;col++){
System.out.print("*");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character ‘*’ draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, I have written this Solution Code: li = list(map(int,input().strip().split()))
m=li[0]
n=li[1]
for i in range(0,n):
if i==n-1:
print("*",end="\n")
else:
print("*",end="")
for i in range(1,m-1):
print("*",end="")
for j in range(0,n-2):
print(" ",end="")
print("*",end="\n")
for i in range(0,n):
print("*",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character ‘*’ draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int m,n;
cin>>m>>n;
for(int i=0;i<n;i++){
cout<<'*';
}
cout<<endl;
m-=2;
while(m--){
cout<<'*';
for(int i=0;i<n-2;i++){
cout<<' ';
}
cout<<'*'<<endl;
}
for(int i=0;i<n;i++){
cout<<'*';
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an input stream of n integers, find the kth largest element for each element in the stream.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow.
Each test case contains two lines. The first line of each test case contains two space-separated integers n and k. Then in the next line are n space-separated values of the array.
Constraints:
1 <= T <= 100
1 <= n <= 10^3
1 <= K <= n
1 <= stream[i] <= 10^5For each test case, in a new line, print the space separated values denoting the kth largest element at each insertion, if the kth largest element at a particular insertion in the stream doesn't exist print -1.Sample Input:
2
6 4
1 2 3 4 5 6
2 1
3 4
Sample Output:
-1 -1 -1 1 2 3
3 4
Explanation:
Testcase1:
k = 4
For 1, the 4th largest element doesn't exist so we print -1.
For 2, the 4th largest element doesn't exist so we print -1.
For 3, the 4th largest element doesn't exist so we print -1.
For 4, the 4th largest element is 1 {1, 2, 3, 4}
For 5, the 4th largest element is 2 {2, 3, 4 ,5}
for 6, the 4th largest element is 3 {3, 4, 5}, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t>0){
String arr[]=br.readLine().split("\\s+");
int n=Integer.parseInt(arr[0]);
int k=Integer.parseInt(arr[1]);
String nums[]=br.readLine().split("\\s+");
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
for(int i=0;i<n;i++){
int curr=Integer.parseInt(nums[i]);
if(pq.size()<k){
pq.add(curr);
}
else{
if(curr>pq.peek()){
pq.remove();
pq.add(curr);
}
}
if(pq.size()==k){
System.out.print(pq.peek()+" ");
}
else{
System.out.print("-1"+" ");
}
}
t--;
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an input stream of n integers, find the kth largest element for each element in the stream.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow.
Each test case contains two lines. The first line of each test case contains two space-separated integers n and k. Then in the next line are n space-separated values of the array.
Constraints:
1 <= T <= 100
1 <= n <= 10^3
1 <= K <= n
1 <= stream[i] <= 10^5For each test case, in a new line, print the space separated values denoting the kth largest element at each insertion, if the kth largest element at a particular insertion in the stream doesn't exist print -1.Sample Input:
2
6 4
1 2 3 4 5 6
2 1
3 4
Sample Output:
-1 -1 -1 1 2 3
3 4
Explanation:
Testcase1:
k = 4
For 1, the 4th largest element doesn't exist so we print -1.
For 2, the 4th largest element doesn't exist so we print -1.
For 3, the 4th largest element doesn't exist so we print -1.
For 4, the 4th largest element is 1 {1, 2, 3, 4}
For 5, the 4th largest element is 2 {2, 3, 4 ,5}
for 6, the 4th largest element is 3 {3, 4, 5}, I have written this Solution Code: from heapq import heappop,heappush,heapify
t = int(input())
for _ in range(t):
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
heap = []
heapify(heap)
for i in arr:
heappush(heap,i)
if len(heap) < k:
print("-1",end=" ")
if len(heap) > k:
heappop(heap)
if len(heap) == k:
print(heap[0],end= " ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an input stream of n integers, find the kth largest element for each element in the stream.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow.
Each test case contains two lines. The first line of each test case contains two space-separated integers n and k. Then in the next line are n space-separated values of the array.
Constraints:
1 <= T <= 100
1 <= n <= 10^3
1 <= K <= n
1 <= stream[i] <= 10^5For each test case, in a new line, print the space separated values denoting the kth largest element at each insertion, if the kth largest element at a particular insertion in the stream doesn't exist print -1.Sample Input:
2
6 4
1 2 3 4 5 6
2 1
3 4
Sample Output:
-1 -1 -1 1 2 3
3 4
Explanation:
Testcase1:
k = 4
For 1, the 4th largest element doesn't exist so we print -1.
For 2, the 4th largest element doesn't exist so we print -1.
For 3, the 4th largest element doesn't exist so we print -1.
For 4, the 4th largest element is 1 {1, 2, 3, 4}
For 5, the 4th largest element is 2 {2, 3, 4 ,5}
for 6, the 4th largest element is 3 {3, 4, 5}, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define max1 1000008
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void solve(){
priority_queue<int> pq;
int n,k;
cin>>n>>k;
int x;
int cnt=1;
FOR(i,n){
cin>>x;
x=-x;
if(cnt<k){out1(-1);pq.push(x);cnt++;continue;}
else{
if(cnt==k){pq.push(x);out1(-pq.top());cnt++;continue;}
if(x<pq.top()){
pq.pop();
pq.push(x);
}
out1(-pq.top());
}
}
}
int main() {
fast();
int t;
cin>>t;
while(t--){
solve();
cout<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement <code>createUserObj</code> which takes two arguments, email and password
and the funtion returns and object with key email and value as email argument and key password
and value as password.Function will take two arguments.Function will return object with keys email and passwordconst obj = createUserObj("akshat. sethi@newtonschool. co", "123456")
console. log(obj) // prints {email:"akshat. sethi@newtonschool. co", password:"123456"}, I have written this Solution Code: function createUserObj(email,password){
return {email,password}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram has recently purchased an empty rectangular grid of NxM dimension. He wants to fill the grid but in a special way. His way of filling is, He choose any block which is not filled yet and fills it and the points obtained in particular step is the number of filled neighbouring block. Neighbour block denotes the block which shares some common side between them. When Ram fills all the blocks then he will stop and calculate the total number of points. Ram wants to know the maximum points he can get?The first line of the input contains a single Integer T, denoting number of test cases.
The next T lines contains two space separated integer N, M i.e dimensions of grid.
<b>Constraints</b>
1 ≤ T ≤ 100
1 ≤ N, M ≤ 1000Print the maximum number of points Ram can get.Sample Input
1
2 2
Sample Output
4
Explanation
Ram can obtain total score 4 in the following way.
First he filled top right block, point = 0;
Then he filled bottom left block, point = 0;
Then when he fill either top left and bottom right, the points obtained in both the cases will be 2 hence maximum 4 points are possible., I have written this Solution Code: t = int(input())
for _ in range(t):
a, b = list(map(int, input().split()))
count = 0
count+= 2*(a-1)*(b-1)
count+= b-1
count+= a-1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram has recently purchased an empty rectangular grid of NxM dimension. He wants to fill the grid but in a special way. His way of filling is, He choose any block which is not filled yet and fills it and the points obtained in particular step is the number of filled neighbouring block. Neighbour block denotes the block which shares some common side between them. When Ram fills all the blocks then he will stop and calculate the total number of points. Ram wants to know the maximum points he can get?The first line of the input contains a single Integer T, denoting number of test cases.
The next T lines contains two space separated integer N, M i.e dimensions of grid.
<b>Constraints</b>
1 ≤ T ≤ 100
1 ≤ N, M ≤ 1000Print the maximum number of points Ram can get.Sample Input
1
2 2
Sample Output
4
Explanation
Ram can obtain total score 4 in the following way.
First he filled top right block, point = 0;
Then he filled bottom left block, point = 0;
Then when he fill either top left and bottom right, the points obtained in both the cases will be 2 hence maximum 4 points are possible., I have written this Solution Code: /**
* author: tourist1256
* created: 2022-06-24 16:26:02
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
#define int long long
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) {
uniform_int_distribution<int64_t> generator(l, r);
return generator(rng);
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n, m;
cin >> n >> m;
int array[n][m];
array[0][0] = 1;
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i > 0 && array[i - 1][j] == 1) {
ans++;
}
if (j > 0 && array[i][j - 1] == 1) {
ans++;
}
array[i][j] = 1;
}
}
cout << ans << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram has recently purchased an empty rectangular grid of NxM dimension. He wants to fill the grid but in a special way. His way of filling is, He choose any block which is not filled yet and fills it and the points obtained in particular step is the number of filled neighbouring block. Neighbour block denotes the block which shares some common side between them. When Ram fills all the blocks then he will stop and calculate the total number of points. Ram wants to know the maximum points he can get?The first line of the input contains a single Integer T, denoting number of test cases.
The next T lines contains two space separated integer N, M i.e dimensions of grid.
<b>Constraints</b>
1 ≤ T ≤ 100
1 ≤ N, M ≤ 1000Print the maximum number of points Ram can get.Sample Input
1
2 2
Sample Output
4
Explanation
Ram can obtain total score 4 in the following way.
First he filled top right block, point = 0;
Then he filled bottom left block, point = 0;
Then when he fill either top left and bottom right, the points obtained in both the cases will be 2 hence maximum 4 points are possible., I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static boolean prime[]= new boolean[10000001];
public static void sieve()
{
for(int i=0;i<=10000000;i++)
prime[i] = true;
prime[0] = prime[1] = false;
for(int p = 2; p*p <=10000000; p++)
{
// If prime[p] is not changed, then it is a prime
if(prime[p] == true)
{
// Update all multiples of p
for(int i = p*p; i <= 10000000; i += p)
prime[i] = false;
}
}
}
static ArrayList<Integer> primeFactors(int n)
{
ArrayList<Integer> pflist=new ArrayList<>();
int c = 2;
while (n > 1) {
if (n % c == 0) {
pflist.add(c);
n /= c;
}
else
c++;
}
return pflist;
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
FastReader sc = new FastReader();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int cases = sc.nextInt();
//sieve();
while(cases-->0)
{
int n=sc.nextInt();
int m=sc.nextInt();
out.write((2*m*n-m-n)+"\n");
}
out.flush();
}
public static void reverse(int[] array)
{
int n=array.length;
for(int i=0;i<n/2;i++)
{
int temp=array[i];
array[i]=array[n-i-1];
array[n-i-1]=temp;
}
}
}
class Pair implements Comparable<Pair> {
int first,second;
public Pair(int first,int second)
{
this.first =first;
this.second=second;
}
public int compareTo(Pair b)
{
//first element in descending order
if (this.first!=b.first)
return (this.first>b.first)?-1:1;
else
return this.second<b.second?-1:1;
//second element in incresing order
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two strings S and T of the same length, you can rearrange the characters in S and T. Your task is to find if it is possible to rearrange S and T such that S is lexicographically smaller than T.The first line of input contains the string S. The next line of input contains the string T.
Constraints:-
1 <= |S| = |T| <= 100000
Note:- Both the string will contain only lowercase english letters.Print "YES" if it is possible to rearrange S and T such that S is lexicographically smaller than T else print "NO".Sample Input:-
school
newton
Sample Output:-
YES
Explanation:-
One of the possible rearrangements:- cshool < newton
Sample Input:-
efgh
abcd
Sample Output:-
NO, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc= new Scanner(System.in);
String str = sc.next();
String s= sc.next();
char min= str.charAt(0);
for(int i=0;i<str.length();i++){
if(str.charAt(i)<min){
min= str.charAt(i);
}
}
char max= s.charAt(0);
for(int i=0;i<s.length();i++){
if(s.charAt(i)>max){
max= s.charAt(i);
}
}
if(min<max){
System.out.print("YES");
}
else{
System.out.print("NO");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two strings S and T of the same length, you can rearrange the characters in S and T. Your task is to find if it is possible to rearrange S and T such that S is lexicographically smaller than T.The first line of input contains the string S. The next line of input contains the string T.
Constraints:-
1 <= |S| = |T| <= 100000
Note:- Both the string will contain only lowercase english letters.Print "YES" if it is possible to rearrange S and T such that S is lexicographically smaller than T else print "NO".Sample Input:-
school
newton
Sample Output:-
YES
Explanation:-
One of the possible rearrangements:- cshool < newton
Sample Input:-
efgh
abcd
Sample Output:-
NO, I have written this Solution Code: s = input()
t = input()
s = list(s)
t = list(t)
s = sorted(s)
t = sorted(t)
flag = 0
for i in range(len(s)):
if s[i] < t[i]:
flag =1
break
else:
continue
if flag ==0:
print("NO")
else:
print("YES"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two strings S and T of the same length, you can rearrange the characters in S and T. Your task is to find if it is possible to rearrange S and T such that S is lexicographically smaller than T.The first line of input contains the string S. The next line of input contains the string T.
Constraints:-
1 <= |S| = |T| <= 100000
Note:- Both the string will contain only lowercase english letters.Print "YES" if it is possible to rearrange S and T such that S is lexicographically smaller than T else print "NO".Sample Input:-
school
newton
Sample Output:-
YES
Explanation:-
One of the possible rearrangements:- cshool < newton
Sample Input:-
efgh
abcd
Sample Output:-
NO, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
string s,t;
cin>>s>>t;
int a[26]={0},b[26]={0};
for(int i=0;i<s.length();i++){
a[s[i]-'a']++;
b[t[i]-'a']++;
}
int x=0,y=0;
for(int i=25;i>=0;i--){
if(a[i]){
x=i;
}
if(b[25-i]){
y=25-i;
}
}
if(x<y){cout<<"YES";}
else{
cout<<"NO";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import static java.lang.System.out;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader reader = new FastReader();
int n = reader.nextInt();
String S = reader.next();
int ncount = 0;
int tcount = 0;
for (char c : S.toCharArray()) {
if (c == 'N') ncount++;
else tcount++;
}
if (ncount > tcount) {
out.print("Nutan\n");
} else {
out.print("Tusla\n");
}
out.flush();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: n = int(input())
s = input()
a1 = s.count('N')
a2 = s.count('T')
if(a1 > a2):
print("Nutan")
else:
print('Tusla'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: //Author: Xzirium
//Time and Date: 02:18:28 24 March 2022
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//-----------------------------------------------------------------------------------------------------------//
READV(N);
string S;
cin>>S;
ll n=0,t=0;
FORI(i,0,N)
{
if(S[i]=='N')
{
n++;
}
else if(S[i]=='T')
{
t++;
}
}
if(n>t)
{
cout<<"Nutan"<<endl;
}
else
{
cout<<"Tusla"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: a, b = list(map(int, input().split(" ")))
print(str(a <= 10 and b >= 10).lower(), end=' ')
print(str(a % 2 == 0 or b % 2 == 0).lower(), end=' ')
print(str(not a == b).lower()), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Main {
static boolean Logical_AND(int a, int b){
if(a<=10 && b>=10){
return true;}
return false;}
static boolean Logical_OR(int a, int b){
if(a%2==0 || b%2==0){
return true;}
return false;}
static boolean Logical_NOT(int a, int b){
if(a!=b){
return true;}
return false;}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
System.out.print(Logical_AND(a, b)+" ");
System.out.print(Logical_OR(a,b)+" ");
System.out.print(Logical_NOT(a,b)+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args){
FastReader read = new FastReader();
int a = read.nextInt();
int b = read.nextInt();
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(){
InputStreamReader inr = new InputStreamReader(System.in);
br = new BufferedReader(inr);
}
String next(){
while(st==null || !st.hasMoreElements())
try{
st = new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
long nextLong(){
return Long.parseLong(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split())
print(a+b)
print(a-b)
print(a*b)
print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: #include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define ma 10000001
bool a[ma];
int main()
{
int n;
cin>>n;
for(int i=0;i<=n;i++){
a[i]=false;
}
for(int i=2;i<=n;i++){
if(a[i]==false){
for(int j=i+i;j<=n;j+=i){
a[j]=true;
}
}
}
int cnt=0;
for(int i=2;i<=n;i++){
if(a[i]==false){cnt++;}
}
cout<<cnt;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args)
throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long n = Integer.parseInt(br.readLine());
long i=2,j,count,noOfPrime=0;
if(n<=1)
System.out.println("0");
else{
while(i<=n)
{
count=0;
for(j=2; j<=Math.sqrt(i); j++)
{
if( i%j == 0 ){
count++;
break;
}
}
if(count==0){
noOfPrime++;
}
i++;
}
System.out.println(noOfPrime);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: function numberOfPrimes(N)
{
let arr = new Array(N+1);
for(let i = 0; i <= N; i++)
arr[i] = 0;
for(let i=2; i<= N/2; i++)
{
if(arr[i] === -1)
{
continue;
}
let p = i;
for(let j=2; p*j<= N; j++)
{
arr[p*j] = -1;
}
}
//console.log(arr);
let count = 0;
for(let i=2; i<= N; i++)
{
if(arr[i] === 0)
{
count++;
}
}
//console.log(arr);
return count;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import math
n = int(input())
n=n+1
if n<3:
print(0)
else:
primes=[1]*(n//2)
for i in range(3,int(math.sqrt(n))+1,2):
if primes[i//2]:primes[i*i//2::i]=[0]*((n-i*i-1)//(2*i)+1)
print(sum(primes)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Consider an array of N integers initially carrying all values as 0. You will traverse the array N times and in each traversal, you will apply the operation as <b>1- Arr[i]</b>. i.e. you will change the value to 1 if the current value is 0 or change the value to 0 if the current value is 1. You will traverse the array as described below:-
In first go :- 1, 2, 3, 4, 5,. .. .. . N
In Second go:- 2, 4, 6, 8, 10,. .. .. N
In third go:- 3, 6, 9, 12,. .. .. . N
and so on. till the Nth go
Your task is to tell the number of 1 in the array after the Nth go.Input contains a single integer N.
Constraints:-
1 < = N < = 10<sup>14</sup>Print the number of 1 after the Nth traverse.Sample Input:-
4
Sample Output:-
2
Explanation:-
initially array will be :- 0 0 0 0
After 1st go :- 1 1 1 1
After 2nd go :- 1 0 1 0
After 3rd go :- 1 0 0 0
After 4th go:- 1 0 0 1
Sample Input:-
2
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader scan=new BufferedReader(new InputStreamReader(System.in));
long n=Long.parseLong(scan.readLine());
long ans=(long)Math.sqrt(n);
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Consider an array of N integers initially carrying all values as 0. You will traverse the array N times and in each traversal, you will apply the operation as <b>1- Arr[i]</b>. i.e. you will change the value to 1 if the current value is 0 or change the value to 0 if the current value is 1. You will traverse the array as described below:-
In first go :- 1, 2, 3, 4, 5,. .. .. . N
In Second go:- 2, 4, 6, 8, 10,. .. .. N
In third go:- 3, 6, 9, 12,. .. .. . N
and so on. till the Nth go
Your task is to tell the number of 1 in the array after the Nth go.Input contains a single integer N.
Constraints:-
1 < = N < = 10<sup>14</sup>Print the number of 1 after the Nth traverse.Sample Input:-
4
Sample Output:-
2
Explanation:-
initially array will be :- 0 0 0 0
After 1st go :- 1 1 1 1
After 2nd go :- 1 0 1 0
After 3rd go :- 1 0 0 0
After 4th go:- 1 0 0 1
Sample Input:-
2
Sample Output:-
1, I have written this Solution Code: import math
n=int(input())
print(int(math.sqrt(n))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Consider an array of N integers initially carrying all values as 0. You will traverse the array N times and in each traversal, you will apply the operation as <b>1- Arr[i]</b>. i.e. you will change the value to 1 if the current value is 0 or change the value to 0 if the current value is 1. You will traverse the array as described below:-
In first go :- 1, 2, 3, 4, 5,. .. .. . N
In Second go:- 2, 4, 6, 8, 10,. .. .. N
In third go:- 3, 6, 9, 12,. .. .. . N
and so on. till the Nth go
Your task is to tell the number of 1 in the array after the Nth go.Input contains a single integer N.
Constraints:-
1 < = N < = 10<sup>14</sup>Print the number of 1 after the Nth traverse.Sample Input:-
4
Sample Output:-
2
Explanation:-
initially array will be :- 0 0 0 0
After 1st go :- 1 1 1 1
After 2nd go :- 1 0 1 0
After 3rd go :- 1 0 0 0
After 4th go:- 1 0 0 1
Sample Input:-
2
Sample Output:-
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int t;
t=1;
while(t--){
int n;
cin>>n;
int x=sqrt(n);
cout<<x;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<b>User Task</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: def Pattern(N):
print('*')
for i in range (0,N-2):
print('*',end='')
for j in range (0,i+1):
print('^',end='')
print('*')
for i in range (0,N+1):
print('*',end='')
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<b>User Task</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: void Pattern(int N){
cout<<'*'<<endl;
for(int i=0;i<N-2;i++){
cout<<'*';
for(int j=0;j<=i;j++){
cout<<'^';
}
cout<<'*'<<endl;
}
for(int i=0;i<=N;i++){
cout<<'*';
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<b>User Task</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: static void Pattern(int N){
System.out.println('*');
for(int i=0;i<N-2;i++){
System.out.print('*');
for(int j=0;j<=i;j++){
System.out.print('^');
}System.out.println('*');
}
for(int i=0;i<=N;i++){
System.out.print('*');
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.