Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: Given an unsorted array A of size N and value K. The elements of the array A contains positive integers. You have to print all the elements which are greater than K in the array in sorted order (including K as well if present in the array A), and print all the elements which are smaller than K in sorted order both of them in separate lines. If the elements greater than or equal to K are not present in the array then print "-1". Similarly, in the case of smaller elements print -1 if elements smaller than K doesn’t exist. If a number appears more than once print number more than once.First line of input contains number of testcases T. For each testcase, there are two lines, first of which contains N and K separated by space, next line contains N space separated integers. Constraints: 1 <= T <= 100 1 <= N <= 100000 1 <= K <= 1000000 1 <= A[i] <= 1000000 Sum of N over all test cases do not exceed 100000For each testcase, print the required elements(if any), else print "-1" (without quotes)Input: 1 5 1 2 1 5 7 6 Output: 1 2 5 6 7 -1 Explanation: Testcase 1 : Since, 1, 2, 5, 6, 7 are greater or equal to given K. Also, no element less than K is present in the array., I have written this Solution Code: t=int(input()) while t>0: a=input().split() b=input().split() for i in range(len(b)): b[i]=int(b[i]) lesser=[] greater=[] for i in b: if i>=int(a[1]): greater.append(i) else: lesser.append(i) if len(greater)==0: print(-1,end="") else: greater.sort() for x in greater: print(x,end=" ") print() if len(lesser)==0: print(-1,end="") else: lesser.sort() for y in lesser: print(y,end=" ") print() t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an unsorted array A of size N and value K. The elements of the array A contains positive integers. You have to print all the elements which are greater than K in the array in sorted order (including K as well if present in the array A), and print all the elements which are smaller than K in sorted order both of them in separate lines. If the elements greater than or equal to K are not present in the array then print "-1". Similarly, in the case of smaller elements print -1 if elements smaller than K doesn’t exist. If a number appears more than once print number more than once.First line of input contains number of testcases T. For each testcase, there are two lines, first of which contains N and K separated by space, next line contains N space separated integers. Constraints: 1 <= T <= 100 1 <= N <= 100000 1 <= K <= 1000000 1 <= A[i] <= 1000000 Sum of N over all test cases do not exceed 100000For each testcase, print the required elements(if any), else print "-1" (without quotes)Input: 1 5 1 2 1 5 7 6 Output: 1 2 5 6 7 -1 Explanation: Testcase 1 : Since, 1, 2, 5, 6, 7 are greater or equal to given K. Also, no element less than K is present in the array., 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 n,k; cin>>n>>k; vector<int> A,B; for(int i=0;i<n;i++) { int a; cin>>a; if(a<k) B.pu(a); else A.pu(a); } sort(all(A)); sort(all(B)); for(auto it:A) { cout<<it<<" "; }if(A.size()==0) cout<<-1; cout<<endl; for(auto it:B) { cout<<it<<" "; }if(B.size()==0) cout<<-1; cout<<endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them. If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T – the number of test cases. Each of the next T lines contains 3 space separated integers A, B and C respectively. <b> Constraints: </b> 1 ≤ T ≤ 10 0 ≤ A, B, C ≤ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" – the answer to the i<sup>th</sup> test case.Sample Input 1: 2 3 4 2 2 2 2 Sample Output 1: No Yes Sample Explanation 1: For the first test case, there is no possible way to make all the elements zero. For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), 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.hasMoreTokens()){ 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().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("").append(String.valueOf(object)); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } public static void main(String[] args) throws Exception{ try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); int testCases=in.nextInt(); while(testCases-- > 0) { int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(); while ((a>0&&b>0)||(a>0&&c>0)||(b>0&&c>0)) { if (a >= b && a >= c) { a--; if (b >= c) { b--; } else{ c--; } } else if (b >= a && b >= c) { b--; if (a >= c) { a--; } else{ c--; } } else{ c--; if (a >= b) { a--; } else{ b--; } } } if (a==0&&b==0&&c==0){ out.println("Yes"); } else{ out.println("No"); } } out.close(); } catch (Exception e) { return; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them. If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T – the number of test cases. Each of the next T lines contains 3 space separated integers A, B and C respectively. <b> Constraints: </b> 1 ≤ T ≤ 10 0 ≤ A, B, C ≤ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" – the answer to the i<sup>th</sup> test case.Sample Input 1: 2 3 4 2 2 2 2 Sample Output 1: No Yes Sample Explanation 1: For the first test case, there is no possible way to make all the elements zero. For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), I have written this Solution Code: t=int(input()) for i in range(t): arr=list(map(int,input().split())) a,b,c=sorted(arr) if((a+b+c)%2): print("No") elif ((a+b)>=c): print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them. If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T – the number of test cases. Each of the next T lines contains 3 space separated integers A, B and C respectively. <b> Constraints: </b> 1 ≤ T ≤ 10 0 ≤ A, B, C ≤ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" – the answer to the i<sup>th</sup> test case.Sample Input 1: 2 3 4 2 2 2 2 Sample Output 1: No Yes Sample Explanation 1: For the first test case, there is no possible way to make all the elements zero. For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), I have written this Solution Code: // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define pi 3.141592653589793238 #define int long long #define ll long long #define ld long double using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); long long powm(long long a, long long b,long long mod) { long long res = 1; while (b > 0) { if (b & 1) res = res * a %mod; a = a * a %mod; b >>= 1; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE if(fopen("input.txt","r")) { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); } #endif int t; cin>>t; while(t--) { int a,b,c; cin>>a>>b>>c; if(a>b+c||b>a+c||c>a+b) cout<<"No\n"; else { int sum=a+b+c; if(sum%2) cout<<"No\n"; else cout<<"Yes\n"; } } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You need to make an order counter to keep track of the total number of orders received. Complete the function <code> generateOrder() </code> which returns a <code>function func()</code>. This function <code>func</code> should maintain a <code> count (initially 0)</code>. Every time <code>func</code> is called, <code> count</code> must be incremented by 1 and the string <code>"Total orders = " + count</code> must be returned. <b>Note:</b> The function generateOrder() will be called internally. You do not need to call it yourself. The generateOrder() takes no argument. It is called internally.The generateOrder() function returns a function that returns the string <code>"Total orders = " + count</code>, where <code>count</code> is the number of times the function is called. const initC = generateOrder(starting); console.log(initC()) //prints "Total orders = 1" console.log(initC()) //prints "Total orders = 2" console.log(initC()) //prints "Total orders = 3" , I have written this Solution Code: let generateOrder = function() { let prefix = "Total orders = "; let count = 0; let totalOrders = function(){ count++ return prefix + count; } return totalOrders; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Separate chaining technique in hashing allows us to use a linked list at each hash slot to handle the problem of collisions. That is, every slot of the hash table is a linked list, so whenever a collision occurs, the element can be appened as a node to the linked list at the slot. In this question, we'll learn how to fill up the hash table using Separate chaining technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr. The size of the array is denoted by sizeOfArray. You need to fill up the hash table using Separate chaining and print the resultant hash table.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains 2 lines of input. The first line contains size of the hashtable and the size of the array. The next line contains elements of the array Constraints: 1 <= T <= 100 2 <= hashSize <= 10^3 1 <= sizeOfArray <= 10^3 0 <= arr[i] <= 10^7For each testcase, in a new line, print the hash table. You need to print the hash table as represented in the example. Note: Please print tilde ( '~') character at the end of every testcase for separation of list from one another. Given below in the example represent to how to separate each testcase by tilde character.Sample Input: 2 10 6 92 4 14 24 44 91 10 5 12 45 36 87 11 Sample Output: 1->91 2->92 4->4->14->24->44 ~ 1->11 2->12 5->45 6->36 7->87 ~ Explanation: Testcase1: 92%10=2 so 92 goes to slot 2. 4%10=4 so 4 goes to slot 4. 14%10=4. But 4 is already occupied so we make a linked list at this position and add 14 after 4 in slot 4 and so on. Testcase2: 12%10=2 so 12 goes to slot 2. 45%10=5 goes to slot 5. 36%10=6 goes to slot 6. 87%10=7 goes to slot 7 and finally 11%10=1 goes to slot 1., 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().split(" "); int t=Integer.parseInt(str[0]); while(t-->0){ str=br.readLine().split(" "); int k=Integer.parseInt(str[0]); int n=Integer.parseInt(str[1]); int[] arr=new int[n]; str=br.readLine().split(" "); for(int i=0;i<n;i++){ arr[i]=Integer.parseInt(str[i]); } String[] st=new String[k]; for(int i=0;i<k;i++){ st[i]=""; } for(int i=0;i<n;i++){ st[arr[i]%k]+="->"+str[i]; } for(int i=0;i<k;i++){ if(st[i]!=""){ System.out.println(i+st[i]); } } System.out.println("~"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Separate chaining technique in hashing allows us to use a linked list at each hash slot to handle the problem of collisions. That is, every slot of the hash table is a linked list, so whenever a collision occurs, the element can be appened as a node to the linked list at the slot. In this question, we'll learn how to fill up the hash table using Separate chaining technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr. The size of the array is denoted by sizeOfArray. You need to fill up the hash table using Separate chaining and print the resultant hash table.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains 2 lines of input. The first line contains size of the hashtable and the size of the array. The next line contains elements of the array Constraints: 1 <= T <= 100 2 <= hashSize <= 10^3 1 <= sizeOfArray <= 10^3 0 <= arr[i] <= 10^7For each testcase, in a new line, print the hash table. You need to print the hash table as represented in the example. Note: Please print tilde ( '~') character at the end of every testcase for separation of list from one another. Given below in the example represent to how to separate each testcase by tilde character.Sample Input: 2 10 6 92 4 14 24 44 91 10 5 12 45 36 87 11 Sample Output: 1->91 2->92 4->4->14->24->44 ~ 1->11 2->12 5->45 6->36 7->87 ~ Explanation: Testcase1: 92%10=2 so 92 goes to slot 2. 4%10=4 so 4 goes to slot 4. 14%10=4. But 4 is already occupied so we make a linked list at this position and add 14 after 4 in slot 4 and so on. Testcase2: 12%10=2 so 12 goes to slot 2. 45%10=5 goes to slot 5. 36%10=6 goes to slot 6. 87%10=7 goes to slot 7 and finally 11%10=1 goes to slot 1., I have written this Solution Code: t=int(input()) for i in range(t): rowNcol=input().split() els=input().split() ds=[] for i in range(int(rowNcol[0])): col=[] ds.append(col) for i in range(int(rowNcol[1])): ds[int(int(els[i])%int(rowNcol[0]))].append(els[i]) for i in range(len(ds)): if(len(ds[i])==0): continue else: print(i,end="") for j in range(len(ds[i])): print("->"+ds[i][j],end="") print() print("~"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Separate chaining technique in hashing allows us to use a linked list at each hash slot to handle the problem of collisions. That is, every slot of the hash table is a linked list, so whenever a collision occurs, the element can be appened as a node to the linked list at the slot. In this question, we'll learn how to fill up the hash table using Separate chaining technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr. The size of the array is denoted by sizeOfArray. You need to fill up the hash table using Separate chaining and print the resultant hash table.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains 2 lines of input. The first line contains size of the hashtable and the size of the array. The next line contains elements of the array Constraints: 1 <= T <= 100 2 <= hashSize <= 10^3 1 <= sizeOfArray <= 10^3 0 <= arr[i] <= 10^7For each testcase, in a new line, print the hash table. You need to print the hash table as represented in the example. Note: Please print tilde ( '~') character at the end of every testcase for separation of list from one another. Given below in the example represent to how to separate each testcase by tilde character.Sample Input: 2 10 6 92 4 14 24 44 91 10 5 12 45 36 87 11 Sample Output: 1->91 2->92 4->4->14->24->44 ~ 1->11 2->12 5->45 6->36 7->87 ~ Explanation: Testcase1: 92%10=2 so 92 goes to slot 2. 4%10=4 so 4 goes to slot 4. 14%10=4. But 4 is already occupied so we make a linked list at this position and add 14 after 4 in slot 4 and so on. Testcase2: 12%10=2 so 12 goes to slot 2. 45%10=5 goes to slot 5. 36%10=6 goes to slot 6. 87%10=7 goes to slot 7 and finally 11%10=1 goes to slot 1., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define max1 1000001 int main(){ int t; cin>>t; while(t--){ int n,m,x; cin>>m>>n; vector<int> a[m]; for(int i=0;i<n;i++){ cin>>x; a[x%m].push_back(x); } for(int i=0;i<m;i++){ if(a[i].size()==0){continue;} cout<<i<<"->"; for(int j=0;j<a[i].size()-1;j++){ cout<<a[i][j]<<"->"; } cout<<a[i][a[i].size()-1]<<endl; } cout<<"~"<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S and a pattern P both of lowercase characters. The task is to check if the given pattern P exists in the given string S or not.First line of input contains number of testcases T. For each testcase, first line will the string and second line will be the pattern to be searched. Constraints: 1 <= T <= 100 1 <= |S|, |P| <= 1000For each testcase, print "Yes" if pattern exists or "No" if doesn't.Input: 2 aabaacaadaabaaabaa aaba aabaacaadaabaaabaa ccda Output: Yes No Explanation: Testcase 1: Given pattern aaba is found in the string at index 0. Testcase 2: Given pattern ccda doesn't exists in the string at all., I have written this Solution Code: c=int(input()) for x in range(c): S=input() P=input() if P in S: 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 string S and a pattern P both of lowercase characters. The task is to check if the given pattern P exists in the given string S or not.First line of input contains number of testcases T. For each testcase, first line will the string and second line will be the pattern to be searched. Constraints: 1 <= T <= 100 1 <= |S|, |P| <= 1000For each testcase, print "Yes" if pattern exists or "No" if doesn't.Input: 2 aabaacaadaabaaabaa aaba aabaacaadaabaaabaa ccda Output: Yes No Explanation: Testcase 1: Given pattern aaba is found in the string at index 0. Testcase 2: Given pattern ccda doesn't exists in the string at all., 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 testcases=Integer.parseInt(br.readLine()); for(int i=0;i<testcases;i++) { String input=br.readLine(); String pattern=br.readLine(); if(input.indexOf(pattern)>=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: Given a string S and a pattern P both of lowercase characters. The task is to check if the given pattern P exists in the given string S or not.First line of input contains number of testcases T. For each testcase, first line will the string and second line will be the pattern to be searched. Constraints: 1 <= T <= 100 1 <= |S|, |P| <= 1000For each testcase, print "Yes" if pattern exists or "No" if doesn't.Input: 2 aabaacaadaabaaabaa aaba aabaacaadaabaaabaa ccda Output: Yes No Explanation: Testcase 1: Given pattern aaba is found in the string at index 0. Testcase 2: Given pattern ccda doesn't exists in the string at all., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #include <iostream> #include<stack> using namespace std; void getZarr(string str, int Z[]) { int n = str.length(); int L, R, k; L = R = 0; for (int i = 1; i < n; ++i) { if (i > R) { L = R = i; while (R<n && str[R-L] == str[R]) R++; Z[i] = R-L; R--; } else { k = i-L; if (Z[k] < R-i+1) Z[i] = Z[k]; else { L = i; while (R<n && str[R-L] == str[R]) R++; Z[i] = R-L; R--; } } } } void search(string text, string pattern) { // Create concatenated string "P$T" string concat = pattern + "$" + text; int l = concat.length(); int Z[l]; getZarr(concat, Z); for (int i = 0; i < l; ++i) { if (Z[i] == pattern.length()) {cout <<"Yes" << endl;return ;} } cout<<"No"<<endl; } int main(){ int t; cin>>t; while(t--){ string t; string p; cin>>t>>p; search(t, p); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an sorted array <b>Arr[]</b> of size <b>N</b>, containing both <b>negative</b> and <b>positive</b> integers, you need to print the squared sorted output. <b>Note</b> Try using two pointer approachThe first line of input contains T, denoting the number of test cases. Each testcase contains 2 lines. The first line contains the N size of the array. The second line contains elements of an array separated by space. Constraints: 1 &le; T &le; 100 1 &le; N &le; 10000 -10000 &le; A[i] &le; 10000 The Sum of N over all test cases does not exceed 10^6For each test case you need to print the sorted squared output in new lineInput: 1 5 -7 -2 3 4 6 Output: 4 9 16 36 49, I have written this Solution Code: import java.util.*; import java.io.*; class Main { public static void main(String[] args)throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(read.readLine()); while (t-- > 0) { int n = Integer.parseInt(read.readLine()); int[] arr = new int[n]; String str[] = read.readLine().trim().split(" "); for(int i = 0; i < n; i++) arr[i] = Integer.parseInt(str[i]); arr = sortedSquares(arr); for(int i = 0; i < n; i++) System.out.print(arr[i] + " "); System.out.println(); } } public static int[] sortedSquares(int[] A) { int[] nums = new int[A.length]; int k=A.length-1; int i=0, j=A.length-1; while(i<=j){ if(Math.abs(A[i]) <= Math.abs(A[j])){ nums[k--] = A[j]*A[j]; j--; } else{ nums[k--] = A[i]*A[i]; i++; } } return nums; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an sorted array <b>Arr[]</b> of size <b>N</b>, containing both <b>negative</b> and <b>positive</b> integers, you need to print the squared sorted output. <b>Note</b> Try using two pointer approachThe first line of input contains T, denoting the number of test cases. Each testcase contains 2 lines. The first line contains the N size of the array. The second line contains elements of an array separated by space. Constraints: 1 &le; T &le; 100 1 &le; N &le; 10000 -10000 &le; A[i] &le; 10000 The Sum of N over all test cases does not exceed 10^6For each test case you need to print the sorted squared output in new lineInput: 1 5 -7 -2 3 4 6 Output: 4 9 16 36 49, I have written this Solution Code: t = int(input()) for i in range(t): n = int(input()) for i in sorted(map(lambda j:int(j)**2,input().split())): print(i,end=' ') print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer <b>N</b>, you need to typecast this integer to String. If the typecasting is done successfully then we will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>checkConvertion()</b>, which contains N as a parameter.You need to return the typecasted string value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".Sample Input: 5 Sample Output: Nice Job Sample Input: 6 Sample Output: Nice Job, I have written this Solution Code: def checkConevrtion(a): return str(a) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer <b>N</b>, you need to typecast this integer to String. If the typecasting is done successfully then we will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>checkConvertion()</b>, which contains N as a parameter.You need to return the typecasted string value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".Sample Input: 5 Sample Output: Nice Job Sample Input: 6 Sample Output: Nice Job, I have written this Solution Code: static String checkConevrtion(int a) { return String.valueOf(a); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: An integer x is called suffix of integer y if binary form of x is suffix of binary form of y. For example, 3 (binary = 11) is suffix of 7( binary = 111) and 11 ( binary = 1011). You are given an integer array of size n and an Integer x. You have to count the number of integers y in the given array such that x is suffix of y. <b>NOTE</b> : Leading zeroes are not considered in binary form for this problem . For example : 5 in binary is 101 , not 0101 .First line contains n. Second line contains n space separated. Next line contains a single integer x. <b> Constraints </b> 1 <= n <= 10<sup>5</sup> 1 <= arr[i], x = 10<sup>9</sup>A single integer denoting the required answer.Input: 5 11 13 3 9 7 3 Output: 3 Explanation : 11 => 1011 13 => 1101 3 => 11 9 => 1001 7 => 111 3 in binary form is "11". 3 is suffix of [ 11, 3, 7 ]., I have written this Solution Code: t= int(input()) arr = list(map(int, input().split())) k = int(input()) k = bin(k)[2:][::-1] count = 0 for i in range(len(arr)): l = bin(arr[i])[2:][::-1][0:len(k)] if l == k: count+=1 print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: An integer x is called suffix of integer y if binary form of x is suffix of binary form of y. For example, 3 (binary = 11) is suffix of 7( binary = 111) and 11 ( binary = 1011). You are given an integer array of size n and an Integer x. You have to count the number of integers y in the given array such that x is suffix of y. <b>NOTE</b> : Leading zeroes are not considered in binary form for this problem . For example : 5 in binary is 101 , not 0101 .First line contains n. Second line contains n space separated. Next line contains a single integer x. <b> Constraints </b> 1 <= n <= 10<sup>5</sup> 1 <= arr[i], x = 10<sup>9</sup>A single integer denoting the required answer.Input: 5 11 13 3 9 7 3 Output: 3 Explanation : 11 => 1011 13 => 1101 3 => 11 9 => 1001 7 => 111 3 in binary form is "11". 3 is suffix of [ 11, 3, 7 ]., I have written this Solution Code: import java.io.*; import java.util.*; public class Main { private static boolean isSuffix(int x,int y){ while(x>0 && y>0){ if(x%2 != y%2)return false; x/=2; y/=2; } return x==0; } public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); int n=Integer.parseInt(in.next()); int [] a = new int[n]; for(int i=0;i<n;i++){ a[i] = Integer.parseInt(in.next()); } int x=Integer.parseInt(in.next()); int ans=0; for(int i=0;i<n;i++){ if(isSuffix(x,a[i])){ ans++; } } out.print(ans); out.close(); } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void println(int i) { writer.println(i); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers and an integer K, your task is to print the number of distinct elements present in every window of size K.First line of input contains two space- separated integers N and K, the next line contains N space- separated integers depicting the values of the array. Constraints:- 1 <= K <= N <= 100000 1 <= Arr[i] <= 1000Print (N- K+1) integers, the number of distinct elements for all window of size K.Sample Input:- 6 3 1 2 3 2 2 3 Sample Output:- 3 2 2 2 Explanation: for the 1st window of size 3, elements are: 1 2 3 thus the number of distinct elements would be: 3 Similarly, for the 2nd window: 2 3rd window: 2 4th window: 2 Sample Input:- 6 4 1 2 3 3 2 1 Sample Output:- 3 2 3, 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)); StringBuilder result=new StringBuilder(); String constraints[]=br.readLine().trim().split(" "); int N=Integer.parseInt(constraints[0]); int K=Integer.parseInt(constraints[1]); String input[]=br.readLine().trim().split(" "); Map<String,Integer> myMap=new HashMap<>(); for(int i=0;i<K;i++){ if(myMap.containsKey(input[i])){ int temp=myMap.get(input[i]); myMap.replace(input[i],temp+1); } else myMap.put(input[i],1); } result.append(myMap.size()+" "); int leftIndex=0; for(int i=K;i<N;i++){ int temp=myMap.get(input[leftIndex]); if(temp==1) myMap.remove(input[leftIndex]); else myMap.replace(input[leftIndex],temp-1); if(myMap.containsKey(input[i])){ temp=myMap.get(input[i]); myMap.replace(input[i],temp+1); } else myMap.put(input[i],1); result.append(myMap.size()+" "); leftIndex++; } System.out.println(result.toString()); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers and an integer K, your task is to print the number of distinct elements present in every window of size K.First line of input contains two space- separated integers N and K, the next line contains N space- separated integers depicting the values of the array. Constraints:- 1 <= K <= N <= 100000 1 <= Arr[i] <= 1000Print (N- K+1) integers, the number of distinct elements for all window of size K.Sample Input:- 6 3 1 2 3 2 2 3 Sample Output:- 3 2 2 2 Explanation: for the 1st window of size 3, elements are: 1 2 3 thus the number of distinct elements would be: 3 Similarly, for the 2nd window: 2 3rd window: 2 4th window: 2 Sample Input:- 6 4 1 2 3 3 2 1 Sample Output:- 3 2 3, I have written this Solution Code: n,k = map(int,input().split()) l = list(map(int,input().split())) d = {} for i in range(k): d[l[i]] = i print(len(d),end=" ") for i in range(k,n): if(d[l[i-k]] < i-k+1): d.pop(l[i-k]) d[l[i]] = i print(len(d),end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers and an integer K, your task is to print the number of distinct elements present in every window of size K.First line of input contains two space- separated integers N and K, the next line contains N space- separated integers depicting the values of the array. Constraints:- 1 <= K <= N <= 100000 1 <= Arr[i] <= 1000Print (N- K+1) integers, the number of distinct elements for all window of size K.Sample Input:- 6 3 1 2 3 2 2 3 Sample Output:- 3 2 2 2 Explanation: for the 1st window of size 3, elements are: 1 2 3 thus the number of distinct elements would be: 3 Similarly, for the 2nd window: 2 3rd window: 2 4th window: 2 Sample Input:- 6 4 1 2 3 3 2 1 Sample Output:- 3 2 3, I have written this Solution Code: #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 max1 101 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } signed main(){ fast(); int n,k; cin>>n>>k; int A[n]; FOR(i,n){ cin>>A[i];} unordered_map<int,int> m; int cnt=0; for(int i=0;i<k;i++){ m[A[i]]++; } cnt=m.size(); vector<int> v; v.emplace_back(cnt); for(int i=k;i<n;i++){ m[A[i-k]]--; if(m[A[i-k]]==0){cnt--;} m[A[i]]++; if(m[A[i]]==1){cnt++;} v.emplace_back(cnt); } FOR(i,v.size()){ out1(v[i]);} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary sorted non-increasing array arr of size <b>N</b>. You need to print the count of <b>1's</b> in the binary array. Try to solve the problem using binary searchThe input line contains T, denotes the number of testcases. Each test case contains two lines. The first line contains N (size of binary array). The second line contains N elements of binary array separated by space. <b>Constraints:</b> 1 <= T <= 100 1 <= N <= 10^6 arr[i] = 0,1 <b>Sum of N over all testcases does not exceed 10^6</b>For each testcase in new line, print the count 1's in binary array.Input: 2 8 1 1 1 1 1 0 0 0 8 1 1 0 0 0 0 0 0 Output: 5 2 Explanation: Testcase 1: Number of 1's in given binary array : 1 1 1 1 1 0 0 0 is 5. Testcase 2: Number of 1's in given binary array : 1 1 0 0 0 0 0 0 is 2., I have written this Solution Code: import java.io.*; import java.util.*; class Main { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static void main (String[] args) throws IOException { Reader sc=new Reader(); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int[] a=new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } int count=search(a,0,n-1); System.out.println(count); } } public static int search(int[] a,int l,int h){ while(l<=h){ int mid=l+(h-l)/2; if ((mid==h||a[mid+1]==0)&&(a[mid]==1)) return mid+1; if (a[mid]==1) l=mid+1; else h=mid-1; } return 0; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary sorted non-increasing array arr of size <b>N</b>. You need to print the count of <b>1's</b> in the binary array. Try to solve the problem using binary searchThe input line contains T, denotes the number of testcases. Each test case contains two lines. The first line contains N (size of binary array). The second line contains N elements of binary array separated by space. <b>Constraints:</b> 1 <= T <= 100 1 <= N <= 10^6 arr[i] = 0,1 <b>Sum of N over all testcases does not exceed 10^6</b>For each testcase in new line, print the count 1's in binary array.Input: 2 8 1 1 1 1 1 0 0 0 8 1 1 0 0 0 0 0 0 Output: 5 2 Explanation: Testcase 1: Number of 1's in given binary array : 1 1 1 1 1 0 0 0 is 5. Testcase 2: Number of 1's in given binary array : 1 1 0 0 0 0 0 0 is 2., I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e6 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int t; cin >> t; while(t--){ int n; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; int l = 0, h = n+1; while(l+1 < h){ int m = (l + h) >> 1; if(a[m] == 1) l = m; else h = m; } cout << l << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary sorted non-increasing array arr of size <b>N</b>. You need to print the count of <b>1's</b> in the binary array. Try to solve the problem using binary searchThe input line contains T, denotes the number of testcases. Each test case contains two lines. The first line contains N (size of binary array). The second line contains N elements of binary array separated by space. <b>Constraints:</b> 1 <= T <= 100 1 <= N <= 10^6 arr[i] = 0,1 <b>Sum of N over all testcases does not exceed 10^6</b>For each testcase in new line, print the count 1's in binary array.Input: 2 8 1 1 1 1 1 0 0 0 8 1 1 0 0 0 0 0 0 Output: 5 2 Explanation: Testcase 1: Number of 1's in given binary array : 1 1 1 1 1 0 0 0 is 5. Testcase 2: Number of 1's in given binary array : 1 1 0 0 0 0 0 0 is 2., I have written this Solution Code: c=int(input()) for x in range(c): size=int(input()) s=input() print(s.count('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 integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, 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 n=Integer.parseInt(br.readLine()); String [] str=br.readLine().trim().split(" "); int a[]=new int[n]; for(int i=0;i<n;i++){ a[i]=Integer.parseInt(str[i]); } Arrays.sort(a); int size=a[n-1]+1; int c[]=new int[size]; for(int i=0;i<size;i++) c[i]=0; for(int i=0;i<n;i++) c[a[i]]++; int max=0,freq=c[1]; for(int i=2;i<size;i++){ if(freq<=c[i]){ freq=c[i]; max=i; } } System.out.println(max); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, I have written this Solution Code: n = int(input()) a = [int(x) for x in input().split()] freq = {} for x in a: if x not in freq: freq[x] = 1 else: freq[x] += 1 mx = max(freq.values()) rf = sorted(freq) for i in range(len(rf) - 1, -1, -1): if freq[rf[i]] == mx: print(rf[i]) break, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int n; cin >> n; for(int i = 1; i <= n; i++){ int p; cin >> p; a[p]++; } int mx = 0, id = -1; for(int i = 1; i <= 100; i++){ if(a[i] >= mx) mx = a[i], id = i; } cout << id; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of N integers. Find the product of maximum values for every subarray of size K. Print the answer modulo 10<sup>9</sup>+7. A subarray is any contiguous sequence of elements in an array.The first line contains two integers N and K, denoting the size of the array and the size of the subarray respectively. The next line contains N integers denoting the elements of the array. <b>Constarints</b> 1 <= K <= N <= 1000000 1 <= A[i] <= 1000000Print a single integer denoting the product of maximums for every subarray of size K modulo 1000000007Sample Input 1: 6 4 1 5 2 3 6 4 Sample Output 1: 180 <b>Explanation:</b> For subarray [1, 5, 2, 3], maximum = 5 For subarray [5, 2, 3, 6], maximum = 6 For subarray [2, 3, 6, 4], maximum = 6 Therefore, ans = 5*6*6 = 180, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { Reader sc=new Reader(); int n=sc.nextInt(); int b=sc.nextInt(); int[] a=new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } int j, max; long mul=1; Deque<Integer> dq= new LinkedList<Integer>(); for (int i = 0;i<b;i++) { while (!dq.isEmpty() && a[i] >=a[dq.peekLast()]) dq.removeLast(); dq.addLast(i); } mul=((mul%1000000007)*(a[dq.peek()]%1000000007))%1000000007; for (int i=b; i < n;i++) { while ((!dq.isEmpty()) && dq.peek() <=i-b) dq.removeFirst(); while ((!dq.isEmpty()) && a[i]>=a[dq.peekLast()]) dq.removeLast(); dq.addLast(i); mul=((mul%1000000007)*(a[dq.peek()]%1000000007))%1000000007; } System.out.println(mul%1000000007); } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of N integers. Find the product of maximum values for every subarray of size K. Print the answer modulo 10<sup>9</sup>+7. A subarray is any contiguous sequence of elements in an array.The first line contains two integers N and K, denoting the size of the array and the size of the subarray respectively. The next line contains N integers denoting the elements of the array. <b>Constarints</b> 1 <= K <= N <= 1000000 1 <= A[i] <= 1000000Print a single integer denoting the product of maximums for every subarray of size K modulo 1000000007Sample Input 1: 6 4 1 5 2 3 6 4 Sample Output 1: 180 <b>Explanation:</b> For subarray [1, 5, 2, 3], maximum = 5 For subarray [5, 2, 3, 6], maximum = 6 For subarray [2, 3, 6, 4], maximum = 6 Therefore, ans = 5*6*6 = 180, I have written this Solution Code: from collections import deque deq=deque() n,k=list(map(int,input().split())) array=list(map(int,input().split())) for i in range(k): while(deq and array[deq[-1]]<=array[i]): deq.pop() deq.append(i) ans=1 for j in range(k,n): ans=ans*array[deq[0]] ans=(ans)%1000000007 while(deq and deq[0]<=j-k): deq.popleft() while(deq and array[deq[-1]]<=array[j]): deq.pop() deq.append(j) ans=ans*array[deq[0]] ans=(ans)%1000000007 print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of N integers. Find the product of maximum values for every subarray of size K. Print the answer modulo 10<sup>9</sup>+7. A subarray is any contiguous sequence of elements in an array.The first line contains two integers N and K, denoting the size of the array and the size of the subarray respectively. The next line contains N integers denoting the elements of the array. <b>Constarints</b> 1 <= K <= N <= 1000000 1 <= A[i] <= 1000000Print a single integer denoting the product of maximums for every subarray of size K modulo 1000000007Sample Input 1: 6 4 1 5 2 3 6 4 Sample Output 1: 180 <b>Explanation:</b> For subarray [1, 5, 2, 3], maximum = 5 For subarray [5, 2, 3, 6], maximum = 6 For subarray [2, 3, 6, 4], maximum = 6 Therefore, ans = 5*6*6 = 180, 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 = 1e6 + 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]; deque<int> q; for(int i = 1; i <= k; i++){ while(!q.empty() && a[q.back()] <= a[i]) q.pop_back(); q.push_back(i); } int ans = a[q.front()]; for(int i = k+1; i <= n; i++){ if(q.front() == i-k) q.pop_front(); while(!q.empty() && a[q.back()] <= a[i]) q.pop_back(); q.push_back(i); ans = (ans*a[q.front()]) % mod; } cout << ans; } 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: You will be given an array of several arrays that each contain integers and your goal is to write a function that will sum up all the numbers in all the arrays. For example, if the input is [[3, 2], [1], [4, 12]] then your program should output 22 because 3 + 2 + 1 + 4 + 12 = 22An array containing arrays which can contain any number of elements.Sum of all the elements in all of the arrays.Sample input:- [[3, 2], [1], [4, 12]] Sample output:- 22 Explanation:- 3 + 2 + 1 + 4 + 12 = 22, I have written this Solution Code: function sum_array(arr) { // store our final answer var sum = 0; // loop through entire array for (var i = 0; i < arr.length; i++) { // loop through each inner array for (var j = 0; j < arr[i].length; j++) { // add this number to the current final sum sum += arr[i][j]; } } console.log(sum); }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares. Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix. <b>Constraints:-</b> 1 &le; N &le; 800 1 &le; Matrix[i][j] &le; 100000 Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1: 3 1 2 3 4 5 6 7 8 9 Output 1: 25 20 Sample Input 2: 4 1 2 3 4 6 8 9 10 11 12 13 14 15 16 17 18 Sample Output 2: 80 79 <b>Explanation 1</b> The black square contains 1, 3, 5, 7, 9; sum = 25 The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: n=int(input()) bSum=0 wSum=0 for i in range(n): c=(input().split()) for j in range(len(c)): if(i%2==0): if(j%2==0): bSum+=int(c[j]) else: wSum+=int(c[j]) else: if(j%2==0): wSum+=int(c[j]) else: bSum+=int(c[j]) print(bSum) print(wSum), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares. Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix. <b>Constraints:-</b> 1 &le; N &le; 800 1 &le; Matrix[i][j] &le; 100000 Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1: 3 1 2 3 4 5 6 7 8 9 Output 1: 25 20 Sample Input 2: 4 1 2 3 4 6 8 9 10 11 12 13 14 15 16 17 18 Sample Output 2: 80 79 <b>Explanation 1</b> The black square contains 1, 3, 5, 7, 9; sum = 25 The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main { public static void main (String[] args)throws IOException { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int mat[][] = new int[N][N]; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) mat[i][j] = sc.nextInt(); } alternate_Matrix_Sum(mat,N); } static void alternate_Matrix_Sum(int mat[][], int N) { long sum =0, sum1 = 0; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { if((i+j)%2 == 0) sum += mat[i][j]; else sum1 += mat[i][j]; } } System.out.println(sum); System.out.print(sum1); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Arpit Gupta has brought a toy for his valentine. She is playing with that toy which runs for T seconds when winded.If winded when the toy is already running, from that moment it will run for T seconds (not additional T seconds) For example if T is 10 and toy has run for 5 seconds and winded at this moment then in total it will run for 15 seconds. Arpit's Valentine winds the toy N times.She winds the toy at t[i] seconds after the first time she winds it.How long will the toy run in total?First Line of input contains two integers N and T Second Line of input contains N integers, list of time Arpit's Valentine has wound the toy at. Constraints 1 <= N <= 100000 1 <= T <= 1000000000 1 <= t[i] <= 1000000000 t[0] = 0Print a single integer the total time the toy has run.Sample input 1 2 4 0 3 Sample output 1 7 Sample input 2 2 10 0 5 Sample output 2 15 Explanation: Testcase1:- at first the toy is winded at 0 it will go till 4 but it again winded at 3 making it go for more 4 seconds so the total is 7, 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().split(" "); int n=Integer.parseInt(str[0]); int t=Integer.parseInt(str[1]); int[] arr=new int[n]; str=br.readLine().split(" "); for(int i=0;i<n;i++){ arr[i]=Integer.parseInt(str[i]); } int sum=0; for(int i=1;i<n;i++){ int dif=arr[i]-arr[i-1]; if(dif>t){ sum=sum+t; }else{ sum=sum+dif; } } sum+=t; System.out.print(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Arpit Gupta has brought a toy for his valentine. She is playing with that toy which runs for T seconds when winded.If winded when the toy is already running, from that moment it will run for T seconds (not additional T seconds) For example if T is 10 and toy has run for 5 seconds and winded at this moment then in total it will run for 15 seconds. Arpit's Valentine winds the toy N times.She winds the toy at t[i] seconds after the first time she winds it.How long will the toy run in total?First Line of input contains two integers N and T Second Line of input contains N integers, list of time Arpit's Valentine has wound the toy at. Constraints 1 <= N <= 100000 1 <= T <= 1000000000 1 <= t[i] <= 1000000000 t[0] = 0Print a single integer the total time the toy has run.Sample input 1 2 4 0 3 Sample output 1 7 Sample input 2 2 10 0 5 Sample output 2 15 Explanation: Testcase1:- at first the toy is winded at 0 it will go till 4 but it again winded at 3 making it go for more 4 seconds so the total is 7, I have written this Solution Code: n , t = [int(x) for x in input().split() ] l= [int(x) for x in input().split() ] c = 0 for i in range(len(l)-1): if l[i+1] - l[i]<=t: c+=l[i+1] - l[i] else: c+=t c+=t print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Arpit Gupta has brought a toy for his valentine. She is playing with that toy which runs for T seconds when winded.If winded when the toy is already running, from that moment it will run for T seconds (not additional T seconds) For example if T is 10 and toy has run for 5 seconds and winded at this moment then in total it will run for 15 seconds. Arpit's Valentine winds the toy N times.She winds the toy at t[i] seconds after the first time she winds it.How long will the toy run in total?First Line of input contains two integers N and T Second Line of input contains N integers, list of time Arpit's Valentine has wound the toy at. Constraints 1 <= N <= 100000 1 <= T <= 1000000000 1 <= t[i] <= 1000000000 t[0] = 0Print a single integer the total time the toy has run.Sample input 1 2 4 0 3 Sample output 1 7 Sample input 2 2 10 0 5 Sample output 2 15 Explanation: Testcase1:- at first the toy is winded at 0 it will go till 4 but it again winded at 3 making it go for more 4 seconds so the total is 7, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ long n,t; cin>>n>>t; long a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } long cur=t; long ans=t; for(int i=1;i<n;i++){ ans+=min(a[i]-a[i-1],t); } cout<<ans; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an sorted array <b>Arr[]</b> of size <b>N</b>, containing both <b>negative</b> and <b>positive</b> integers, you need to print the squared sorted output. <b>Note</b> Try using two pointer approachThe first line of input contains T, denoting the number of test cases. Each testcase contains 2 lines. The first line contains the N size of the array. The second line contains elements of an array separated by space. Constraints: 1 &le; T &le; 100 1 &le; N &le; 10000 -10000 &le; A[i] &le; 10000 The Sum of N over all test cases does not exceed 10^6For each test case you need to print the sorted squared output in new lineInput: 1 5 -7 -2 3 4 6 Output: 4 9 16 36 49, I have written this Solution Code: import java.util.*; import java.io.*; class Main { public static void main(String[] args)throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(read.readLine()); while (t-- > 0) { int n = Integer.parseInt(read.readLine()); int[] arr = new int[n]; String str[] = read.readLine().trim().split(" "); for(int i = 0; i < n; i++) arr[i] = Integer.parseInt(str[i]); arr = sortedSquares(arr); for(int i = 0; i < n; i++) System.out.print(arr[i] + " "); System.out.println(); } } public static int[] sortedSquares(int[] A) { int[] nums = new int[A.length]; int k=A.length-1; int i=0, j=A.length-1; while(i<=j){ if(Math.abs(A[i]) <= Math.abs(A[j])){ nums[k--] = A[j]*A[j]; j--; } else{ nums[k--] = A[i]*A[i]; i++; } } return nums; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an sorted array <b>Arr[]</b> of size <b>N</b>, containing both <b>negative</b> and <b>positive</b> integers, you need to print the squared sorted output. <b>Note</b> Try using two pointer approachThe first line of input contains T, denoting the number of test cases. Each testcase contains 2 lines. The first line contains the N size of the array. The second line contains elements of an array separated by space. Constraints: 1 &le; T &le; 100 1 &le; N &le; 10000 -10000 &le; A[i] &le; 10000 The Sum of N over all test cases does not exceed 10^6For each test case you need to print the sorted squared output in new lineInput: 1 5 -7 -2 3 4 6 Output: 4 9 16 36 49, I have written this Solution Code: t = int(input()) for i in range(t): n = int(input()) for i in sorted(map(lambda j:int(j)**2,input().split())): print(i,end=' ') print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ronaldo has challenged Messi to beat his team in the upcoming “Friendly” fixture. But both these legends are tired of the original football rules, so they decided to play Football with a twist. Each player is assigned an ID, from 1 to 10^6. Initially Ronaldo has the ball in his posession. Given a sequence of N passes, help Messi Know which ID player has the ball, after N passes. Note: Passes are of two types : i) P ID, which means the player currently having the ball passes it to Player with identity ID. ii) B, which means the player currently having the ball passes it back to the Player he got the Pass From. Also, It is guaranteed that the given order of passes will be a valid order.The first line of input contains number of testcases T. The 1st line of each testcase, contains two integers, N and ID1, denoting the total number of passes and the ID of Ronaldo. Respectively. Each of the next N lines, contains the information of a Pass which can be either of the above two types, i.e: 1) P ID 2) B Constraints 1 <= T <= 100 1 <= N <= 10^5 1 <= IDs <= 10^6 Sum of N for every test case is less than 10^6For each testcase you need to print the ID of the Player having the ball after N passes.Input : 2 3 1 P 13 P 14 B 5 1 P 12 P 13 P 14 B B Output : 13 14 Explanation : Testcase 1: Initially, the ball is with Ronaldo, having ID 1. In the first pass, he passes the ball to Player with ID 13. In the Second Pass, the player currently having the ball, ie Player with ID 13, passes it to player with ID 14. In the last pass the player currently having the ball, ie Player with ID 14 passed the ball back to the player from whom he got the Pass, i.e the ball is passed back to Player with Player ID 13, as Player ID 13 had passed the ball to player ID 14 in the previous pass. Testcase 2: Initially, the ball is with Ronaldo, having ID 1. In the first pass he passes the ball to player with ID 12. In the second pass, the second player passes the ball to palyer with ID 13, again the player with ID 13 passes the ball to player with ID 14. Now, player with ID 14 passed back the ball to 13, and again 13 passes back the ball to 14., 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().trim()); while (t-- > 0) { String[] line = br.readLine().trim().split(" "); int n = Integer.parseInt(line[0]); int curr = Integer.parseInt(line[1]); int prev = curr; while (n-- > 0) { String[] currLine = br.readLine().trim().split(" "); if (currLine[0].equals("P")) { prev = curr; curr = Integer.parseInt(currLine[1]); } if (currLine[0].equals("B")) { int temp = curr; curr = prev; prev = temp; } } System.out.println(curr); System.gc(); } br.close(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ronaldo has challenged Messi to beat his team in the upcoming “Friendly” fixture. But both these legends are tired of the original football rules, so they decided to play Football with a twist. Each player is assigned an ID, from 1 to 10^6. Initially Ronaldo has the ball in his posession. Given a sequence of N passes, help Messi Know which ID player has the ball, after N passes. Note: Passes are of two types : i) P ID, which means the player currently having the ball passes it to Player with identity ID. ii) B, which means the player currently having the ball passes it back to the Player he got the Pass From. Also, It is guaranteed that the given order of passes will be a valid order.The first line of input contains number of testcases T. The 1st line of each testcase, contains two integers, N and ID1, denoting the total number of passes and the ID of Ronaldo. Respectively. Each of the next N lines, contains the information of a Pass which can be either of the above two types, i.e: 1) P ID 2) B Constraints 1 <= T <= 100 1 <= N <= 10^5 1 <= IDs <= 10^6 Sum of N for every test case is less than 10^6For each testcase you need to print the ID of the Player having the ball after N passes.Input : 2 3 1 P 13 P 14 B 5 1 P 12 P 13 P 14 B B Output : 13 14 Explanation : Testcase 1: Initially, the ball is with Ronaldo, having ID 1. In the first pass, he passes the ball to Player with ID 13. In the Second Pass, the player currently having the ball, ie Player with ID 13, passes it to player with ID 14. In the last pass the player currently having the ball, ie Player with ID 14 passed the ball back to the player from whom he got the Pass, i.e the ball is passed back to Player with Player ID 13, as Player ID 13 had passed the ball to player ID 14 in the previous pass. Testcase 2: Initially, the ball is with Ronaldo, having ID 1. In the first pass he passes the ball to player with ID 12. In the second pass, the second player passes the ball to palyer with ID 13, again the player with ID 13 passes the ball to player with ID 14. Now, player with ID 14 passed back the ball to 13, and again 13 passes back the ball to 14., I have written this Solution Code: for i in range(int(input())): N, ID = map(int,input().split()) pre = 0 for i in range(N): arr = input().split() if len(arr)==2: pre,ID = ID,arr[1] else: ID,pre = pre,ID print(ID) if pre else print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ronaldo has challenged Messi to beat his team in the upcoming “Friendly” fixture. But both these legends are tired of the original football rules, so they decided to play Football with a twist. Each player is assigned an ID, from 1 to 10^6. Initially Ronaldo has the ball in his posession. Given a sequence of N passes, help Messi Know which ID player has the ball, after N passes. Note: Passes are of two types : i) P ID, which means the player currently having the ball passes it to Player with identity ID. ii) B, which means the player currently having the ball passes it back to the Player he got the Pass From. Also, It is guaranteed that the given order of passes will be a valid order.The first line of input contains number of testcases T. The 1st line of each testcase, contains two integers, N and ID1, denoting the total number of passes and the ID of Ronaldo. Respectively. Each of the next N lines, contains the information of a Pass which can be either of the above two types, i.e: 1) P ID 2) B Constraints 1 <= T <= 100 1 <= N <= 10^5 1 <= IDs <= 10^6 Sum of N for every test case is less than 10^6For each testcase you need to print the ID of the Player having the ball after N passes.Input : 2 3 1 P 13 P 14 B 5 1 P 12 P 13 P 14 B B Output : 13 14 Explanation : Testcase 1: Initially, the ball is with Ronaldo, having ID 1. In the first pass, he passes the ball to Player with ID 13. In the Second Pass, the player currently having the ball, ie Player with ID 13, passes it to player with ID 14. In the last pass the player currently having the ball, ie Player with ID 14 passed the ball back to the player from whom he got the Pass, i.e the ball is passed back to Player with Player ID 13, as Player ID 13 had passed the ball to player ID 14 in the previous pass. Testcase 2: Initially, the ball is with Ronaldo, having ID 1. In the first pass he passes the ball to player with ID 12. In the second pass, the second player passes the ball to palyer with ID 13, again the player with ID 13 passes the ball to player with ID 14. Now, player with ID 14 passed back the ball to 13, and again 13 passes back the ball to 14., I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; signed main() { IOS; int t; cin >> t; while(t--){ int n, id; cin >> n >> id; int pre = 0, cur = id; for(int i = 1; i <= n; i++){ char c; cin >> c; if(c == 'P'){ int x; cin >> x; pre = cur; cur = x; } else{ swap(pre, cur); } } cout << cur << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Take input from standard input while you do not get 0 as an input. Print all the inputs separated by space. It is guaranteed that the number of integers are less than 100000.The input will contain a series of integers in one line each. Input should be taken while you have not get a 0 as an input. 0 <= input <= 10Print the input integers seperated by space.Sample Input 6 5 5 0 Sample Output 6 5 5 0 Sample Input 9 3 5 7 6 9 8 3 2 7 7 3 5 0 Sample Output 9 3 5 7 6 9 8 3 2 7 7 3 5 0, I have written this Solution Code: n=1 index=0 li=[] while n!=0: n=int(input()) li.append(n) index=index+1 #li = list(map(int,input().strip().split())) for i in range(0,len(li)-1): print(li[i],end=" ") print(li[len(li)-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Take input from standard input while you do not get 0 as an input. Print all the inputs separated by space. It is guaranteed that the number of integers are less than 100000.The input will contain a series of integers in one line each. Input should be taken while you have not get a 0 as an input. 0 <= input <= 10Print the input integers seperated by space.Sample Input 6 5 5 0 Sample Output 6 5 5 0 Sample Input 9 3 5 7 6 9 8 3 2 7 7 3 5 0 Sample Output 9 3 5 7 6 9 8 3 2 7 7 3 5 0, 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); int n=100001; int a; for(int i=0;i<n;i++){ a=sc.nextInt(); System.out.print(a+" "); if(a==0){break;} } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Take input from standard input while you do not get 0 as an input. Print all the inputs separated by space. It is guaranteed that the number of integers are less than 100000.The input will contain a series of integers in one line each. Input should be taken while you have not get a 0 as an input. 0 <= input <= 10Print the input integers seperated by space.Sample Input 6 5 5 0 Sample Output 6 5 5 0 Sample Input 9 3 5 7 6 9 8 3 2 7 7 3 5 0 Sample Output 9 3 5 7 6 9 8 3 2 7 7 3 5 0, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; signed main() { IOS; int n; while(cin >> n){ cout << n << " "; if(n == 0) break; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A string is called square if it is some string written twice in a row. For example, the strings "aa", "abcabc", "abab" and "baabaa" are square. But the strings "aaa", "abaaab" and "abcdabc" are not square. For a given string s determine if it is square.The input consists of a string S consisting of lowercase English alphabets. <b>Constraints</b> The length of the string is between 1 to 100.Print Yes if the string in the corresponding test case is square, No otherwise.<b>Sample Input 1</b> aaa <b>Sample Output 1</b> No <b>Sample Input 2</b> xyxy <b>Sample Output 2</b> Yes, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t=1; // cin >> t; for (int i = 0; i < t; i++){ string s; cin >> s; int N = s.size(); if (N % 2 == 1){ cout << "No" << endl; } else { if (s.substr(0, N / 2) == s.substr(N / 2)){ cout << "Yes" << endl; } else { cout << "No" << endl; } } } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A shop sells candies of sweetness ranging from 1 to 1000000000. Price of a candy with sweetness X is <b>A*X + B*f(X)</b> units, where f(X) returns number of digits in the decimal notation of X. Given A, B, and T, find the candy with maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.The first and the only line of input contains three integers A, B and T. Constraints: 1 <= A, B <= 10^9 1 <= T <= 10^18Print the maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.Sample Input 1 10 7 100 Sample Output 1 9 Explanation: Cost of 9 level candy = 9*10 + 7*f(9) = 9*10 + 7*1 = 97. Sample Input 2 1000000000 1000000000 100 Sample Output 2 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader s=new BufferedReader(new InputStreamReader(System.in)); String []S=s.readLine().split(" "); long A=Long.parseLong(S[0]); long B=Long.parseLong(S[1]); long T=Long.parseLong(S[2]); findmaxsweetness(A,B,T); } public static void findmaxsweetness(long A,long B,long T){ long start=0; long end=1000000001; while(start<end){ long mid=start+(end-start)/2; long amount=findsweetness(A,B,mid); if(amount>T){ end=mid; } else{ start=mid+1; } } if(start==0) System.out.println(start); else System.out.println(start-1); } public static long findsweetness(long A,long B,long mid){ String S=String.valueOf(mid); long len=S.length(); long result= (A*mid)+(B*len); return result; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A shop sells candies of sweetness ranging from 1 to 1000000000. Price of a candy with sweetness X is <b>A*X + B*f(X)</b> units, where f(X) returns number of digits in the decimal notation of X. Given A, B, and T, find the candy with maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.The first and the only line of input contains three integers A, B and T. Constraints: 1 <= A, B <= 10^9 1 <= T <= 10^18Print the maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.Sample Input 1 10 7 100 Sample Output 1 9 Explanation: Cost of 9 level candy = 9*10 + 7*f(9) = 9*10 + 7*1 = 97. Sample Input 2 1000000000 1000000000 100 Sample Output 2 0, I have written this Solution Code: a,b,t=map(int,input().split()) if(a+b>t): print(0) exit() i=1 j=1000000000 while i<=j: m=(i+j)//2 v1=str(m) v=(a*m)+(len(v1)*b) if v>t: j=m-1 else: ans=m i=m+1 print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: A shop sells candies of sweetness ranging from 1 to 1000000000. Price of a candy with sweetness X is <b>A*X + B*f(X)</b> units, where f(X) returns number of digits in the decimal notation of X. Given A, B, and T, find the candy with maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.The first and the only line of input contains three integers A, B and T. Constraints: 1 <= A, B <= 10^9 1 <= T <= 10^18Print the maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.Sample Input 1 10 7 100 Sample Output 1 9 Explanation: Cost of 9 level candy = 9*10 + 7*f(9) = 9*10 + 7*1 = 97. Sample Input 2 1000000000 1000000000 100 Sample Output 2 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(); ////////////// typedef unsigned long long ull; 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(){ #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif ll A,B,X; cin >> A >> B >> X; ll lb = 0, ub = 1000000001, mid; while (ub - lb > 1) { mid = (ub + lb) / 2; (A*mid+B*to_string(mid).length() <= X ? lb : ub) = mid; } cout << lb << endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have N light bulbs, however they are currently jumbled up in wires. When you start unravelling the bulbs, you observe that the situation can be described by a directed acyclic graph connecting the bulbs to each other. Formally, you are given a directed graph consisting of N nodes (numbered 1 to N) and M edges such that it contains no cycles. A sequence of vertices (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) is called a path if there exists an edge from v<sub>i</sub> to v<sub>i+1</sub> for every i such that 1 ≤ i ≤ k-1. A path (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) in the graph is called maximal, if for any vertex v, the sequence (v, v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) or (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>, v) do not represent paths in the graph. Find the number of maximal paths in the graph.The first line contains two integers N and M. The next M lines each contain two integers u and v – representing an edge from vertex u to vertex v. <b> Constraints: </b> 1 ≤ N ≤ 10<sup>5</sup> 0 ≤ M ≤ 2×10<sup>5</sup> 1 ≤ u, v ≤ N The graph does not contain any self-loops or multiple edges.Print a single integer – the number of maximal paths.Sample Input 1: 3 1 1 2 Sample Output 1: 2 Sample Explanation 1: The two maximal paths are (1, 2) and (3). Sample Input 2: 3 3 1 2 2 3 1 3 Sample Output 2: 2 Sample Explanation 1: The two maximal paths are (1, 2, 3) and (1, 3). Sample Input 3: 3 2 1 3 3 2 Sample Output 3: 1 Sample Explanation 3: The only maximal path is (1, 3, 2)., I have written this Solution Code: import java.io.*; import java.util.*; public class Main { public static void solve(FastIO io) { final int N = io.nextInt(); final int M = io.nextInt(); Node[] nodes = new Node[N + 1]; for (int i = 1; i <= N; ++i) { nodes[i] = new Node(i); } for (int i = 0; i < M; ++i) { final int U = io.nextInt(); final int V = io.nextInt(); nodes[U].next.add(nodes[V]); ++nodes[V].indegree; } long total = 0; long[] ans = new long[N + 1]; Arrays.fill(ans, -1); for (int i = 1; i <= N; ++i) { if (nodes[i].indegree == 0) { total += countMaximal(nodes[i], ans); } } io.println(total); } private static long countMaximal(Node u, long[] ans) { if (ans[u.id] < 0) { if (u.next.isEmpty()) { ans[u.id] = 1; } else { long got = 0; for (Node v : u.next) { got += countMaximal(v, ans); } ans[u.id] = got; } } return ans[u.id]; } private static class Node { public int id; public List<Node> next = new LinkedList<>(); public int indegree; public Node(int id) { this.id = id; } } public static class FastIO { private InputStream reader; private PrintWriter writer; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastIO(InputStream r, OutputStream w) { reader = r; writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w))); } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = reader.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { return Double.parseDouble(nextString()); } public int[] nextIntArray(int n) { return nextIntArray(n, 0); } public int[] nextIntArray(int n, int off) { int[] arr = new int[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextInt(); } return arr; } public long[] nextLongArray(int n) { return nextLongArray(n, 0); } public long[] nextLongArray(int n, int off) { long[] arr = new long[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void printArray(int[] arr) { for (int i = 0; i < arr.length; i++) { if (i != 0) { writer.print(' '); } writer.print(arr[i]); } } public void printArray(long[] arr) { for (int i = 0; i < arr.length; i++) { if (i != 0) { writer.print(' '); } writer.print(arr[i]); } } public void printlnArray(int[] arr) { printArray(arr); writer.println(); } public void printlnArray(long[] arr) { printArray(arr); writer.println(); } public void printf(String format, Object... args) { print(String.format(format, args)); } public void flush() { writer.flush(); } } private static class Solution implements Runnable { @Override public void run() { FastIO io = new FastIO(System.in, System.out); solve(io); io.flush(); } } public static void main(String[] args) throws InterruptedException { Thread t = new Thread(null, new Solution(), "Solution", 1 << 30); t.start(); t.join(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have N light bulbs, however they are currently jumbled up in wires. When you start unravelling the bulbs, you observe that the situation can be described by a directed acyclic graph connecting the bulbs to each other. Formally, you are given a directed graph consisting of N nodes (numbered 1 to N) and M edges such that it contains no cycles. A sequence of vertices (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) is called a path if there exists an edge from v<sub>i</sub> to v<sub>i+1</sub> for every i such that 1 ≤ i ≤ k-1. A path (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) in the graph is called maximal, if for any vertex v, the sequence (v, v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) or (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>, v) do not represent paths in the graph. Find the number of maximal paths in the graph.The first line contains two integers N and M. The next M lines each contain two integers u and v – representing an edge from vertex u to vertex v. <b> Constraints: </b> 1 ≤ N ≤ 10<sup>5</sup> 0 ≤ M ≤ 2×10<sup>5</sup> 1 ≤ u, v ≤ N The graph does not contain any self-loops or multiple edges.Print a single integer – the number of maximal paths.Sample Input 1: 3 1 1 2 Sample Output 1: 2 Sample Explanation 1: The two maximal paths are (1, 2) and (3). Sample Input 2: 3 3 1 2 2 3 1 3 Sample Output 2: 2 Sample Explanation 1: The two maximal paths are (1, 2, 3) and (1, 3). Sample Input 3: 3 2 1 3 3 2 Sample Output 3: 1 Sample Explanation 3: The only maximal path is (1, 3, 2)., I have written this Solution Code: #include <bits/stdc++.h> #define int long long #define endl '\n' using namespace std; typedef long long ll; typedef long double ld; #define db(x) cerr << #x << ": " << x << '\n'; #define read(a) int a; cin >> a; #define reads(s) string s; cin >> s; #define readb(a, b) int a, b; cin >> a >> b; #define readc(a, b, c) int a, b, c; cin >> a >> b >> c; #define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];} #define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];} #define print(a) cout << a << endl; #define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl; #define printv(v) for (int i: v) cout << i << " "; cout << endl; #define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} #define all(v) v.begin(), v.end() #define sz(v) (int)(v.size()) #define rz(v, n) v.resize((n) + 1); #define pb push_back #define fi first #define se second #define vi vector <int> #define pi pair <int, int> #define vpi vector <pi> #define vvi vector <vi> #define setprec cout << fixed << showpoint << setprecision(20); #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const ll inf = 1e18; const ll mod = 1e9 + 7; //const ll mod = 998244353; vector<vector<int>> adj; int n, m; vector<int> visited, ans; void dfs(int v) { visited[v] = true; for (int u : adj[v]) { if (!visited[u]) dfs(u); } ans.push_back(v); } void topological_sort() { ans.clear(); for (int i = 1; i <= n; ++i) { if (!visited[i]) dfs(i); } reverse(ans.begin(), ans.end()); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; adj.resize(n + 1); visited.resize(n + 1); vi d(n + 1), f(n + 1); FOR (i, 1, m) { readb(u, v); adj[u].pb(v); d[v]++; } topological_sort(); int sum = 0; for (int i: ans) { if (!d[i]) f[i] = 1; for (int v: adj[i]) f[v] += f[i]; if (!sz(adj[i])) sum += f[i]; } cout << sum; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have an array sorted in non- decreasing order and an element key. You have to find whether the key is present inside your array or not.The first line contains a single element N(size of our array) The next line contains N space- separated integer A[i]. The next line contains a single integer key.Determine whether the key is present in our array or not.Sample Input 1: 8 5 6 7 8 1 2 3 4 7 Sample Output 1: 1 Explanation: 7 present at 3rd index., 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 n = sc.nextInt(); int[] arr = new int[n]; for(int i =0; i < n; i++){ arr[i] = sc.nextInt(); } int k = sc.nextInt(); boolean ans = false; for(int i =0; i < n; i++){ if(arr[i] == k){ ans = true; } } if(ans){ System.out.print(1); }else{ System.out.print(0); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have an array sorted in non- decreasing order and an element key. You have to find whether the key is present inside your array or not.The first line contains a single element N(size of our array) The next line contains N space- separated integer A[i]. The next line contains a single integer key.Determine whether the key is present in our array or not.Sample Input 1: 8 5 6 7 8 1 2 3 4 7 Sample Output 1: 1 Explanation: 7 present at 3rd index., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; void helper(vector<int>& nums, int target,int low,int high,int &isMatch){ if(low>high) return; if(low==high ){ if(target==nums[low]) isMatch=low; return; } int mid=(high-low)/2+low; if(isMatch==-1 && mid>=0) helper(nums,target,low,mid,isMatch); if(isMatch==-1 && mid>=0) helper(nums,target,mid+1,high,isMatch); return; } int search(vector<int>& nums, int target) { int isMatch=-1; helper(nums,target,0,nums.size()-1,isMatch); return isMatch; } int main() { int n,key; cin>>n; vector<int>arr(n); for(int &i:arr)cin>>i; cin>>key; cout <<(search(arr,key)>=0 ? 1 : 0); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array, your task is to print the minimum size of the set so that at least half of the integers of the array are removed.The first line contains n the size of the array and the next line contains input of the array <b>Constraints</b> 1 <= n<= 1e5 (n is even) 1 <= arr[i] <= 1e5Return the minimum set size Sample Input : 10 3 3 3 3 5 5 5 2 2 7 Sample Output : 2 Explanation : Choosing {3, 7} will make the new array [5, 5, 5, 2, 2] which has size 5 (i. e equal to half of the size of the old array). Possible sets of size 2 are {3, 5}, {3, 2}, {5, 2}. Choosing set {2, 7} is not possible as it will make the new array [3, 3, 3, 3, 5, 5, 5] which has a size greater than half of the size of the old array. Sample Input 1: 5 7 7 7 7 7 Sample Output 1: 1 Explanation : The only possible set you can choose is {7}. This will make the new array empty., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main(String[] args) throws IOException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); int arr[] = new int[n]; String[] str = br.readLine().trim().split(" "); for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(str[i]); } HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < n; i++) { map.put(arr[i], map.getOrDefault(arr[i], 0) + 1); } PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder()); for (Map.Entry entry : map.entrySet()) { maxHeap.add((Integer) entry.getValue()); } long ans = 0; int h=n/2; int c=0; while(ans<h) { ans += maxHeap.poll(); c++; } 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 an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array, your task is to print the minimum size of the set so that at least half of the integers of the array are removed.The first line contains n the size of the array and the next line contains input of the array <b>Constraints</b> 1 <= n<= 1e5 (n is even) 1 <= arr[i] <= 1e5Return the minimum set size Sample Input : 10 3 3 3 3 5 5 5 2 2 7 Sample Output : 2 Explanation : Choosing {3, 7} will make the new array [5, 5, 5, 2, 2] which has size 5 (i. e equal to half of the size of the old array). Possible sets of size 2 are {3, 5}, {3, 2}, {5, 2}. Choosing set {2, 7} is not possible as it will make the new array [3, 3, 3, 3, 5, 5, 5] which has a size greater than half of the size of the old array. Sample Input 1: 5 7 7 7 7 7 Sample Output 1: 1 Explanation : The only possible set you can choose is {7}. This will make the new array empty., I have written this Solution Code: from collections import defaultdict import numpy as np n=int(input()) val=np.array([input().strip().split()],int).flatten() d=defaultdict(int) l=n for i in val: d[i]+=1 a=[] for i in d: a.append([d[i],i]) a.sort(reverse=True) c=0 h=0 for i in a: c+=1 h+=i[0] if(h>(l//2-1)): break print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array, your task is to print the minimum size of the set so that at least half of the integers of the array are removed.The first line contains n the size of the array and the next line contains input of the array <b>Constraints</b> 1 <= n<= 1e5 (n is even) 1 <= arr[i] <= 1e5Return the minimum set size Sample Input : 10 3 3 3 3 5 5 5 2 2 7 Sample Output : 2 Explanation : Choosing {3, 7} will make the new array [5, 5, 5, 2, 2] which has size 5 (i. e equal to half of the size of the old array). Possible sets of size 2 are {3, 5}, {3, 2}, {5, 2}. Choosing set {2, 7} is not possible as it will make the new array [3, 3, 3, 3, 5, 5, 5] which has a size greater than half of the size of the old array. Sample Input 1: 5 7 7 7 7 7 Sample Output 1: 1 Explanation : The only possible set you can choose is {7}. This will make the new array empty., I have written this Solution Code: /** * Author : tourist1256 * Time : 2022-01-12 19:43:00 **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif int minSetSize(vector<int> &arr) { unordered_map<int, int> counter; priority_queue<int> q; int res = 0, removed = 0; for (auto a : arr) counter[a]++; for (auto c : counter) q.push(c.second); while (removed < arr.size() / 2) { removed += q.top(); q.pop(); res++; } return res; } int main() { #ifdef LOCAL auto start = std::chrono::high_resolution_clock::now(); #endif ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n); for (auto &it : a) { cin >> it; } cout << minSetSize(a) << "\n"; #ifdef LOCAL auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); cerr << "Time taken : " << ((long double)duration.count()) / ((long double)1e9) << "s " << endl; #endif return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers x and y, check if x can be converted to y by adding F(n) to x where F(n){n>=1} is defined as:- 1+3+9+27+81+. .3^n.<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>Ifpossible()</b> that takes the integer x and y as parameter. Constraints:- 1<= x < y <= 10^9Return 1 if it is possible to convert x into y else return 0.Sample Input:- 5 7 Sample Output:- 0 Sample Input:- 3 16 Sample Output:- 1 Explanation:- F(3) = 1 + 3 + 9 = 13 3 + 13 = 16, I have written this Solution Code: public static int Ifpossible(long x, long y){ long sum=y-x; long ans=0; long ch = 1; while(ans<sum){ ans+=ch; if(ans==sum){return 1;} ch*=3; } return 0; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers x and y, check if x can be converted to y by adding F(n) to x where F(n){n>=1} is defined as:- 1+3+9+27+81+. .3^n.<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>Ifpossible()</b> that takes the integer x and y as parameter. Constraints:- 1<= x < y <= 10^9Return 1 if it is possible to convert x into y else return 0.Sample Input:- 5 7 Sample Output:- 0 Sample Input:- 3 16 Sample Output:- 1 Explanation:- F(3) = 1 + 3 + 9 = 13 3 + 13 = 16, I have written this Solution Code: int Ifpossible(long x, long y){ long sum=y-x; long ans=0; long ch = 1; while(ans<sum){ ans+=ch; if(ans==sum){return 1;break;} ch*=(long)3; } return 0; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers x and y, check if x can be converted to y by adding F(n) to x where F(n){n>=1} is defined as:- 1+3+9+27+81+. .3^n.<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>Ifpossible()</b> that takes the integer x and y as parameter. Constraints:- 1<= x < y <= 10^9Return 1 if it is possible to convert x into y else return 0.Sample Input:- 5 7 Sample Output:- 0 Sample Input:- 3 16 Sample Output:- 1 Explanation:- F(3) = 1 + 3 + 9 = 13 3 + 13 = 16, I have written this Solution Code: int Ifpossible(long x, long y){ long sum=y-x; long ans=0; long ch = 1; while(ans<sum){ ans+=ch; if(ans==sum){return 1;} ch*=3; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers x and y, check if x can be converted to y by adding F(n) to x where F(n){n>=1} is defined as:- 1+3+9+27+81+. .3^n.<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>Ifpossible()</b> that takes the integer x and y as parameter. Constraints:- 1<= x < y <= 10^9Return 1 if it is possible to convert x into y else return 0.Sample Input:- 5 7 Sample Output:- 0 Sample Input:- 3 16 Sample Output:- 1 Explanation:- F(3) = 1 + 3 + 9 = 13 3 + 13 = 16, I have written this Solution Code: def Ifpossible(x,y) : result = y-x ans = 0 ch = 1 while ans<result : ans+=ch if ans==result: return 1; ch*=3 return 0; , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Rahul has given a linked list and he wants to move all 0’s to the front of the linked list. Help Rahul to fulfill his wish. <b>Note:</b> The order of all other elements except 0 should be the same after rearrangement. For custom input/output, enter the list in reverse order, and the output will also be in reverse order. Example: 1 1 2 0 3 0 0 is the linked list given to Rahul. First, enter the list in reverse order so the new list will become 0 0 3 0 2 1 1. According to Rahul's wish, all zeros should be moved to the front of the linked list. Hence the output will be 0 0 0 3 2 1 1<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>moveZeroes()</b> that takes the head node as a parameter. <b>Constraints:</b> 1 &le; T &le; 100 1 &le; N &le; 100000 0 &le; Node.data &le; 100000 <b>Note:- </b> The sum of all test cases doesn't exceed 10^5Return the head of the modified linked list.Input: 2 10 0 4 0 5 0 2 1 0 1 0 7 1 1 2 3 0 0 0 Output: 0 0 0 0 0 1 1 2 5 4 0 0 0 3 2 1 1, I have written this Solution Code: static public Node moveZeroes(Node head){ ArrayList<Integer> a=new ArrayList<>(); int c=0; while(head!=null){ if(head.data==0){ c++; } else{ a.add(head.data); } head=head.next; } head=null; for(int i=a.size()-1;i>=0;i--){ if(head==null){ head=new Node(a.get(i)); } else{ Node temp=new Node(a.get(i)); temp.next=head; head=temp; } } while(c-->0){ Node temp=new Node(0); temp.next=head; head=temp; } return head; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a queue of integers and N queries. Your the task is to perform these operations:- enqueue:-this operation will add an element to your current queue. dequeue:-this operation will delete the element from the starting of the queue displayfront:-this operation will print the element presented at front Note:-if queue is empty than dequeue operation will do nothing, and 0 will be printed as a front element of queue if it is empty.User task: Since this will be a functional problem, you don't have to take input. You just have to complete the functions: <b>enqueue()</b>:- that takes integer to be added as a parameter. <b>dequeue()</b>:- that takes no parameter. <b>displayfront()</b> :- that takes no parameter. Constraints: 1 <= N(Number of queries) <= 10<sup>3</sup>You don't need to print anything else other than in displayfront() in which you require to print the element at front of your queue in a new line, if the queue is empty you just need to print 0.Sample Input:- 7 displayfront enqueue 2 displayfront enqueue 4 displayfront dequeue displayfront Sample Output:- 0 2 2 4 Sample input: 5 enqueue 4 enqueue 5 displayfront dequeue displayfront Sample output:- 4 5, I have written this Solution Code: class Queue { private Node front, rear; private int currentSize; class Node { Node next; int val; Node(int val) { this.val = val; next = null; } } public Queue() { front = null; rear = null; currentSize = 0; } public boolean isEmpty() { return (currentSize <= 0); } public void dequeue() { if (isEmpty()) { } else{ front = front.next; currentSize--; } } //Add data to the end of the list. public void enqueue(int data) { Node oldRear = rear; rear = new Node(data); if (isEmpty()) { front = rear; } else { oldRear.next = rear; } currentSize++; } public void displayfront(){ if(isEmpty()){ System.out.println("0"); } else{ System.out.println(front.val); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Create a new class VipCustomer it should have 3 fields name, creditLimit(double), and email address, there default value is as {name:"XYZ", creditLimit:"10", email:"xyz@abc. com"} respectively means ordering of parameter should be same. E.g constructor(name,creditLimit,email); create 3 constructor 1st constructor empty should call the constructor with 3 parameters with default values 2nd constructor should pass on the 2 values it receives as name and creditLimit respectively and, add a default value for the 3rd 3rd constructor should save all fields. create getters only for this name getName, getCreditLimit and getEmail and confirm it works. Note: each methods and variables should of public typeYou don't have to take any input, You only have to write class <b>VipCustomer</b>.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Input: class VipCustomer{ // if your code works fine for the tester } Sample Output: Correct, I have written this Solution Code: class VipCustomer{ public double creditLimit; public String name; public String email; VipCustomer(){ this("XYZ",10.0,"[email protected]"); } VipCustomer(String name,double creditLimit){ this(name,creditLimit,"[email protected]"); } VipCustomer(String _name,double _creditLimit,String _email){ email=_email; name=_name; creditLimit=_creditLimit; } public String getName(){ return this.name; } public String getEmail(){ return this.email; } public double getCreditLimit(){ return this.creditLimit; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: <em>Unix time is a system for describing a point in time. It is the number of seconds that have elapsed since the Unix epoch, excluding leap seconds. The Unix epoch is 00:00:00 UTC on 1 January 1970</em> Implement the function <code>msSinceEpoch</code>, which returns milliseconds since the Unix epoch. (Use JS built-in functions)The function takes no argumentThe function returns a numberconsole. log(msSinceEpoch()) // prints 1642595040109, I have written this Solution Code: function msSinceEpoch() { // write code here // return the output , do not use console.log here return Date.now() }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree with n nodes (numbered from 1 to n) having weight wi and left and right children (li, ri), find whether the given tree is BST or not.The first line of the input contains an integer n, the number of nodes in the tree. The second line of input contains n integers, the values of the nodes of the tree. The third line of the input contains an integer, denoting the root node of the tree. Next n lines contain two integers l, r denoting the left and right child of the tree. (The value is 0 if there is no left or right child) Constraints 1 <= n <= 50000 0 <= l, r <= n (0 denotes no child) 1 <= w <= 1000000000Output "YES" if the given tree is BST, else output "NO"Sample Input 5 10 3 9 2 1 4 3 0 0 0 2 0 5 1 0 0 Sample Output YES, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static class TreeNode{ int data; TreeNode left; TreeNode right; public TreeNode(int data){ this.data = data; } } static int max = Integer.MIN_VALUE; static int min = Integer.MAX_VALUE; static boolean isBST = true; static boolean isBSTUtil(TreeNode root, int min, int max){ if(root == null) return true; if(root.data > max || root.data < min){ return false; } return isBSTUtil(root.left, min, root.data) && isBSTUtil(root.right, root.data, max); } static void inorder(TreeNode root){ if (root != null){ inorder(root.left); if(root.data < min) min = root.data; if(root.data > max) max = root.data; inorder(root.right); } } public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int [] arr = new int[n]; String [] str = br.readLine().split(" "); for(int i = 0; i < str.length; i++){ arr[i] = Integer.parseInt(str[i]); } int root = Integer.parseInt(br.readLine()); TreeNode [] tree = new TreeNode[n]; for(int i = 0; i < n; i++){ tree[i] = new TreeNode(arr[i]); } for(int i = 0; i < n; i++){ String [] in = br.readLine().split(" "); int l = Integer.parseInt(in[0]); int r = Integer.parseInt(in[1]); if(l != 0) tree[i].left = tree[l - 1]; if(r != 0) tree[i].right = tree[r - 1]; } inorder(tree[root - 1]); System.out.println(isBSTUtil(tree[root - 1], min, max) == true ? "YES" : "NO"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree with n nodes (numbered from 1 to n) having weight wi and left and right children (li, ri), find whether the given tree is BST or not.The first line of the input contains an integer n, the number of nodes in the tree. The second line of input contains n integers, the values of the nodes of the tree. The third line of the input contains an integer, denoting the root node of the tree. Next n lines contain two integers l, r denoting the left and right child of the tree. (The value is 0 if there is no left or right child) Constraints 1 <= n <= 50000 0 <= l, r <= n (0 denotes no child) 1 <= w <= 1000000000Output "YES" if the given tree is BST, else output "NO"Sample Input 5 10 3 9 2 1 4 3 0 0 0 2 0 5 1 0 0 Sample Output YES, I have written this Solution Code: N = int(input()) if N == 1: print("YES") exit() in_arr = list(map(int,input().split())) root = int(input()) in_tree_arr = [list(map(int,input().split())) for i in range(N)] in_order_arr = [] def traverse(root): if root==0: return traverse(in_tree_arr[root-1][0]) in_order_arr.append(in_arr[root-1]) traverse(in_tree_arr[root-1][1]) traverse(root) for i in range(N-1): if in_order_arr[i]<in_order_arr[i+1]: continue else: print("NO") break else: print("YES"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree with n nodes (numbered from 1 to n) having weight wi and left and right children (li, ri), find whether the given tree is BST or not.The first line of the input contains an integer n, the number of nodes in the tree. The second line of input contains n integers, the values of the nodes of the tree. The third line of the input contains an integer, denoting the root node of the tree. Next n lines contain two integers l, r denoting the left and right child of the tree. (The value is 0 if there is no left or right child) Constraints 1 <= n <= 50000 0 <= l, r <= n (0 denotes no child) 1 <= w <= 1000000000Output "YES" if the given tree is BST, else output "NO"Sample Input 5 10 3 9 2 1 4 3 0 0 0 2 0 5 1 0 0 Sample Output YES, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; class Node { public: Node( int v ) { data = v; left = NULL; right = NULL; } int data; Node* left; Node* right; }; bool isBST(Node *tree, int min, int max){ if(tree == NULL) return true; if(tree -> data < min || tree -> data > max) return false; return isBST(tree -> left, min, tree -> data - 1) && isBST(tree -> right, tree -> data + 1, max); } int main(){ int n; cin >> n; Node* *tree; tree = new Node*[n]; for(int i = 0; i < n; i++){ int value; cin >> value; tree[i] = new Node(value); } int root; cin >> root; for(int i = 0; i < n; i++){ int left,right; cin>>left; cin>>right; if(left != 0) tree[i] -> left = tree[left - 1]; if(right != 0) tree[i] -> right = tree[right - 1]; } if(isBST(tree[root - 1], INT_MIN, INT_MAX)) cout<< "YES"; else cout<<"NO"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Tom loves palindromes. He has the power to convert any ordinary string to a palindrome. In one move tom can choose a character of a string and change it to any other character. Given a string, find the minimum number of moves in which tom can change it to a palindrome.Input consists of a string. Every character of a string contains lowercase alphabets 'a' to 'z' inclusive. Constraints 1 <= |s| <= 1000The minimum number of moves to convert the given string to a palindrome.Sample input 1 naman Sample output 1 0 Sample input 2 reorder Sample output 2 1, 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 line=br.readLine(); int count=0; int i=0,j=line.length()-1; while(i<line.length() && j>=0) { if(line.charAt(i)!=line.charAt(j)) count++; i++; j--; } System.out.print(count/2); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Tom loves palindromes. He has the power to convert any ordinary string to a palindrome. In one move tom can choose a character of a string and change it to any other character. Given a string, find the minimum number of moves in which tom can change it to a palindrome.Input consists of a string. Every character of a string contains lowercase alphabets 'a' to 'z' inclusive. Constraints 1 <= |s| <= 1000The minimum number of moves to convert the given string to a palindrome.Sample input 1 naman Sample output 1 0 Sample input 2 reorder Sample output 2 1, 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() { string s; cin>>s; int n=s.size(); int cnt=0; for(int i=0;i<n/2;i++) { if(s[i]!=s[n-1-i]) cnt++; } cout<<cnt<<endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: For a number N we have N! unique permutations. <b>A permutation is a sequence of integers from 1 to N of length N containing each number exactly once.</b> For a positive integer X, <b>X! = 1 * 2 * 3 *...* X-1 * X</b> Your task is to find the Kth smallest permutation when all possible permutations of size N are arranged in sorted order.Input contains only two integers, the value of N and K. Constraints:- 1 <= N <= 10000 1 <= K <= min(N!,100000000)Print the Kth permutation in form of a string. i. e don't print spaces between two numbers.Sample Input:- 3 5 Sample Output:- 312 Explanation:- All permutations of length 3 are:- 123 132 213 231 312 321 Sample Input:- 11 2 Sample Output:- 1234567891110, 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 s[]=br.readLine().split(" "); int n=Integer.parseInt(s[0]); int k=Integer.parseInt(s[1]); Main m=new Main(); System.out.print(m.getPermutation(n,k)); } public String getPermutation(int n, int k) { int idx = 1; for ( idx = 1; idx <= n;idx++) { if (fact(idx) >= k) break; } StringBuilder ans = new StringBuilder(); for( int i = 1; i <=n-idx;i++) { ans.append(i); } ArrayList<Integer> dat = new ArrayList<>(n); for( int i = 1; i <= idx;i++) { dat.add(i); } for( int i = 1; i <= idx;i++) { int t = (int) ((k-1)/fact(idx-i)); ans.append(dat.get(t)+(n-idx)); dat.remove(t); k = (int)(k-t*(fact(idx-i))); } return ans.toString(); } public String getPermutation0(int n, int k) { int idx = k; StringBuilder ans = new StringBuilder(); ArrayList<Integer> dat = new ArrayList<>(n); for( int i = 1; i <= n;i++) { dat.add(i); } for(int i = 1; i <= n;i++) { idx = (int)((k-1)/fact(n-i)); ans.append(dat.get(idx)); dat.remove(idx); k = (int)(k - idx*fact(n-i)); } return ans.toString(); } public long fact(int n) { int f = 1; for( int i = 1; i <= n;i++) { f *= i; } return f; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: For a number N we have N! unique permutations. <b>A permutation is a sequence of integers from 1 to N of length N containing each number exactly once.</b> For a positive integer X, <b>X! = 1 * 2 * 3 *...* X-1 * X</b> Your task is to find the Kth smallest permutation when all possible permutations of size N are arranged in sorted order.Input contains only two integers, the value of N and K. Constraints:- 1 <= N <= 10000 1 <= K <= min(N!,100000000)Print the Kth permutation in form of a string. i. e don't print spaces between two numbers.Sample Input:- 3 5 Sample Output:- 312 Explanation:- All permutations of length 3 are:- 123 132 213 231 312 321 Sample Input:- 11 2 Sample Output:- 1234567891110, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int factorial(int n) { if (n > 12) { // this overflows in int. So, its definitely greater than k // which is all we care about. So, we return INT_MAX which // is also greater than k. return INT_MAX; } // Can also store these values. But this is just < 12 iteration, so meh! int fact = 1; for (int i = 2; i <= n; i++) fact *= i; return fact; } string getPermutationi(int k, vector<int> &candidateSet) { int n = candidateSet.size(); if (n == 0) { return ""; } if (k > factorial(n)) return ""; // invalid. Should never reach here. int f = factorial(n - 1); int pos = k / f; k %= f; string ch = to_string(candidateSet[pos]); // now remove the character ch from candidateSet. candidateSet.erase(candidateSet.begin() + pos); return ch + getPermutationi(k, candidateSet); } string solve(int n, int k) { vector<int> candidateSet; for (int i = 1; i <= n; i++) candidateSet.push_back(i); return getPermutationi(k - 1, candidateSet); } int main(){ int n,k; cin>>n>>k; cout<<solve(n,k); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, “act” and “tac” are an anagram of each other.Input consists of two strings in lowercase english characters. Constraints: 1 ≤ |s1|, |s2| ≤ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input naman manan Sample Output YES Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., 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 s1 = br.readLine(); String s2 = br.readLine(); boolean flag = true; int[] arr1 = new int[26]; int[] arr2 = new int[26]; for(int i=0; i<s1.length(); i++){ arr1[s1.charAt(i)-97]++; } for(int i=0; i<s2.length(); i++){ arr2[s2.charAt(i)-97]++; } for(int i=0; i<25; i++){ if(arr1[i]!=arr2[i]){ flag = false; break; } } if(flag==true) 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 a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, “act” and “tac” are an anagram of each other.Input consists of two strings in lowercase english characters. Constraints: 1 ≤ |s1|, |s2| ≤ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input naman manan Sample Output YES Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., I have written this Solution Code: s1 = input().strip() s2 = input().strip() dict1 = dict() dict2 = dict() for i in s1: dict1[i] = dict1.get(i, 0) + 1 for j in s2: dict2[j] = dict2.get(j, 0) + 1 print(("NO", "YES")[dict1 == dict2]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, “act” and “tac” are an anagram of each other.Input consists of two strings in lowercase english characters. Constraints: 1 ≤ |s1|, |s2| ≤ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input naman manan Sample Output YES Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., 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 int A[26],B[26]; signed main() { string s,p; cin>>s>>p; for(int i=0;i<s.size();i++) { int y=s[i]-'a'; A[y]++; } for(int i=0;i<p.size();i++) { int y=p[i]-'a'; B[y]++; }int ch=1; for(int i=0;i<26;i++) { if(B[i]!=A[i])ch=0; } if(ch==1) cout<<"YES"<<endl; else cout<<"NO"<<endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, “act” and “tac” are an anagram of each other.Input consists of two strings in lowercase english characters. Constraints: 1 ≤ |s1|, |s2| ≤ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input naman manan Sample Output YES Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., I have written this Solution Code: // str1 and str2 are the two input strings function isAnagram(str1,str2){ // Get lengths of both strings let n1 = str1.length; let n2 = str2.length; // If length of both strings is not same, // then they cannot be anagram if (n1 != n2) return "NO"; str1 = str1.split('') str2 = str2.split('') // Sort both strings str1.sort(); str2.sort() // Compare sorted strings for (let i = 0; i < n1; i++) if (str1[i] != str2[i]) return "NO"; return "YES"; } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string of length N, count the number of vowels present at even places.First line of input contains a single integer N. Second line contains a string of size N. Constraints:- 1 <= N <= 100000 Note:- String will contain only lowercase english letterPrint the number of vowels present at the even placesSample Input:- 12 newtonschool Sample Output:- 2 Sample Input:- 5 basid Sample Output:- 2, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader reader =new BufferedReader(new InputStreamReader(System.in)); String name = reader.readLine(); String s=reader.readLine(); long c=0; for(int i=1;i<s.length();i=i+2){ if(s.charAt(i)=='a'||s.charAt(i)=='e'||s.charAt(i)=='i'||s.charAt(i)=='o'||s.charAt(i)=='u') c++; } System.out.println(c); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string of length N, count the number of vowels present at even places.First line of input contains a single integer N. Second line contains a string of size N. Constraints:- 1 <= N <= 100000 Note:- String will contain only lowercase english letterPrint the number of vowels present at the even placesSample Input:- 12 newtonschool Sample Output:- 2 Sample Input:- 5 basid Sample Output:- 2, I have written this Solution Code: def check(c): if c=='a' or c=='e' or c=='i' or c=='o' or c=='u': return True else: return False n=int(input()) s=input() j=0 cnt=0 ans=0 for i in range(0,n): j=i+1 if j%2==0: if check(s[i]): #=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u': cnt+=1 print(cnt) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string of length N, count the number of vowels present at even places.First line of input contains a single integer N. Second line contains a string of size N. Constraints:- 1 <= N <= 100000 Note:- String will contain only lowercase english letterPrint the number of vowels present at the even placesSample Input:- 12 newtonschool Sample Output:- 2 Sample Input:- 5 basid Sample Output:- 2, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; bool check(char c){ if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u'){return true;} else{ return false; } } int main() { int n; cin>>n; string s; cin>>s; int j=0; int cnt=0; int ans=0; for(int i=0;i<n;i++){ if(i&1){ if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u'){ cnt++; }} } cout<<cnt; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: We are given a string. Your task is to compress the consecutive letters of the string For example, given string is "AAACCCBBD", thus here A's occurrence 3 times C's occurrence 3 times B's occurrence 2 times D's occurrence 1 time So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line. Constraints: 1 <= T <= 10 1 <= sizeof(String) <= 10^6 All characters of String are upper case letters. (A-Z) Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input: 2 AAACCCBBD ABCD Output: A3C3B2D1 A1B1C1D1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void compress(String str, int l){ for (int i = 0; i < l; i++) { int count = 1; while (i < l - 1 && str.charAt(i) == str.charAt(i + 1)) { count++; i++; } System.out.print(str.charAt(i)); System.out.print(count); } System.out.println(); } public static void main (String[] args) throws IOException{ BufferedReader rd = new BufferedReader(new InputStreamReader(System.in)); int test = Integer.parseInt(rd.readLine()); while(test-->0){ String s = rd.readLine(); int len = s.length(); compress(s,len); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: We are given a string. Your task is to compress the consecutive letters of the string For example, given string is "AAACCCBBD", thus here A's occurrence 3 times C's occurrence 3 times B's occurrence 2 times D's occurrence 1 time So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line. Constraints: 1 <= T <= 10 1 <= sizeof(String) <= 10^6 All characters of String are upper case letters. (A-Z) Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input: 2 AAACCCBBD ABCD Output: A3C3B2D1 A1B1C1D1, I have written this Solution Code: def compress(st): n = len(st) i = 0 while i < n: count = 1 while (i < n-1 and st[i] == st[i + 1]): count += 1 i += 1 i += 1 print(st[i-1] +str(count),end="") t=int(input()) for i in range(t): s=input() compress(s) print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: We are given a string. Your task is to compress the consecutive letters of the string For example, given string is "AAACCCBBD", thus here A's occurrence 3 times C's occurrence 3 times B's occurrence 2 times D's occurrence 1 time So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line. Constraints: 1 <= T <= 10 1 <= sizeof(String) <= 10^6 All characters of String are upper case letters. (A-Z) Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input: 2 AAACCCBBD ABCD Output: A3C3B2D1 A1B1C1D1, I have written this Solution Code: #include "bits/stdc++.h" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; void solve(){ string s; cin >> s; int c = 1; char p = 0; int n = s.length(); for(int i = 1; i < n; i++){ if(s[i] != s[i-1]){ cout << s[i-1] << c; c = 1; } else c++; } cout << s[n-1] << c << endl; } void testcases(){ int tt = 1; cin >> tt; while(tt--){ solve(); } } signed main() { IOS; clock_t start = clock(); testcases(); cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of size N, your task is to calculate the total sum of maximum and minimum elements in each subarray of size K. See example for better understanding.First line of input contains an two space separated integers depicting values of N and K, next line contains N space separated integers depicting values of Arr[i]. Constraints:- 1 < = k < = N < = 100000 -100000 < = Arr[i] < = 100000Print the required sumSample Input:- 5 3 1 2 3 4 5 Sample Output:- 18 Explanation:- For subarray 1 2 3 :- 1 + 3 = 4 For subarray 2 3 4 :- 2 + 4 = 6 For subarray 3 4 5 :- 3 + 5 = 8 total sum = 4+6+8 = 18 Sample Input:- 7 4 2 5 -1 7 -3 -1 -2 Sample Output:- 18, 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 a[]=br.readLine().split(" "); int n=Integer.parseInt(a[0]); int k=Integer.parseInt(a[1]); String s[]=br.readLine().split(" "); int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=Integer.parseInt(s[i]); int min=100000,max=-100000; long sum=0; for(int i=0;i<n-k+1;i++){ min=100000; max=-100000; for(int j=i;j<k+i;j++){ min=Math.min(arr[j],min); max=Math.max(arr[j],max); } sum=sum+max+min; } System.out.print(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of size N, your task is to calculate the total sum of maximum and minimum elements in each subarray of size K. See example for better understanding.First line of input contains an two space separated integers depicting values of N and K, next line contains N space separated integers depicting values of Arr[i]. Constraints:- 1 < = k < = N < = 100000 -100000 < = Arr[i] < = 100000Print the required sumSample Input:- 5 3 1 2 3 4 5 Sample Output:- 18 Explanation:- For subarray 1 2 3 :- 1 + 3 = 4 For subarray 2 3 4 :- 2 + 4 = 6 For subarray 3 4 5 :- 3 + 5 = 8 total sum = 4+6+8 = 18 Sample Input:- 7 4 2 5 -1 7 -3 -1 -2 Sample Output:- 18, I have written this Solution Code: from collections import deque def solve(arr,n,k): Sum = 0 S = deque() G = deque() for i in range(k): while ( len(S) > 0 and arr[S[-1]] >= arr[i]): S.pop() while ( len(G) > 0 and arr[G[-1]] <= arr[i]): G.pop() G.append(i) S.append(i) for i in range(k, n): Sum += arr[S[0]] + arr[G[0]] while ( len(S) > 0 and S[0] <= i - k): S.popleft() while ( len(G) > 0 and G[0] <= i - k): G.popleft() while ( len(S) > 0 and arr[S[-1]] >= arr[i]): S.pop() while ( len(G) > 0 and arr[G[-1]] <= arr[i]): G.pop() G.append(i) S.append(i) Sum += arr[S[0]] + arr[G[0]] return Sum n,k=map(int,input().split()) l=list(map(int,input().split())) print(solve(l,n,k)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of size N, your task is to calculate the total sum of maximum and minimum elements in each subarray of size K. See example for better understanding.First line of input contains an two space separated integers depicting values of N and K, next line contains N space separated integers depicting values of Arr[i]. Constraints:- 1 < = k < = N < = 100000 -100000 < = Arr[i] < = 100000Print the required sumSample Input:- 5 3 1 2 3 4 5 Sample Output:- 18 Explanation:- For subarray 1 2 3 :- 1 + 3 = 4 For subarray 2 3 4 :- 2 + 4 = 6 For subarray 3 4 5 :- 3 + 5 = 8 total sum = 4+6+8 = 18 Sample Input:- 7 4 2 5 -1 7 -3 -1 -2 Sample Output:- 18, I have written this Solution Code: // C++ program to find sum of all minimum and maximum // elements Of Sub-array Size k. #include<bits/stdc++.h> using namespace std; #define int long long int int SumOfKsubArray(int arr[] , int n , int k) { int sum = 0; // Initialize result // The queue will store indexes of useful elements // in every window // In deque 'G' we maintain decreasing order of // values from front to rear // In deque 'S' we maintain increasing order of // values from front to rear deque< int > S(k), G(k); // Process first window of size K int i = 0; for (i = 0; i < k; i++) { // Remove all previous greater elements // that are useless. while ( (!S.empty()) && arr[S.back()] >= arr[i]) S.pop_back(); // Remove from rear // Remove all previous smaller that are elements // are useless. while ( (!G.empty()) && arr[G.back()] <= arr[i]) G.pop_back(); // Remove from rear // Add current element at rear of both deque G.push_back(i); S.push_back(i); } // Process rest of the Array elements for ( ; i < n; i++ ) { // Element at the front of the deque 'G' & 'S' // is the largest and smallest // element of previous window respectively sum += arr[S.front()] + arr[G.front()]; // Remove all elements which are out of this // window while ( !S.empty() && S.front() <= i - k) S.pop_front(); while ( !G.empty() && G.front() <= i - k) G.pop_front(); // remove all previous greater element that are // useless while ( (!S.empty()) && arr[S.back()] >= arr[i]) S.pop_back(); // Remove from rear // remove all previous smaller that are elements // are useless while ( (!G.empty()) && arr[G.back()] <= arr[i]) G.pop_back(); // Remove from rear // Add current element at rear of both deque G.push_back(i); S.push_back(i); } // Sum of minimum and maximum element of last window sum += arr[S.front()] + arr[G.front()]; return sum; } // Driver program to test above functions signed main() { int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } cout << SumOfKsubArray(a, n, k) ; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given head which is a reference node to a singly- linked list. Complete the function delete_end which delete all nodes after M Nodes of a Linked List.User task: Since this will be a functional problem, you don't have to take input. You just have to complete the functions delete_end that takes the head of the linked list as parameter. Constraints: The Linked List is not empty. Number of nodes(N) will not exceed 1000. 1 <= M <= NYou need not return anything. Just modify the original linked list.Sample Input 1:- 3 1 1 2 3 Sample Output 1:- 1 Explanation M = 1 So delete all nodes after 1st node. Sample Input 2:- 5 3 1 2 3 4 5 Sample Output 2:- 1 2 3 Explanation: Delete all nodes after 3rd node., I have written this Solution Code: static void delete_end(Node head,int m) { m--; while (m>0) { head = head.next; m--; } head.next=null; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed. Given initial positions of Naruto and Sasuke as A and B recpectively. you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ). if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter. Constraints 1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input 1 2 3 Sample Output S Sample Input 1 3 2 Sample Output D, I have written this Solution Code: char Race(int A, int B, int C){ if(abs(C-A)==abs(C-B)){return 'D';} if(abs(C-A)>abs(C-B)){return 'S';} else{ return 'N';} } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed. Given initial positions of Naruto and Sasuke as A and B recpectively. you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ). if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter. Constraints 1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input 1 2 3 Sample Output S Sample Input 1 3 2 Sample Output D, I have written this Solution Code: def Race(A,B,C): if abs(C-A) ==abs(C-B): return 'D' if abs(C-A)>abs(C-B): return 'S' return 'N' , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed. Given initial positions of Naruto and Sasuke as A and B recpectively. you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ). if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter. Constraints 1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input 1 2 3 Sample Output S Sample Input 1 3 2 Sample Output D, I have written this Solution Code: char Race(int A, int B, int C){ if(abs(C-A)==abs(C-B)){return 'D';} if(abs(C-A)>abs(C-B)){return 'S';} else{ return 'N';} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed. Given initial positions of Naruto and Sasuke as A and B recpectively. you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ). if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter. Constraints 1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input 1 2 3 Sample Output S Sample Input 1 3 2 Sample Output D, I have written this Solution Code: static char Race(int A,int B,int C){ if(Math.abs(C-A)==Math.abs(C-B)){return 'D';} if(Math.abs(C-A)>Math.abs(C-B)){return 'S';} else{ return 'N';} }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: <em>The JS Date object has many useful properties. </em> Implement the function <code>whichDay</code>, which takes a Date object and returns a string like this "It is the first day of the week" depending on that object it will show the return string, which day of the week it is. (Use JS built-in functions) Note:- Sunday is the "last" day of the week while rest all days are the first, second, third, fourth, fifth, and sixth dayThe function takes an argument <code>date</code> which is a Date object.The function returns a stringconst date = new Date("2022", "1", "2") // Wed Feb 02 2022 // In the above line we create a Date object using Date Class which is used to create arbitrary dates console.log(whichDay(date)) // prints "It is the third day of the week", I have written this Solution Code: function whichDay(date) { // write code here // return the output , do not use console.log here let str = "" switch (date.getDay()) { case 0: str = 'last' break; case 1: str = 'first' break; case 2: str = 'second' break; case 3: str = 'third' break; case 4: str = 'fourth' break; case 5: str = 'fifth' break; case 6: str = 'sixth' break; default: break; } return `Today is the ${str} day of the week` }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N in the form of a string, find the number of its good substrings. A good substring is a substring that is divisible by the given prime p. A good substring can start with a 0.The first line of input contains a single number, the length of the string, |N| The second line of input contains the number N. The third and final line of input contains a prime number p. Constraints 1 <= |N| <= 100000 2 <= p <= 10000 p is a prime numberThe only line of output contains the number of good substrings.Sample Input 4 3543 3 Sample Output 6 Explanation Good substrings are 3, 354, 3543, 54, 543, 3, 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 n = Integer.parseInt(br.readLine()); String str = br.readLine(); int p = Integer.parseInt(br.readLine()); System.out.print(getCount(n, str, p)); } static int getCount(int n, String str, int p){ int count = 0; int[] arr = new int[p]; arr[0] = 1; int curr = 0; int mul = 1; int num = 0; if(p == 2 || p == 5){ for(int i=n-1; i>=0; i--){ if(Character.getNumericValue(str.charAt(i))%p == 0){ count+=i+1; } } return count; } for(int i=n-1; i>=0; i--){ int dig = str.charAt(i)-'0'; dig*=mul; dig%=p; curr += dig; curr %= p; count += arr[curr]; arr[curr]++; mul *= 10; mul %= p; } return count; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N in the form of a string, find the number of its good substrings. A good substring is a substring that is divisible by the given prime p. A good substring can start with a 0.The first line of input contains a single number, the length of the string, |N| The second line of input contains the number N. The third and final line of input contains a prime number p. Constraints 1 <= |N| <= 100000 2 <= p <= 10000 p is a prime numberThe only line of output contains the number of good substrings.Sample Input 4 3543 3 Sample Output 6 Explanation Good substrings are 3, 354, 3543, 54, 543, 3, I have written this Solution Code: from collections import Counter N = int(input()) S = input().strip() P = int(input()) if P == 2 or P == 5: ans=0 for i in range(N): if int(S[i])%P==0: ans+=(i+1) print(ans) exit() S = [int(i) for i in S][::-1] T = [0]*(N+1) x = 1 for i in range(N): T[i+1] = S[i]*x + T[i] T[i+1] %= P x *= 10 x %= P ans = 0 for k,v in Counter(T).items(): ans += v*(v-1)//2 print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N in the form of a string, find the number of its good substrings. A good substring is a substring that is divisible by the given prime p. A good substring can start with a 0.The first line of input contains a single number, the length of the string, |N| The second line of input contains the number N. The third and final line of input contains a prime number p. Constraints 1 <= |N| <= 100000 2 <= p <= 10000 p is a prime numberThe only line of output contains the number of good substrings.Sample Input 4 3543 3 Sample Output 6 Explanation Good substrings are 3, 354, 3543, 54, 543, 3, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define sd(x) scanf("%d", &x) #define sz(v) (int) v.size() #define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl; #define slld(x) scanf("%lld", &x) #define all(x) x.begin(), x.end() #define For(i, st, en) for(ll 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 pb push_back #define ll long long #define int long long #define mp make_pair #define F first #define S second typedef pair<int, int> pii; typedef vector<int> vi; #define MOD 1000000007 #define INF 1000000000000000007LL const int N = 100005; // it's swapnil07 ;) #ifdef SWAPNIL07 #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } int begtime = clock(); #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; #else #define endl '\n' #define trace(...) #define end_routine() #endif signed main() { fast #ifdef SWAPNIL07 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int n; cin>>n; string s; cin>>s; int p; cin>>p; int arr[p+1]; memset(arr, 0, sizeof(arr)); arr[0]=1; int mult = 1; int cur = 0; int ans = 0; if (p == 2 || p == 5){ for (int i = n-1; i >= 0; --i){ if ((s[i]-'0') % p == 0){ ans += i + 1; } } cout<<ans; return 0; } for(int i=n-1; i>=0; i--){ int a = s[i]-'0'; a *= mult; a %= p; cur += a; cur %= p; ans += arr[cur]; // trace(ans); arr[cur]++; mult *= 10; mult %= p; } cout<<ans; 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 print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b> There will be two functions: <ul> <li>verticalFive(): Print stars in vertical order</li> <li>horizontalFive(): Print stars in horizontal order</l> </ul><b>User Task:</b> Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>. Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function. <b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input: Sample Output: * * * * * * * * * *, I have written this Solution Code: static void verticalFive(){ System.out.println("*"); System.out.println("*"); System.out.println("*"); System.out.println("*"); System.out.println("*"); } static void horizontalFive(){ System.out.print("* * * * *"); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b> There will be two functions: <ul> <li>verticalFive(): Print stars in vertical order</li> <li>horizontalFive(): Print stars in horizontal order</l> </ul><b>User Task:</b> Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>. Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function. <b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input: Sample Output: * * * * * * * * * *, I have written this Solution Code: def vertical5(): for i in range(0,5): print("*",end="\n") #print() def horizontal5(): for i in range(0,5): print("*",end=" ") vertical5() print(end="\n") horizontal5(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: The question is super small and super simple. You are given an integer n. Initially you have an empty string. You need to construct the string of length n with the following rules: 1. Insert the first character in the beginning of string, the second in the end, the third in the beginning, fourth in the end, and so on. 2. The first character should be 'a', followed by 'b', 'c', and so on. 'z' will be followed by 'a'.The first and the only line of input contains a single number n. Constraints 1 <= n <= 500000Output the generated string.Sample Input 4 Sample Output cabd Sample Input 30 Sample Output caywusqomkigecabdfhjlnprtvxzbd Explanation In the first case the string transforms as follows: "" -> "a" -> "ab" -> "cab" -> "cabd", 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)); int n=Integer.parseInt(scan.readLine()); char ch='a'; boolean isFirst = true; StringBuilder sb = new StringBuilder(); for(int i=0;i<n;i++) { if(isFirst) { sb.insert(0, (char)(ch + i%26)); } else { sb.append((char) (ch + i%26)); } isFirst = !isFirst; } System.out.print(sb.toString()); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: The question is super small and super simple. You are given an integer n. Initially you have an empty string. You need to construct the string of length n with the following rules: 1. Insert the first character in the beginning of string, the second in the end, the third in the beginning, fourth in the end, and so on. 2. The first character should be 'a', followed by 'b', 'c', and so on. 'z' will be followed by 'a'.The first and the only line of input contains a single number n. Constraints 1 <= n <= 500000Output the generated string.Sample Input 4 Sample Output cabd Sample Input 30 Sample Output caywusqomkigecabdfhjlnprtvxzbd Explanation In the first case the string transforms as follows: "" -> "a" -> "ab" -> "cab" -> "cabd", I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define sd(x) scanf("%d", &x) #define sz(v) (int) v.size() #define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl; #define slld(x) scanf("%lld", &x) #define all(x) x.begin(), x.end() #define For(i, st, en) for(ll 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 pb push_back #define ll long long #define int long long #define mp make_pair #define F first #define S second typedef pair<int, int> pii; typedef vector<int> vi; #define MOD 1000000007 #define INF 1000000000000000007LL const int N = 100005; // it's swapnil07 ;) #ifdef SWAPNIL07 int begtime = clock(); #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; #else #define endl '\n' #define end_routine() #endif signed main() { fast #ifdef SWAPNIL07 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int n; cin>>n; deque<char> vect; int cur = 0; bool fl = false; for(int i=0; i<n; i++){ if(!fl) vect.push_front('a'+cur); else vect.push_back('a'+cur); cur = (cur+1)%26; fl = !fl; } while(!vect.empty()){ char c = vect.front(); vect.pop_front(); cout<<c; } // end_routine(); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number is called Silly if it can be represented as the sum of the square of consecutive natural numbers starting from 1. For a given number N, find the closest silly number.<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>SillyNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the closest Silly number. Note:- If more than one answer exists return the minimum one.Sample Input:- 18 Sample Output:- 14 Explanation:- 1*1 + 2*2 + 3*3 = 14 Sample Input:- 2 Sample Output:- 1, I have written this Solution Code: static int SillyNumber(int N){ int sum=0; int x=1; while(sum<N){ sum+=x*x; x++; } x--; if(sum-N < N-(sum-x*x)){ return sum; } else{ return sum-x*x; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number is called Silly if it can be represented as the sum of the square of consecutive natural numbers starting from 1. For a given number N, find the closest silly number.<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>SillyNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the closest Silly number. Note:- If more than one answer exists return the minimum one.Sample Input:- 18 Sample Output:- 14 Explanation:- 1*1 + 2*2 + 3*3 = 14 Sample Input:- 2 Sample Output:- 1, I have written this Solution Code: int SillyNumber(int N){ int sum=0; int x=1; while(sum<N){ sum+=x*x; x++; } x--; if(sum-N < N-(sum-x*x)){ return sum; } else{ return sum-x*x; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number is called Silly if it can be represented as the sum of the square of consecutive natural numbers starting from 1. For a given number N, find the closest silly number.<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>SillyNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the closest Silly number. Note:- If more than one answer exists return the minimum one.Sample Input:- 18 Sample Output:- 14 Explanation:- 1*1 + 2*2 + 3*3 = 14 Sample Input:- 2 Sample Output:- 1, I have written this Solution Code: int SillyNumber(int N){ int sum=0; int x=1; while(sum<N){ sum+=x*x; x++; } x--; if(sum-N < N-(sum-x*x)){ return sum; } else{ return sum-x*x; } }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number is called Silly if it can be represented as the sum of the square of consecutive natural numbers starting from 1. For a given number N, find the closest silly number.<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>SillyNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the closest Silly number. Note:- If more than one answer exists return the minimum one.Sample Input:- 18 Sample Output:- 14 Explanation:- 1*1 + 2*2 + 3*3 = 14 Sample Input:- 2 Sample Output:- 1, I have written this Solution Code: def SillyNumber(N): sum=0 x=1 while sum<N: sum=sum+x*x x=x+1 x=x-1 if (sum-N) < (N-(sum-x*x)): return sum; else: return sum - x*x , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable