Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: Given a N x M integer matrix A and Q queries of form X1 Y1 X2 Y2. Print the sum of A[i][j], for X1 <= i <= X2 and Y1 <= j <= Y2.The first line contains two integer N and M, denoting the size of the matrix. Next N line contains M integers denoting elements of the matrix. Next line contains a single integer Q, denoting the number of queries. Next Q lines lines four integers X1 Y1 X2 Y2, denoting the query as mentioned in problem statement 1 <= N, M <= 100 1 <= A[i][j] <= 100 1 <= Q <= 100000 1 <= X1 <= X2 <= N 1 <= Y1 <= Y2 <= MPrint Q lines containing the answer to each query.Sample Input: 2 2 1 5 2 3 3 1 1 1 1 1 1 1 2 1 1 2 2 Sample Output: 1 6 11 Explanation: Q1: 1 Q2: 1 + 5 = 6 Q3: 1 + 5 + 2 + 3 = 11, 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 = 1e2 + 5; const int ten6 = 1e6; const int inf = 1e9 + 9; int a[N][N]; void solve(){ int n, m; cin >> n >> m; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cin >> a[i][j]; a[i][j] += a[i-1][j] + a[i][j-1] - a[i-1][j-1]; } } int q; cin >> q; while(q--){ int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; cout << a[x2][y2] - a[x1-1][y2] - a[x2][y1-1] + a[x1-1][y1-1] << endl; } } void testcases(){ int tt = 1; //cin >> tt; while(tt--){ solve(); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t start = clock(); testcases(); cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: "; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two elements A and B, your task is to swap the given two elements.<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>Swap(int A, int B)</b>.Print one line which contains the output of swapped elements.Sample Input:- 5 7 Sample Output:- 7 5 Sample Input:- 3 6 Sample Output:- 6 3, I have written this Solution Code: class Solution { public static void Swap(int A, int B){ int C = A; A = B; B = C; System.out.println(A + " " + B); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two elements A and B, your task is to swap the given two elements.<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>Swap(int A, int B)</b>.Print one line which contains the output of swapped elements.Sample Input:- 5 7 Sample Output:- 7 5 Sample Input:- 3 6 Sample Output:- 6 3, I have written this Solution Code: # Python program to swap two variables li= list(map(int,input().strip().split())) x=li[0] y=li[1] # create a temporary variable and swap the values temp = x x = y y = temp print(x,end=" ") print(y,end="") , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N. <b>Value</b> of an element A<sub>i</sub> is defined as the sum of the absolute difference of all elements of the array with A<sub>i</sub>. More formally, the value of an element at index i is the sum of |A<sub>i</sub> - A<sub>j</sub>| over all j (1 <= j <= N). Find the maximum such value over all i (1 <= i <= N) in the array. <b>Note</b>: Given array is 1-based indexThe first line of the input contains a single integer N. The second line of the input contains N space-separated integers. <b>Constraints:</b> 1 &le; N &le; 10<sup>5</sup> 1 &le; A<sub>i</sub> &le; 10<sup>9</sup>Print the maximum such value over all i (1 <= i <= N) in the array.Sample Input: 6 1 1 5 5 8 9 Sample Output: 25 <b>Explanation:</b> For, i = 6, |A<sub>1</sub> - A<sub>6</sub>| = 8 |A<sub>2</sub> - A<sub>6</sub>| = 8 |A<sub>3</sub> - A<sub>6</sub>| = 4 |A<sub>4</sub> - A<sub>6</sub>| = 4 |A<sub>5</sub> - A<sub>6</sub>| = 1 Value = 8 + 8 + 4 + 4 + 1 = 25 For all other i, give values less than 25., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); #define int long long #define pb push_back #define ff first #define ss second #define endl '\n' #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using T = pair<int, int>; typedef long double ld; const int mod = 1e9 + 7; const int INF = 2e9; void solve(){ int n; cin >> n; vector<int> a(n + 1); for(int i = 1; i <= n; i++) cin >> a[i]; sort(a.begin(), a.end()); vector<int> pre(n + 1); for(int i = 1; i <= n; i++){ pre[i] = pre[i - 1] + a[i]; } int ans = 0; for(int i = 1; i <= n; i++){ ans = max(ans, (pre[n] - pre[i]) - ((n - i) * (a[i])) + ((i-1)* a[i]) - pre[i - 1]); } cout << ans; } signed main(){ fast int t = 1; // cin >> t; for(int i = 1; i <= t; i++){ solve(); if(i != t) cout << endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of 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: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n. Constraint:- 1<=size of n<=100Output is a single line containing reversed number n.Sample Input 123445 Sample Output 544321 Sample Input 16724368 Sample Output 86342761, 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(); int i=str.length()-1; if(i==0){ int number=Integer.parseInt(str); System.out.println(number); }else{ while(str.charAt(i)=='0'){ i--; } for(int j=i;j>=0;j--){ System.out.print(str.charAt(j)); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n. Constraint:- 1<=size of n<=100Output is a single line containing reversed number n.Sample Input 123445 Sample Output 544321 Sample Input 16724368 Sample Output 86342761, I have written this Solution Code: n=int(input()) def reverse(n): return int(str(n)[::-1]) print(reverse(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n. Constraint:- 1<=size of n<=100Output is a single line containing reversed number n.Sample Input 123445 Sample Output 544321 Sample Input 16724368 Sample Output 86342761, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main() { string s; cin>>s; reverse(s.begin(),s.end()); int I; for( I=0;I<s.length();I++){ if(s[I]!='0'){break;} } if(I==s.length()){cout<<0;return 0;} for(int j=I;j<s.length();j++){ cout<<s[j];} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x. Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements. <b>Constraints:</b> 1 ≤ T ≤ 100 1 ≤ N ≤ 10^5 1 ≤ arr[i] ≤ 10^18 0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput: 3 7 0 1 2 8 10 11 12 19 7 5 1 2 8 10 11 12 19 7 10 1 2 8 10 11 12 19 Output: -1 1 3 Explanation: Testcase 1: No element less than or equal to 0 is found. So output is "-1". Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing). Testcase 3: Number less than or equal to 10 is 10 and its index is 3., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static int BS(int arr[],int x,int start,int end){ if( start > end) return start-1; int mid = start + (end - start)/2; if(arr[mid]==x) return mid; if(arr[mid]>x) return BS(arr,x,start,mid-1); return BS(arr,x,mid+1,end); } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); String[] s; for(;t>0;t--){ s = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int x = Integer.parseInt(s[1]); s = br.readLine().split(" "); int[] arr = new int[n]; for(int i=0;i<n;i++) arr[i] = Integer.parseInt(s[i]); int res = BS(arr,x,0,arr.length-1); System.out.println(res); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x. Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements. <b>Constraints:</b> 1 ≤ T ≤ 100 1 ≤ N ≤ 10^5 1 ≤ arr[i] ≤ 10^18 0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput: 3 7 0 1 2 8 10 11 12 19 7 5 1 2 8 10 11 12 19 7 10 1 2 8 10 11 12 19 Output: -1 1 3 Explanation: Testcase 1: No element less than or equal to 0 is found. So output is "-1". Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing). Testcase 3: Number less than or equal to 10 is 10 and its index is 3., I have written this Solution Code: def bsearch(arr,e,l,r): if(r>=l): mid = l + (r - l)//2 if (arr[mid] == e): return mid elif arr[mid] > e: return bsearch(arr, e,l, mid-1) else: return bsearch(arr,e, mid + 1, r) else: return r t=int(input()) for i in range(t): ip=list(map(int,input().split())) l=list(map(int,input().split())) le=ip[0] e=ip[1] print(bsearch(sorted(l),e,0,le-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x. Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements. <b>Constraints:</b> 1 ≤ T ≤ 100 1 ≤ N ≤ 10^5 1 ≤ arr[i] ≤ 10^18 0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput: 3 7 0 1 2 8 10 11 12 19 7 5 1 2 8 10 11 12 19 7 10 1 2 8 10 11 12 19 Output: -1 1 3 Explanation: Testcase 1: No element less than or equal to 0 is found. So output is "-1". Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing). Testcase 3: Number less than or equal to 10 is 10 and its index is 3., 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 t; cin >> t; while(t--){ int n, x; cin >> n >> x; for(int i = 0; i < n; i++) cin >> a[i]; int l = -1, h = n; while(l+1 < h){ int m = (l + h) >> 1; if(a[m] <= x) 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 linked list where in addition to the next pointer, each node has a child pointer, which may or may not point to a separate list. These child lists may have one or more children of their own, and so on, to produce a multilevel data structure, as shown in below figure.You are given the head of the first level of the list. Flatten the list so that all the nodes appear in a single-level linked list. You need to flatten the list in way that all nodes at first level should come first, then nodes of second level, and so on.User task: Since this is a functional problem you don't have to worry about input, you just have to complete the function <b>flattenList()</b> that takes the head node of the tree as input. Constraints: 1 <= N <= 100 1 <= Data of Nodes <= 100You don't need to print anything you just need to make the given head as the head of the singly linked list. Printing is done by the driver codeSample Input:- 1 → 2 → 3 → 4 ↓ ↓ ↓ 9 → 8 11 → 12 5 → 6 → 7 ↓ 13 → 14 → 15 Sample Output:- 1 2 3 4 9 8 11 12 5 6 7 13 14 15, I have written this Solution Code: static void flattenList(Node head) { /*Base case*/ if (head == null) { return; } Node tmp = null; /* Find tail node of first level linked list */ Node tail = head; while (tail.next != null) { tail = tail.next; } // One by one traverse through all nodes of first level // linked list till we reach the tail node Node cur = head; while (cur != tail) { // If current node has a child if (cur.Child != null) { // then append the child at the end of current list tail.next = cur.Child; // and update the tail to new last node tmp = cur.Child; while (tmp.next != null) { tmp = tmp.next; } tail = tmp; } // Change current node cur = cur.next; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix. Constraints:- 1 <= M, N <= 100 1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:- 3 3 1 2 3 4 5 6 7 8 9 Sample Output:- 18 Explanation:- 1 + 4 + 7 = 12 2 + 5 + 8 = 15 3 + 6 + 9 = 18 maximum = 18 Sample Input:- 3 2 1 4 9 6 9 1 Sample Output:- 19, I have written this Solution Code: m,n=map(int ,input().split()) matrix=[] for i in range(m): l1=[eval(x) for x in input().split()] matrix.append(l1) l2=[] for coloumn in range(n): sum1=0 for row in range(m): sum1+= matrix[row][coloumn] l2.append(sum1) print(max(l2)) '''for row in range(n): sum2=0 for col in range(m): sum2 += matrix[row][col] print(sum2)''', In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix. Constraints:- 1 <= M, N <= 100 1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:- 3 3 1 2 3 4 5 6 7 8 9 Sample Output:- 18 Explanation:- 1 + 4 + 7 = 12 2 + 5 + 8 = 15 3 + 6 + 9 = 18 maximum = 18 Sample Input:- 3 2 1 4 9 6 9 1 Sample Output:- 19, I have written this Solution Code: // mat is the matrix/ 2d array // the dimensions of array are:- a rows, b columns function colMaxSum(mat,a,b) { // write code here // do not console.log // return the answer as a number let idx = -1; // Variable to store max sum let maxSum = Number.MIN_VALUE; // Traverse matrix column wise for (let i = 0; i < b; i++) { let sum = 0; // calculate sum of column for (let j = 0; j < a; j++) { sum += mat[j][i]; } // Update maxSum if it is // less than current sum if (sum > maxSum) { maxSum = sum; // store index idx = i; } } let res; res = [idx, maxSum]; // return result return maxSum; } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix. Constraints:- 1 <= M, N <= 100 1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:- 3 3 1 2 3 4 5 6 7 8 9 Sample Output:- 18 Explanation:- 1 + 4 + 7 = 12 2 + 5 + 8 = 15 3 + 6 + 9 = 18 maximum = 18 Sample Input:- 3 2 1 4 9 6 9 1 Sample Output:- 19, 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 1001 #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(){ int n,m; cin>>n>>m; int a[m]; for(int i=0;i<m;i++){ a[i]=0; } int x; int sum=0; FOR(i,n){ FOR(j,m){ cin>>x; a[j]+=x; sum=max(sum,a[j]); } } out(sum); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix. Constraints:- 1 <= M, N <= 100 1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:- 3 3 1 2 3 4 5 6 7 8 9 Sample Output:- 18 Explanation:- 1 + 4 + 7 = 12 2 + 5 + 8 = 15 3 + 6 + 9 = 18 maximum = 18 Sample Input:- 3 2 1 4 9 6 9 1 Sample Output:- 19, 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 m = sc.nextInt(); int n = sc.nextInt(); int a[][] = new int[m][n]; for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ a[i][j]=sc.nextInt(); } } int sum=0; int ans=0; for(int i=0;i<n;i++){ sum=0; for(int j=0;j<m;j++){ sum+=a[j][i]; } if(sum>ans){ans=sum;} } System.out.print(ans); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Let's define P[i] as the ith Prime Number. Therefore, P[1]=2, P[2]=3, P[3]=5, so on. Given two integers L, R (L<=R), find the value of P[L]+P[L+1]+P[L+2]...+P[R].The first line of the input contains an integer T denoting the number of test cases. The next T lines contain two integers L and R. Constraints 1 <= T <= 50000 1 <= L <= R <= 50000For each test case, print one line corresponding to the required valueSample Input 4 1 3 2 4 5 5 1 5 Sample Output 10 15 11 28, 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()); int max = 1000001; boolean isNotPrime[] = new boolean[max]; ArrayList<Integer> arr = new ArrayList<Integer>(); isNotPrime[0] = true; isNotPrime[1] = true; for (int i=2; i*i <max; i++) { if (!isNotPrime[i]) { for (int j=i*i; j<max; j+= i) { isNotPrime[j] = true; } } } for(int i=2; i<max; i++) { if(!isNotPrime[i]) { arr.add(i); } } while(t-- > 0) { String str[] = br.readLine().trim().split(" "); int l = Integer.parseInt(str[0]); int r = Integer.parseInt(str[1]); System.out.println(primeRangeSum(l,r,arr)); } } static long primeRangeSum(int l , int r, ArrayList<Integer> arr) { long sum = 0; for(int i=l; i<=r;i++) { sum += arr.get(i-1); } return sum; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Let's define P[i] as the ith Prime Number. Therefore, P[1]=2, P[2]=3, P[3]=5, so on. Given two integers L, R (L<=R), find the value of P[L]+P[L+1]+P[L+2]...+P[R].The first line of the input contains an integer T denoting the number of test cases. The next T lines contain two integers L and R. Constraints 1 <= T <= 50000 1 <= L <= R <= 50000For each test case, print one line corresponding to the required valueSample Input 4 1 3 2 4 5 5 1 5 Sample Output 10 15 11 28, I have written this Solution Code: def SieveOfEratosthenes(n): prime = [True for i in range(n+1)] pri = [] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 for p in range(2, n+1): if prime[p]: pri.append(p) return pri N = int(input()) X = [] prim = SieveOfEratosthenes(1000000) for i in range(1,len(prim)): prim[i] = prim[i]+prim[i-1] for i in range(N): nnn = input() X.append((int(nnn.split()[0]),int(nnn.split()[1]))) for xx,yy in X: if xx==1: print(prim[yy-1]) else: print(prim[yy-1]-prim[xx-2]) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Let's define P[i] as the ith Prime Number. Therefore, P[1]=2, P[2]=3, P[3]=5, so on. Given two integers L, R (L<=R), find the value of P[L]+P[L+1]+P[L+2]...+P[R].The first line of the input contains an integer T denoting the number of test cases. The next T lines contain two integers L and R. Constraints 1 <= T <= 50000 1 <= L <= R <= 50000For each test case, print one line corresponding to the required valueSample Input 4 1 3 2 4 5 5 1 5 Sample Output 10 15 11 28, 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; vector<int> v; v.push_back(0); for(int i = 2; i < N; i++){ if(a[i]) continue; v.push_back(i); for(int j = i*i; j < N; j += i) a[j] = 1; } int p = 0; for(auto &i: v){ i += p; p = i; } int t; cin >> t; while(t--){ int l, r; cin >> l >> r; cout << v[r] - v[l-1] << 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 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: The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'. For example, "ACGAATTCCG" is a DNA sequence. When studying DNA, it is useful to identify repeated sequences within the DNA. Given a string s that represents a DNA sequence, return all the 10-letter long sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in any order. This is a functional problem you have to complete the solve function.The first line of the input contains the string s. <b>Constraints</b> 1 <= s. length() <= 1e5 s[i] is either 'A', 'C', 'G', or 'T'Complete the function and return the relevant strings.Sample Input:- GGGGGGGGGGGGG Sample Output:- GGGGGGGGGG, I have written this Solution Code: from collections import defaultdict dna=input() d=defaultdict(int) for i in range(0,len(dna)-9): d[dna[i:i+10]]+=1 ans=[] for i in d: if(d[i]>1): ans.append(i) ans.sort() for i in ans: print(i), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'. For example, "ACGAATTCCG" is a DNA sequence. When studying DNA, it is useful to identify repeated sequences within the DNA. Given a string s that represents a DNA sequence, return all the 10-letter long sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in any order. This is a functional problem you have to complete the solve function.The first line of the input contains the string s. <b>Constraints</b> 1 <= s. length() <= 1e5 s[i] is either 'A', 'C', 'G', or 'T'Complete the function and return the relevant strings.Sample Input:- GGGGGGGGGGGGG Sample Output:- GGGGGGGGGG, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void DNASequence(String input){ int n = input.length(); HashSet<String> set = new HashSet<>(); HashSet<String> res = new HashSet<>(); ArrayList<String> list = new ArrayList<>(); for(int i=0; i<=n-10 ; i++){ String result = input.substring(i, i+10); if(set.contains(result)){ res.add(result); } set.add(result); } for(String r : res){ list.add(r); } Collections.sort(list); for(String r : list){ System.out.println(r); } } public static void main (String[] args) { Scanner sc = new Scanner(System.in); String input = sc.next(); DNASequence(input); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'. For example, "ACGAATTCCG" is a DNA sequence. When studying DNA, it is useful to identify repeated sequences within the DNA. Given a string s that represents a DNA sequence, return all the 10-letter long sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in any order. This is a functional problem you have to complete the solve function.The first line of the input contains the string s. <b>Constraints</b> 1 <= s. length() <= 1e5 s[i] is either 'A', 'C', 'G', or 'T'Complete the function and return the relevant strings.Sample Input:- GGGGGGGGGGGGG Sample Output:- GGGGGGGGGG, I have written this Solution Code: vector<string> solve(string &s) { string res = ""; for (int i = 0; i < 10; i++) { res += s[i]; } unordered_map<string, int> freq; freq[res] += 1; for (int i = 10; i < s.length(); i++) { res.erase(res.begin()); res += s[i]; freq[res] += 1; } vector<string> result; for (auto &it : freq) { if (it.second > 1) { result.push_back(it.first); } } return result; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a Pyramid pattern of '*' of height N. For N = 5, the following pattern is printed. <center> * </center> <center> *** </center> <center> ***** </center> <center> ******* </center> <center>*********</center>The input contains N as an input. </b>Constraint:</b> 1 <b>&le;</b> N <b>&le;</b> 50Print a Pyramid pattern of '*' of height N.Sample Input: 5 Sample Output: <center> * </center> <center> *** </center> <center> ***** </center> <center> ******* </center> <center>*********</center> Sample Input: 2 Sample Output: <center> * </center> <center> *** </center>, I have written this Solution Code: import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=1;i<=n;i++){ int cnt=2*i-1; for(int j=0;j<n-i;j++)System.out.print(" "); for(int j=0;j<cnt;j++)System.out.print("*"); for(int j=0;j<n-i;j++)System.out.print(" "); System.out.println(""); } System.out.println(""); return; } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a linked list consisting of N nodes and an integer K, your task is to reverse every alternate K nodes. In other words , you have to reverse first k nodes , then skip the next k nodes , then reverse next k nodes and so on . NOTE: if there are not K nodes to reverse then reverse all the nodes left (See example for better understanding)<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>ReverseAlternateK()</b> that takes head node and K as parameter. Constraints: 1 <=k<=N<=10000Return the head of the modified linked list.Sample Input:- 8 3 1 2 3 4 5 6 7 8 Sample Output:- 3 2 1 4 5 6 8 7 Explanation: [{1 , 2 ,3 } , {4, 5 , 6} , {7 , 8}] Reverse 1st segment. Skip the 2nd segment. Reverse the 3rd segment. , I have written this Solution Code: public static Node ReverseAlternateK(Node head,int k){ Node current = head; Node next = null, prev = null; int count = 0; while (current != null && count < k) { next = current.next; current.next = prev; prev = current; current = next; count++; } if (head != null) { head.next = current; } count = 0; while (count < k - 1 && current != null) { current = current.next; count++; } if (current != null) { current.next = ReverseAlternateK(current.next, k); } return prev; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A. In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers. Constraints 1 <= N <= 100 1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1 4 1 2 6 4 output-1 3 10 input-2 10 1 2 3 4 5 6 0 7 8 9 output-2 3 7 11 7 17 Explanation(might now be the optimal solution): Testcase 1: Follow the below steps:- Step 1: [1 2 6 4] Step 2: (1 2) and (6 4) Step 3: 3 10, I have written this Solution Code: n = int(input()) all_no = input().split(' ') i = 0 joined_str = '' while(i < n-1): if(i == 0): joined_str = str(int(all_no[i]) + int(all_no[i+1])) else: joined_str = joined_str + ' ' + str(int(all_no[i]) + int(all_no[i+1])) i = i + 2 print(joined_str), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A. In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers. Constraints 1 <= N <= 100 1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1 4 1 2 6 4 output-1 3 10 input-2 10 1 2 3 4 5 6 0 7 8 9 output-2 3 7 11 7 17 Explanation(might now be the optimal solution): Testcase 1: Follow the below steps:- Step 1: [1 2 6 4] Step 2: (1 2) and (6 4) Step 3: 3 10, 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=sc.nextInt(); int a[] = new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } int t; for(int i=0;i<n;i+=2){ System.out.print(a[i]+a[i+1]+" "); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A. In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers. Constraints 1 <= N <= 100 1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1 4 1 2 6 4 output-1 3 10 input-2 10 1 2 3 4 5 6 0 7 8 9 output-2 3 7 11 7 17 Explanation(might now be the optimal solution): Testcase 1: Follow the below steps:- Step 1: [1 2 6 4] Step 2: (1 2) and (6 4) Step 3: 3 10, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; long a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<n;i+=2){ cout<<a[i]+a[i+1]<<" "; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s. At the end of each second Doraemon check if their heights are equal or not. Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter. <b>Constraints:-</b> 1 <b>&le;</b> h2 < h1<b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v1 <b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v2 <b>&le;</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False Sample input:- 4 2 2 4 Sample output:- Yes Explanation:- height of Gian goes as- 4 6 8 10. . height of Suneo goes as:- 2 6 10.. at the end of 1 second their height will become equal. Sample Input:- 5 4 1 6 Sample Output: No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; bool EqualOrNot(int h1, int h2, int v1,int v2){ if (v2>v1&&(h1-h2)%(v2-v1)==0){ return true; } return false; } int main(){ int n1,n2,v1,v2; cin>>n1>>n2>>v1>>v2; if(EqualOrNot(n1,n2,v1,v2)){ cout<<"Yes";} else{ cout<<"No"; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s. At the end of each second Doraemon check if their heights are equal or not. Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter. <b>Constraints:-</b> 1 <b>&le;</b> h2 < h1<b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v1 <b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v2 <b>&le;</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False Sample input:- 4 2 2 4 Sample output:- Yes Explanation:- height of Gian goes as- 4 6 8 10. . height of Suneo goes as:- 2 6 10.. at the end of 1 second their height will become equal. Sample Input:- 5 4 1 6 Sample Output: No, I have written this Solution Code: def EqualOrNot(h1,h2,v1,v2): if (v2>v1 and (h1-h2)%(v2-v1)==0): return True else: return False , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s. At the end of each second Doraemon check if their heights are equal or not. Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter. <b>Constraints:-</b> 1 <b>&le;</b> h2 < h1<b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v1 <b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v2 <b>&le;</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False Sample input:- 4 2 2 4 Sample output:- Yes Explanation:- height of Gian goes as- 4 6 8 10. . height of Suneo goes as:- 2 6 10.. at the end of 1 second their height will become equal. Sample Input:- 5 4 1 6 Sample Output: No, I have written this Solution Code: static boolean EqualOrNot(int h1, int h2, int v1,int v2){ if (v2>v1&&(h1-h2)%(v2-v1)==0){ return true; } return false; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix. Constraints:- 1 < = M, N < = 1000 0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:- 3 5 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 Sample Output:- 0 Sample Input:- 4 4 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 Sample Output:- 1, 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 m = sc.nextInt(); int n = sc.nextInt(); int[][] arr = new int[m][n]; for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ arr[i][j] = sc.nextInt(); } } int max_row_index = 0; int j = n - 1; for (int i = 0; i < m; i++) { while (j >= 0 && arr[i][j] == 1) { j = j - 1; max_row_index = i; } } System.out.println(max_row_index); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix. Constraints:- 1 < = M, N < = 1000 0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:- 3 5 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 Sample Output:- 0 Sample Input:- 4 4 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 Sample Output:- 1, I have written this Solution Code: r, c = list(map(int, input().split())) max_count = 0 max_r = 0 for i in range(r): count = input().count("1") if count > max_count: max_count = count max_r = i print(max_r), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix. Constraints:- 1 < = M, N < = 1000 0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:- 3 5 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 Sample Output:- 0 Sample Input:- 4 4 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 Sample Output:- 1, 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 1001 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int a[max1][max1]; signed main() { int n,m; cin>>n>>m; FOR(i,n){ FOR(j,m){cin>>a[i][j];}} int cnt=0; int ans=0; int res=0; FOR(i,n){ cnt=0; FOR(j,m){ if(a[i][j]==1){ cnt++; }} if(cnt>res){ res=cnt; ans=i; } } out(ans); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix. Constraints:- 1 < = M, N < = 1000 0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:- 3 5 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 Sample Output:- 0 Sample Input:- 4 4 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 Sample Output:- 1, I have written this Solution Code: // mat is the matrix/ 2d array // n,m are dimensions function max1Row(mat, n, m) { // write code here // do not console.log // return the answer as a number let j, max_row_index = 0; j = m - 1; for (let i = 0; i < n; i++) { // Move left until a 0 is found let flag = false; // to check whether a row has more 1's than previous while (j >= 0 && mat[i][j] == 1) { j = j - 1; // Update the index of leftmost 1 // seen so far flag = true;//present row has more 1's than previous } // if the present row has more 1's than previous if (flag) { max_row_index = i; // Update max_row_index } } if (max_row_index == 0 && mat[0][m - 1] == 0) return -1; return max_row_index; } , In this Programming Language: JavaScript, 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: Find factorial of a given number where n! = n * n-1 * n-2 .....* 1First line consists of a single integer denoting n Constraints:- 0 <= n <= 20Output is a single line containing factorial(n)Sample Input 5 Sample Output 120 Explanation:- 5!= 5 * 4 * 3 * 2 * 1 = 120 Sample Input 10 Sample Output 3628800, 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()); long fact=1; for(int i=1; i<=n;i++){ fact*=i; } System.out.print(fact); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find factorial of a given number where n! = n * n-1 * n-2 .....* 1First line consists of a single integer denoting n Constraints:- 0 <= n <= 20Output is a single line containing factorial(n)Sample Input 5 Sample Output 120 Explanation:- 5!= 5 * 4 * 3 * 2 * 1 = 120 Sample Input 10 Sample Output 3628800, I have written this Solution Code: def fact(n): if( n==0 or n==1): return 1 return n*fact(n-1); n=int(input()) print(fact(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find factorial of a given number where n! = n * n-1 * n-2 .....* 1First line consists of a single integer denoting n Constraints:- 0 <= n <= 20Output is a single line containing factorial(n)Sample Input 5 Sample Output 120 Explanation:- 5!= 5 * 4 * 3 * 2 * 1 = 120 Sample Input 10 Sample Output 3628800, I have written this Solution Code: #include <bits/stdc++.h> // #define ll long long using namespace std; int main(){ int t; t=1; while(t--){ int n; cin>>n; unsigned long long sum=1; for(int i=1;i<=n;i++){ sum*=i; } cout<<sum<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: In this season of love, everyone wants to surprise each other. You are also super excited and you wish to buy roses of 3 different colors. You always buy roses in order, white, yellow, red. So if you buy 7 roses, they will be "white, yellow, red, white, yellow, red, white". You need to find the number of yellow roses that you will buy?The only line of input contains a single integer, N, the number of roses that you will buy. Constraints 1 <= N <= 1000Output a single integer, the number of yellow roses.Sample Input 1 2 Sample Output 1 1 Sample Input 2 8 Sample Ouput 2 3 Explanation;- testcase1;- 2 flower will be white,yellow so number of yellow flower is 1, I have written this Solution Code: n=int(input()) x=n/3 if n%3==2: x+=1 print(int(x)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: In this season of love, everyone wants to surprise each other. You are also super excited and you wish to buy roses of 3 different colors. You always buy roses in order, white, yellow, red. So if you buy 7 roses, they will be "white, yellow, red, white, yellow, red, white". You need to find the number of yellow roses that you will buy?The only line of input contains a single integer, N, the number of roses that you will buy. Constraints 1 <= N <= 1000Output a single integer, the number of yellow roses.Sample Input 1 2 Sample Output 1 1 Sample Input 2 8 Sample Ouput 2 3 Explanation;- testcase1;- 2 flower will be white,yellow so number of yellow flower is 1, 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=sc.nextInt(); int ans = n/3; if(n%3==2){ans++;} System.out.print(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: In this season of love, everyone wants to surprise each other. You are also super excited and you wish to buy roses of 3 different colors. You always buy roses in order, white, yellow, red. So if you buy 7 roses, they will be "white, yellow, red, white, yellow, red, white". You need to find the number of yellow roses that you will buy?The only line of input contains a single integer, N, the number of roses that you will buy. Constraints 1 <= N <= 1000Output a single integer, the number of yellow roses.Sample Input 1 2 Sample Output 1 1 Sample Input 2 8 Sample Ouput 2 3 Explanation;- testcase1;- 2 flower will be white,yellow so number of yellow flower is 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int x=n/3; if(n%3==2){ x++;} cout<<x;}, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Let us create a table 'STORY' from existing table 'POSTS' which will contain the information about the stories users will create on LinkedIn. This table 'story' will contain the fields (USERNAME, DATETIME_CREATED, PHOTO) of the table 'posts' ( USE ONLY UPPERCASE LETTERS FOR CODE) <schema>[{'name': 'STORY', 'columns': [{'name': 'USERNAME', 'type': 'VARCHAR(24)'}, {'name': 'DATETIME_CREATED', 'type': 'TEXT'}, {'name': 'PHOTO', 'type': 'BLOB'}]}]</schema>nannannan, I have written this Solution Code: CREATE TABLE STORY AS SELECT USERNAME, DATETIME_CREATED, PHOTO FROM POST; , In this Programming Language: SQL, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find factorial of a given number N. <b>Note: </b> The Factorial of a number is the product of an integer and all the integers below it; e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b> Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N. <b>Constraints:</b> 1 <= N <= 15 Return the factorial of the given number.Sample Input:- 5 Sample Output:- 120 Sample Input:- 3 Sample Output:- 6, I have written this Solution Code: def factorial(n): if(n == 1): return 1 return n * factorial(n-1) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find factorial of a given number N. <b>Note: </b> The Factorial of a number is the product of an integer and all the integers below it; e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b> Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N. <b>Constraints:</b> 1 <= N <= 15 Return the factorial of the given number.Sample Input:- 5 Sample Output:- 120 Sample Input:- 3 Sample Output:- 6, I have written this Solution Code: static int Factorial(int N) { if(N==0){ return 1;} return N*Factorial(N-1); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find factorial of a given number N. <b>Note: </b> The Factorial of a number is the product of an integer and all the integers below it; e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b> Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N. <b>Constraints:</b> 1 <= N <= 15 Return the factorial of the given number.Sample Input:- 5 Sample Output:- 120 Sample Input:- 3 Sample Output:- 6, I have written this Solution Code: // n is the input number function factorial(n) { // write code here // do not console.log // return the answer as a number if (n == 1 ) return 1; return n * factorial(n-1) }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a stack of integers and N queries. Your task is to perform these operations:- <b>push:-</b>this operation will add an element to your current stack. <b>pop:-</b>remove the element that is on top <b>top:-</b>print the element which is currently on top of stack <b>Note:-</b>if the stack is already empty then the pop operation will do nothing and 0 will be printed as a top element of the stack if it is empty.<b>User task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the functions: <b>push()</b>:- that takes the stack and the integer to be added as a parameter. <b>pop()</b>:- that takes the stack as parameter. <b>top()</b> :- that takes the stack as parameter. <b>Constraints:</b> 1 &le; N &le; 10<sup>3</sup>You don't need to print anything else other than in <b>top</b> function in which you require to print the topmost element of your stack in a new line, if the stack is empty you just need to print 0.Input: 7 push 1 push 2 top pop top pop top Output: 2 1 0 , I have written this Solution Code: public static void push (Stack < Integer > st, int x) { st.push (x); } // Function to pop element from stack public static void pop (Stack < Integer > st) { if (st.isEmpty () == false) { int x = st.pop (); } } // Function to return top of stack public static void top(Stack < Integer > st) { int x = 0; if (st.isEmpty () == false) { x = st.peek (); } System.out.println (x); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Remove duplicates of an array and return an array of only unique elements.An array containing numbers.Space separated unique elements from the array.Sample Input:- 1 2 3 5 1 5 9 1 2 8 Sample Output:- 1 2 3 5 9 8 <b>Explanation:-</b> Extra 1, 2, and 5 were removed since they were occurring multiple times. Note: You only have to remove the extra occurrences i.e. each element in the final array should have a frequency equal to one., I have written this Solution Code: nan, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Remove duplicates of an array and return an array of only unique elements.An array containing numbers.Space separated unique elements from the array.Sample Input:- 1 2 3 5 1 5 9 1 2 8 Sample Output:- 1 2 3 5 9 8 <b>Explanation:-</b> Extra 1, 2, and 5 were removed since they were occurring multiple times. Note: You only have to remove the extra occurrences i.e. each element in the final array should have a frequency equal to one., I have written this Solution Code: inp = eval(input("")) new_set = [] for i in inp: if(str(i) not in new_set): new_set.append(str(i)) print(" ".join(new_set)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n piles of stones, where the i- th pile has a<sub>i</sub> stones. Two people play a game, where they take alternating turns removing stones. In a move, a player may remove a positive number of stones from the first non- empty pile (the pile with the minimal index, that has at least one stone). The first player who cannot make a move (because all piles are empty) loses the game. If both players play optimally, determine the winner of the game.The first line of the input contains a single integer n denoting the number of piles. The second line of each test case contains n integers a<sub>1</sub>, …, a<sub>n</sub> where a<sub>i</sub> is equal to the number of stones in the i- th pile. <b>Constraints</b> 1 &le; n &le; 10<sup>3</sup> 1 &le; a<sub>i</sub> &le; 10<sup>9</sup>If the player who makes the first move will win, output "First". Otherwise, output "Second".<b>Sample Input 1</b> 3 2 5 4 <b>Sample Output 1</b> First <b>Sample Input 1</b> 8 1 1 1 1 1 1 1 1 <b>Sample Output 1</b> Second, I have written this Solution Code: #include<iostream> #include<cstdio> #include<algorithm> #include<queue> #include<cstring> #include<ctime> #define db double #define N 100100 using namespace std; int T,n,num[N]; int main() { int i,j,t; // cin>>T; T=1; while(T--) { scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&num[i]); for(i=1;i<n&&num[i]==1;i++); if(i&1) puts("First"); else puts("Second"); } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a rope of length L which you have to cut at 11 positions to divide it into 12 ropes. Here, each of the 12 resulting ropes must have a positive integer length. Find the number of ways to do this division. Note: Two ways to do the division are considered different if and only if there is a position cut in only one of those ways.Input contains a single integer L. Constraints: 12 <= L <= 200Print the number of ways to do the division.Sample Input 1 12 Sample Output 1 1 Sample Input 2 13 Sample Output 2 12, I have written this Solution Code: def ncr(n, r): ans = 1 for i in range(1,r+1): ans *= (n - r + i) ans //= i return ans def NoOfDistributions(N, R): return ncr(N - 1, R - 1) N = int(input()) print(NoOfDistributions(N, 12)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a rope of length L which you have to cut at 11 positions to divide it into 12 ropes. Here, each of the 12 resulting ropes must have a positive integer length. Find the number of ways to do this division. Note: Two ways to do the division are considered different if and only if there is a position cut in only one of those ways.Input contains a single integer L. Constraints: 12 <= L <= 200Print the number of ways to do the division.Sample Input 1 12 Sample Output 1 1 Sample Input 2 13 Sample Output 2 12, I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main(){ fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; int ans=1; for(int i=1;i<12;i++){ ans=ans*(n-i); ans=ans/i; } cout<<ans; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a rope of length L which you have to cut at 11 positions to divide it into 12 ropes. Here, each of the 12 resulting ropes must have a positive integer length. Find the number of ways to do this division. Note: Two ways to do the division are considered different if and only if there is a position cut in only one of those ways.Input contains a single integer L. Constraints: 12 <= L <= 200Print the number of ways to do the division.Sample Input 1 12 Sample Output 1 1 Sample Input 2 13 Sample Output 2 12, I have written this Solution Code: import java.io.*; // for handling input/output import java.util.*; // contains Collections framework // don't change the name of this class // you can add inner classes if needed class Main { public static void main (String[] args) { // Your code here Scanner sc = new Scanner(System.in); int rope = sc.nextInt(); System.out.println(possibleValues(rope)); } static long possibleValues(int rope) { long ans = 1; for(int i = 1; i < 12; i++) { ans *= (rope-i); ans /= i; } return ans; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. Let string A be it's longest palindromic suffix and string B be the longest palindromic prefix of string S. String C = A + B Print the string C.The first line and the only line of the input contains a string S. Constraints 1<=|S|<=100000Print the required answer.Sample Input aabb Sample Output bbaa Explanation longest prefix -> aa longest suffix ->bb Sample Input aaaa Sample Output aaaaaaaa, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader input = new BufferedReader( new InputStreamReader(System.in)); String str = input.readLine(); System.out.println( palindrome( str, str.length() ) ); } public static String palindrome( String str, int n ) { String result = ""; boolean suffix = false; boolean prefix = false; for( int k=n; k>0; k-- ) { if( !prefix && isPalindrome( str, 0, k-1 ) ) { result = result + str.substring( 0,k ); prefix = true; } if( !suffix && isPalindrome( str, n-k, n-1 ) ) { result = str.substring( n-k, n ) + result; suffix = true; } if( suffix && prefix ) break; } return result; } public static boolean isPalindrome( String str, int i, int j ) { while( i<j ) { if( str.charAt(i) != str.charAt(j) ) return false; i++; j--; } return true; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. Let string A be it's longest palindromic suffix and string B be the longest palindromic prefix of string S. String C = A + B Print the string C.The first line and the only line of the input contains a string S. Constraints 1<=|S|<=100000Print the required answer.Sample Input aabb Sample Output bbaa Explanation longest prefix -> aa longest suffix ->bb Sample Input aaaa Sample Output aaaaaaaa, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define mp make_pair #define pu push_back #define ll long long #define fi first #define se second #define sz 4000000 string text,pat; int lcs[sz]; int mcs[sz]; int sum=0; int Z[sz]; void Zarr(string s) { int n=s.size(); if(n>0)Z[0]=0; int L=0,R=0; for(int i=1;i<n;i++) { if(R<i) { L=i;R=i; while(R<n && s[R-L]==s[R]) R++; Z[i]=R-L; R--; }else { if(Z[i-L]<R-i+1) { Z[i]=Z[i-L]; }else { L=i; while(R<n && s[R-L]==s[R]) R++; Z[i]=R-L; R--; } } } } void complcs(string pat) { int m=pat.size(); int i=1; int len=0; while(i<m) { if(pat[i]==pat[len]) { len++; lcs[i]=len; i++; }else { if(len==0) { lcs[i]=0; i++; }else { len=lcs[len-1]; } } } } void kmp(string text,string pat) { int n=text.size(); int m=pat.size(); int i=0,j=0; while(i<n) { if(text[i]==pat[j]) { j++; mcs[n-1-i]=j; i++; }else { if(j==0) { mcs[n-1-i]=j; i++; }else { j=lcs[j-1]; } } } } int dp[sz]; int kmp2(string s) { int n=s.size(); int i=1; int len=0; for(int i=0;i<=n;i++) { lcs[i]=0; } while(i<n) { if(s[i]==s[len]) { len++; lcs[i]=len; i++; }else { if(len==0) { lcs[i]=0; i++; }else { cout<<i<<" "<<len<<" f "<<endl; dp[len]++; len=lcs[len-1]; } } } dp[n]=1; for(int i=n;i>1;i--) { dp[i]+=dp[i+1]; dp[lcs[i-1]]+=dp[i]; } //dp[n]=1; /*int sum=0; for(int i=n;i>0;i--) { int pp=dp[i]; if(i>1) dp[i]+=dp[i+1]+sum; else dp[i]+=dp[i+1]; sum+=pp; }*/ } int print(string s) { string p=""; int n=s.size(); for(int i=n-1;i>=0;i--) { p+=s[i]; } for(int i=0;i<=n;i++) { lcs[i]=0; mcs[i]=0; } complcs(s); //cout<<"gg"; kmp(p,s); //cout<<"check"; int sum=1; for(int i=0;i<n;i++) { // cout<<i<<" "<<mcs[i]<<endl; if(mcs[i]==i) { sum=max(sum,i*2); }else if(mcs[i]>i) { sum=max(sum,i*2+1); } } return sum; } int main() { string s; cin>>s; string p=""; int n=s.size(); for(int i=n-1;i>=0;i--) { p+=s[i]; } int nn=print(s); int mm=print(p); // cout<<nn<<" "<<mm<<endl; string ss=p.substr(0,mm); ss=ss+s.substr(0,nn); int nm=ss.size(); for(int i=0;i<=nm;i++) { lcs[i]=0; } cout<<ss<<endl; Zarr(ss); int an=ss.size(); for(int i=0;i<an;i++) { //cout<<Z[i]<<" "; dp[Z[i]]++; } dp[an]++; for(int i=an-1;i>=0;i--) { dp[i]+=dp[i+1]; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: As they were totally exhausted with the daily chores, Ketani and Nilswap decided to play a game.They get alternate turns in the game and Ketani starts the game. The game consists of a tree containing N nodes numbered 1 to N. On each turn the person chooses a node of the tree that is not yet numbered. If it's Ketani's turn, he writes an odd number to this node whereas if it's Nilswap's turn, he writes an even number to this node. After the entire tree has been numbered, all the odd numbered nodes that are adjacent to an even numbered node turn even (instantaneous, no propagation). If the tree contains any odd number in the end, Ketani wins otherwise Nilswap wins. You need to output the name of the winner. Note: Initially none of the nodes contains a number. Both players play optimally.The first line of the input contains an integer N, the number of nodes in the tree. The next N-1 lines contain two integers u, v indicating there is an edge between u and v. Constraints 2 <= N <= 100000 1 <= u, v <= 100000 u != v The given edges form a tree.Output a single string, the winner of the game.Sample Input 1 3 1 2 2 3 Sample Output 1 Ketani Sample Input 2 2 1 2 Sample Output 2 Nilswap Explanation 1: -> Ketani writes an odd number to node 2. -> Nilswap writes an even number to node 3. -> Ketani writes an odd number to node 1. -> After this, node 2 converts to an even number. But node 1 is still white. So Ketani wins., 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 vector<int> adj[N]; bool ans; bool dfs(int u, int par = 0) { int cnt = 0; for (auto v: adj[u]) if (v != par) cnt += dfs(v, u); if (cnt >= 2) { ans = true; return false; } return 1 - cnt; } signed main(){ #ifdef SWAPNIL07 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif fast int n; cin >> n; for (int i = 1; i < n; i++) { int v, u; cin >> v >> u; adj[v].pb(u); adj[u].pb(v);; } ans |= dfs(1); if(ans){ cout<<"Ketani"; } else{ cout<<"Nilswap"; } 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 array and Q queries. Your 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 the frontUser 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 the integer to be added and the maximum size of array as parameter. <b>dequeue()</b>:- that takes the queue as parameter. <b>displayfront()</b> :- that takes the queue as parameter. Constraints: 1 <= Q(Number of queries) <= 10<sup>3</sup> <b> Custom Input:</b> First line of input should contains two integer number of queries Q and the size of the array N. Next Q lines contains any of the given three operations:- enqueue x dequeue displayfrontDuring a dequeue operation if queue is empty you need to print "Queue is empty", during enqueue operation if the maximum size of array is reached you need to print "Queue is full" and during displayfront operation you need to print the element which is at the front and if the queue is empty you need to print "Queue is empty". Note:-Each msg or element is to be printed on a new line Sample Input:- 8 2 displayfront enqueue 2 displayfront enqueue 4 displayfront dequeue displayfront enqueue 5 Sample Output:- Queue is empty 2 2 4 Queue is full Explanation:-here size of given array is 2 so when last enqueue operation perfomed the array was already full so we display the msg "Queue is full". Sample input: 5 5 enqueue 4 enqueue 5 displayfront dequeue displayfront Sample output:- 4 5, I have written this Solution Code: public static void enqueue(int x,int k) { if (rear >= k) { System.out.println("Queue is full"); } else { a[rear] = x; rear++; } } public static void dequeue() { if (rear <= front) { System.out.println("Queue is empty"); } else { front++; } } public static void displayfront() { if (rear<=front) { System.out.println("Queue is empty"); } else { int x = a[front]; System.out.println(x); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of positive integers. The task is to find inversion count of array. Inversion Count : For an array, inversion count indicates how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j. Asked in Adobe, Amazon, Microsoft.The first line of each test case is N, the size of the array. The second line of each test case contains N elements. Constraints:- 1 ≤ N ≤ 10^5 1 ≤ a[i] ≤ 10^5Print the inversion count of array.Sample Input: 5 2 4 1 3 5 Sample Output: 3 Explanation: Testcase 1: The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 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 input[]=br.readLine().split("\\s"); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=Integer.parseInt(input[i]); } System.out.print(implementMergeSort(a,0,n-1)); } public static long implementMergeSort(int arr[], int start, int end) { long count=0; if(start<end) { int mid=start+(end-start)/2; count +=implementMergeSort(arr,start,mid); count +=implementMergeSort(arr,mid+1,end); count +=merge(arr,start,end,mid); } return count; } public static long merge(int []a,int start,int end,int mid) { int i=start; int j=mid+1; int k=0; int len=end-start+1; int c[]=new int[len]; long inv_count=0; while(i<=mid && j<=end) { if(a[i]<=a[j]) { c[k++]=a[i]; i++; } else { c[k++]=a[j]; j++; inv_count +=(mid-i)+1; } } while(i<=mid) { c[k++]=a[i++]; } while(j<=end) { c[k++]=a[j++]; } for(int l=0;l<len;l++) a[start+l]=c[l]; return inv_count; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of positive integers. The task is to find inversion count of array. Inversion Count : For an array, inversion count indicates how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j. Asked in Adobe, Amazon, Microsoft.The first line of each test case is N, the size of the array. The second line of each test case contains N elements. Constraints:- 1 ≤ N ≤ 10^5 1 ≤ a[i] ≤ 10^5Print the inversion count of array.Sample Input: 5 2 4 1 3 5 Sample Output: 3 Explanation: Testcase 1: The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3)., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define int long long long long _mergeSort(int arr[], int temp[], int left, int right); long long merge(int arr[], int temp[], int left, int mid, int right); /* This function sorts the input array and returns the number of inversions in the array */ long long mergeSort(int arr[], int array_size) { int temp[array_size]; return _mergeSort(arr, temp, 0, array_size - 1); } /* An auxiliary recursive function that sorts the input array and returns the number of inversions in the array. */ long long _mergeSort(int arr[], int temp[], int left, int right) { int mid, inv_count = 0; if (right > left) { /* Divide the array into two parts and call _mergeSortAndCountInv() for each of the parts */ mid = (right + left) / 2; /* Inversion count will be sum of inversions in left-part, right-part and number of inversions in merging */ inv_count += _mergeSort(arr, temp, left, mid); inv_count += _mergeSort(arr, temp, mid + 1, right); /*Merge the two parts*/ inv_count += merge(arr, temp, left, mid + 1, right); } return inv_count; } /* This funt merges two sorted arrays and returns inversion count in the arrays.*/ long long merge(int arr[], int temp[], int left, int mid, int right) { int i, j, k; long long inv_count = 0; i = left; /* i is index for left subarray*/ j = mid; /* j is index for right subarray*/ k = left; /* k is index for resultant merged subarray*/ while ((i <= mid - 1) && (j <= right)) { if (arr[i] <= arr[j]) { temp[k++] = arr[i++]; } else { temp[k++] = arr[j++]; /* this is tricky -- see above explanation/diagram for merge()*/ inv_count = inv_count + (mid - i); } } /* Copy the remaining elements of left subarray (if there are any) to temp*/ while (i <= mid - 1) temp[k++] = arr[i++]; /* Copy the remaining elements of right subarray (if there are any) to temp*/ while (j <= right) temp[k++] = arr[j++]; /*Copy back the merged elements to original array*/ for (i = left; i <= right; i++) arr[i] = temp[i]; return inv_count; } signed main() { int n; cin>>n; int a[n]; unordered_map<int,int> m; for(int i=0;i<n;i++){ cin>>a[i]; if(m.find(a[i])==m.end()){ m[a[i]]=i; } } cout<<mergeSort(a,n); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, You have to find the maximum product of two integers.The first line of input contains a single integer N. The next line of input contains N space separated integers. Constraints:- 2 <= N <= 100000 -10000 <= Arr[i] <= 10000Print the maximum product of two elements.Sample Input:- 5 -1 -2 3 4 -5 Sample Output:- 12 Explanation:- 4*3 = 12 Sample Input:- 4 -1 -1 1 1 Sample Output:- 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long signed main(){ int n,l; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } sort(a,a+n); int res = max(a[0]*a[1],a[n-1]*a[n-2]); cout<<res; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b> Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: def checkSpecial_M_Visor(N,M) : # Final result of summation of divisors i=2; count=0 while i<=N : if(N%i==0): count=count+1 i=i+2 if(count == M): return "Yes" return "No" , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b> Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: static String checkSpecial_M_Visor(int N, int M) { int temp=0; for(int i = 2; i <=N; i+=2) { if(N%i==0) temp++; } if(temp==M) return "Yes"; else return "No"; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b> Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: string checkSpecial_M_Visor(int N,int M){ int count=0; for(int i=2;i<=N;i+=2){ if(N%i==0){ count++; } } if(count==M){return "Yes";} return "No"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b> Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: const char* checkSpecial_M_Visor(int N,int M){ int count=0; for(int i=2;i<=N;i+=2){ if(N%i==0){ count++; } } char* ans; if(count==M){return "Yes";} return "No"; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: How would you add your own method to the Array object so the following code would work? const arr = [1, 2, 3] console. log(arr.average()) // 2input will be an array, run like this const anyArray = [5,6...] anyArray.average should return average of the arraysAverage of the given arrayconst myArray = [1,2,3,4,5] console.log(myArray.average()) // 3, I have written this Solution Code: Array.prototype.average = function() { // calculate sum var sum = this.reduce(function(prev, cur) { return prev + cur; }); // return sum divided by number of elements return sum / this.length; } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary array of size N. Count number of 1's and 0's in the array.First line contains n. Next line contains n space separated integers. <b>Constraints</b> 1 <= N <= 10<sup>5</sup> 0 <= arr[i] <= 1Print two integers, count of 1s and count of 0s.Input: 5 0 1 1 0 1 Output: 3 2, I have written this Solution Code: n=int(input()) arr= input().split() one=zero=0 for i in range(0, n): if arr[i]=='1': one+=1 else: zero+=1 print(one, zero), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary array of size N. Count number of 1's and 0's in the array.First line contains n. Next line contains n space separated integers. <b>Constraints</b> 1 <= N <= 10<sup>5</sup> 0 <= arr[i] <= 1Print two integers, count of 1s and count of 0s.Input: 5 0 1 1 0 1 Output: 3 2, I have written this Solution Code: import java.io.*; import java.util.*; public class Main { 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 ones=0; for(int i=0;i<n;i++){ ones += a[i]; } int zeroes=n-ones; out.print(ones + " " + zeroes); 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: You are given two arrays A and B of size N each. You can perform any of the following operation any number of times: <ul> <li>Choose any index i (1 <= i <= N) and increase A<sub>i</sub> by 1 and decrease B<sub>i</sub> by 1</li> <li>Choose any index i (1 <= i <= N) and decrease A<sub>i</sub> by 1 and increase B<sub>i</sub> by 1</li> </ul> Find out whether you can make the corresponding elements of both arrays equal.The first line of the input contains a single integer N. The second line of the input contains N space seperated integers A<sub>i</sub> The third line of the input contains N space seperated integers B<sub>i</sub> Constraints: 1 <= N <= 10<sup>5</sup> 1 <= A<sub>i</sub>, B<sub>i</sub> <= 10<sup>9</sup>Print "YES" if you can make the corresponding elements of both arrays equal in any number of moves, else print "NO"Sample Input: 5 3 7 6 4 2 5 7 4 4 2 Sample Output: YES Explaination: First, we apply the second type of move on index i = 3 and then we apply the first type of move on index i = 1., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws Exception{ InputStreamReader reader = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(reader); int size = Integer.parseInt(br.readLine()); int[] arr1 = new int[size]; int[] arr2 = new int[size]; String[] str1 = br.readLine().trim().split(" "); for(int i=0; i<arr1.length; i++){ arr1[i] = Integer.parseInt(str1[i]); } String[] str2 = br.readLine().trim().split(" "); for(int i=0; i<arr2.length; i++){ arr2[i] = Integer.parseInt(str2[i]); } boolean bl = true; for(int i=0; i<size; i++){ if(arr1[i] != arr2[i]){ if((Math.abs(arr1[i]-arr2[i])&1)==1){ bl = false; break; } } } if(bl==true){ 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: You are given two arrays A and B of size N each. You can perform any of the following operation any number of times: <ul> <li>Choose any index i (1 <= i <= N) and increase A<sub>i</sub> by 1 and decrease B<sub>i</sub> by 1</li> <li>Choose any index i (1 <= i <= N) and decrease A<sub>i</sub> by 1 and increase B<sub>i</sub> by 1</li> </ul> Find out whether you can make the corresponding elements of both arrays equal.The first line of the input contains a single integer N. The second line of the input contains N space seperated integers A<sub>i</sub> The third line of the input contains N space seperated integers B<sub>i</sub> Constraints: 1 <= N <= 10<sup>5</sup> 1 <= A<sub>i</sub>, B<sub>i</sub> <= 10<sup>9</sup>Print "YES" if you can make the corresponding elements of both arrays equal in any number of moves, else print "NO"Sample Input: 5 3 7 6 4 2 5 7 4 4 2 Sample Output: YES Explaination: First, we apply the second type of move on index i = 3 and then we apply the first type of move on index i = 1., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int n; cin >> n; vector<int> a(n), b(n); for(auto &i : a) cin >> i; for(auto &i : b) cin >> i; for(int i = 0; i < n; i++){ if(abs(a[i] - b[i]) % 2){ cout << "NO"; return 0; } } cout << "YES"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); int n=Integer.parseInt(br.readLine().trim()); if(n%3==1) System.out.println("Dead"); else System.out.println("Alive"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: n = int(input().strip()) if n%3 == 1: print("Dead") else: print("Alive"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., 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 int n; cin>>n; if(n%3==1) cout<<"Dead"; else cout<<"Alive"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges. <b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments. Constraints:- 1 <= N <= 10000 1 <= A <= N 1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:- 5 3 4 Sample Output:- 2 Sample Input:- 5 5 5 Sample Output:- 5, I have written this Solution Code: static int LikesBoth(int N, int A, int B){ return (A+B-N); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges. <b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments. Constraints:- 1 <= N <= 10000 1 <= A <= N 1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:- 5 3 4 Sample Output:- 2 Sample Input:- 5 5 5 Sample Output:- 5, I have written this Solution Code: def LikesBoth(N,A,B): return (A+B-N) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges. <b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments. Constraints:- 1 <= N <= 10000 1 <= A <= N 1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:- 5 3 4 Sample Output:- 2 Sample Input:- 5 5 5 Sample Output:- 5, I have written this Solution Code: int LikesBoth(int N,int A, int B){ return (A+B-N); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges. <b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments. Constraints:- 1 <= N <= 10000 1 <= A <= N 1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:- 5 3 4 Sample Output:- 2 Sample Input:- 5 5 5 Sample Output:- 5, I have written this Solution Code: int LikesBoth(int N,int A, int B){ return (A+B-N); }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary array (a binary array is an array consisting only of zeroes and ones) of size N. You can do following operation on the array any number of times. In an operation you can select any subarray of size 3 of the array such that all three elements of that subarray are not same and replace that subarray with a single element which is the element with frequency 2 in that subarray. For example if we are given array [0, 1, 0, 1, 1, 0] if we select subarray (0-2) then we will replace [0, 1, 0] with [0] so the array finally becomes [0, 1, 1, 0]. You have to find if it is possible to apply this operation some number of times to finally reduce the array to size 1.First line of input contains a single integer N, size of the array. Second line contains N integers denoting the binary array. Constraints: 3 <= N <= 100000 0 <= Arr[i] <= 1Print 1 if it is possible to finally reduce the array to size 1 else print 0.Sample Input 1 5 0 1 0 1 0 Sample Output 1 1 Explanation: First we select subarray (0-2) array gets changed to 0 1 0 Second we select subarray (0-2) array gets changed to 0 As the size became 1 therefore it is possible. Sample Input 2 5 1 1 1 1 0 Sample Output 2 0 Explanation - First we select subarray (2-4) array gets changed to 1 1 1 1 Now we cannot do the operation anymore., I have written this Solution Code: a=int(input()) b=input().split(" ") p=0 if b[0]=="1" and b[1]=="1" and b[2]=="1" and b[3]=="1" and b[4]=="1" and b[5]=="1": print(1) p=1 exit(0) bb="" for i in b: bb=bb+i b=bb while len(b)!=1 and p==0: if "101" in b: b=b.replace("101","1") elif "110" in b: b=b.replace("110","1") elif "011" in b: b=b.replace("011","1") elif "010" in b: b=b.replace("010","0") elif "001" in b: b=b.replace("001","0") elif "100" in b: b=b.replace("100","0") else: break if len(b)==1 and p==0: print("1") elif p==0 and len(b)!=1: print("0"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary array (a binary array is an array consisting only of zeroes and ones) of size N. You can do following operation on the array any number of times. In an operation you can select any subarray of size 3 of the array such that all three elements of that subarray are not same and replace that subarray with a single element which is the element with frequency 2 in that subarray. For example if we are given array [0, 1, 0, 1, 1, 0] if we select subarray (0-2) then we will replace [0, 1, 0] with [0] so the array finally becomes [0, 1, 1, 0]. You have to find if it is possible to apply this operation some number of times to finally reduce the array to size 1.First line of input contains a single integer N, size of the array. Second line contains N integers denoting the binary array. Constraints: 3 <= N <= 100000 0 <= Arr[i] <= 1Print 1 if it is possible to finally reduce the array to size 1 else print 0.Sample Input 1 5 0 1 0 1 0 Sample Output 1 1 Explanation: First we select subarray (0-2) array gets changed to 0 1 0 Second we select subarray (0-2) array gets changed to 0 As the size became 1 therefore it is possible. Sample Input 2 5 1 1 1 1 0 Sample Output 2 0 Explanation - First we select subarray (2-4) array gets changed to 1 1 1 1 Now we cannot do the operation anymore., I have written this Solution Code: #pragma GCC optimize ("O3") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; int v=0; for(int i=0;i<n;++i){ int d; cin>>d; if(d==0) ++v; else --v; } if(abs(v)==1){ cout<<1; } else{ cout<<0; } #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary array (a binary array is an array consisting only of zeroes and ones) of size N. You can do following operation on the array any number of times. In an operation you can select any subarray of size 3 of the array such that all three elements of that subarray are not same and replace that subarray with a single element which is the element with frequency 2 in that subarray. For example if we are given array [0, 1, 0, 1, 1, 0] if we select subarray (0-2) then we will replace [0, 1, 0] with [0] so the array finally becomes [0, 1, 1, 0]. You have to find if it is possible to apply this operation some number of times to finally reduce the array to size 1.First line of input contains a single integer N, size of the array. Second line contains N integers denoting the binary array. Constraints: 3 <= N <= 100000 0 <= Arr[i] <= 1Print 1 if it is possible to finally reduce the array to size 1 else print 0.Sample Input 1 5 0 1 0 1 0 Sample Output 1 1 Explanation: First we select subarray (0-2) array gets changed to 0 1 0 Second we select subarray (0-2) array gets changed to 0 As the size became 1 therefore it is possible. Sample Input 2 5 1 1 1 1 0 Sample Output 2 0 Explanation - First we select subarray (2-4) array gets changed to 1 1 1 1 Now we cannot do the operation anymore., 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()); int zero = 0,one = 0; String[] s = br.readLine().trim().split(" "); for(int i=0;i<n;i++){ int x = Integer.parseInt(s[i]); if(x%2==0) zero++; else one++; } if(zero-one==1 || zero-one==-1 ) 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: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); int n=Integer.parseInt(br.readLine().trim()); if(n%3==1) System.out.println("Dead"); else System.out.println("Alive"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: n = int(input().strip()) if n%3 == 1: print("Dead") else: print("Alive"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., 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 int n; cin>>n; if(n%3==1) cout<<"Dead"; else cout<<"Alive"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary array A[] of size N. The task is to arrange an array in increasing order. (O(N) time complexity solution)Every test case contains two lines, first line contains an integer N (size of array) and second line contains space separated elements of array. 1 <= N <= 20 0 <= A[i] <= 1Print a single line containing space separated elements of sorted arrays.Input: 5 1 0 1 1 0 Output: 0 0 1 1 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void cal(int arr[], int n){ int countZ = 0; for(int i = 0; i < n; i++) { if(arr[i] == 0) { countZ++; } } for(int i = 1; i <= countZ; i++) { System.out.print("0 "); } for(int i = 1; i <= n - countZ; i++) { System.out.print("1 "); } } public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String nD = br.readLine(); String nDArr[] = nD.split(" "); int n = Integer.parseInt(nDArr[0]); int arr[]= new int[n]; String input = br.readLine(); String sar[] = input.split(" "); for(int i = 0; i < n; i++){ arr[i] = Integer.parseInt(sar[i]); } cal(arr, n); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary array A[] of size N. The task is to arrange an array in increasing order. (O(N) time complexity solution)Every test case contains two lines, first line contains an integer N (size of array) and second line contains space separated elements of array. 1 <= N <= 20 0 <= A[i] <= 1Print a single line containing space separated elements of sorted arrays.Input: 5 1 0 1 1 0 Output: 0 0 1 1 1, I have written this Solution Code: n = int(input()) l = list(map(int, input().split())) l = sorted(l) for i in l: print(i, end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary array A[] of size N. The task is to arrange an array in increasing order. (O(N) time complexity solution)Every test case contains two lines, first line contains an integer N (size of array) and second line contains space separated elements of array. 1 <= N <= 20 0 <= A[i] <= 1Print a single line containing space separated elements of sorted arrays.Input: 5 1 0 1 1 0 Output: 0 0 1 1 1, 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; cin >> n; int a[2] = {0}; for(int i = 1; i <= n; i++){ int p; cin >> p; a[p]++; } for(int i = 0; i <= 1; i++) for(int j = 0; j < a[i]; j++) cout << i << " "; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given N strings and Q queries, for each query you will be given a string, your task is to print all the anagrams of the string from the given N strings. If no anagrams exist then print -1. Note:- Given string may contain duplicated strings you should print it as many times as it occurs.First line of input contains a single integer N, second line of input contains N space separated strings. Third line of input contains a single integer Q, next Q line contains a single string each. Constraints:- 1 < = N < = 1000 1 < = |String| < = 10 1 < = Q < = 100000 Note:-String will only contain lower case english lettersFor each query in a new line print the anagrams in lexicographical order separated by spaces.Sample Input:- 6 cat tea pet tac act eat 4 cat tca eee tea Sample Output:- act cat tac act cat tac -1 eat tea, 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)); HashMap<String, List<String> > hs=new HashMap<>(); int n=Integer.parseInt(br.readLine()); String st[]=br.readLine().split(" "); for(int i=0;i<n;i++){ String temp=st[i]; char ch[]=temp.toCharArray(); Arrays.sort(ch); String temp1=new String(ch); if(hs.containsKey(temp1)){ hs.get(temp1).add(temp); } else{ List<String> ValueList = new ArrayList<>(); ValueList.add(temp); hs.put(temp1,ValueList); } } int q=Integer.parseInt(br.readLine()); for(int i=0;i<q;i++){ String check=br.readLine(); char temp[]=check.toCharArray(); Arrays.sort(temp); check=new String(temp); if(hs.containsKey(check)){ List<String> li=hs.get(check); Collections.sort(li); int x=li.size(); for(int j=0;j<x;j++){ System.out.print(li.get(j)+" "); } System.out.println(); } else{ System.out.println(-1); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given N strings and Q queries, for each query you will be given a string, your task is to print all the anagrams of the string from the given N strings. If no anagrams exist then print -1. Note:- Given string may contain duplicated strings you should print it as many times as it occurs.First line of input contains a single integer N, second line of input contains N space separated strings. Third line of input contains a single integer Q, next Q line contains a single string each. Constraints:- 1 < = N < = 1000 1 < = |String| < = 10 1 < = Q < = 100000 Note:-String will only contain lower case english lettersFor each query in a new line print the anagrams in lexicographical order separated by spaces.Sample Input:- 6 cat tea pet tac act eat 4 cat tca eee tea Sample Output:- act cat tac act cat tac -1 eat tea, 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 200001 #define MOD 1000000007 #define read(type) readInt<type>() #define int long long #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } unordered_map<string,vector<string>> m; signed main(){ int n; cin>>n; string s,p; while(n--){ cin>>s; p=s; sort(s.begin(),s.end()); m[s].EB(p); } for(auto it =m.begin();it!=m.end();it++){ sort(it->second.begin(),it->second.end()); } int q; cin>>q; while(q--){ cin>>s; sort(s.begin(),s.end()); if(m.find(s)==m.end()){out(-1);continue;} else{ vector<string> v = m[s]; for(int i=0;i<v.size();i++){ out1(v[i]); } END; } } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, find the sum of all the digits of the number Note: Use a recursive method to solve this problem.<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>Sum()</b> that takes the integer N as a parameter. Constraints: 1 ≤ T ≤ 100 0 ≤ N ≤ 1000000000Return sum of digits.Sample Input 2 25 28 Sample Output 7 10, I have written this Solution Code: // n is the input number function recSum(n) { // write code here // do not console.log // return the answer as a number if (n < 10) return n; return n % 10 + recSum(Math.floor(n / 10)) } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, find the sum of all the digits of the number Note: Use a recursive method to solve this problem.<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>Sum()</b> that takes the integer N as a parameter. Constraints: 1 ≤ T ≤ 100 0 ≤ N ≤ 1000000000Return sum of digits.Sample Input 2 25 28 Sample Output 7 10, I have written this Solution Code: static long Sum(long n) { if(n==0){return 0;} return n%10+Sum(n/10); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b> Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: def checkSpecial_M_Visor(N,M) : # Final result of summation of divisors i=2; count=0 while i<=N : if(N%i==0): count=count+1 i=i+2 if(count == M): return "Yes" return "No" , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b> Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: static String checkSpecial_M_Visor(int N, int M) { int temp=0; for(int i = 2; i <=N; i+=2) { if(N%i==0) temp++; } if(temp==M) return "Yes"; else return "No"; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b> Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: string checkSpecial_M_Visor(int N,int M){ int count=0; for(int i=2;i<=N;i+=2){ if(N%i==0){ count++; } } if(count==M){return "Yes";} return "No"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b> Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: const char* checkSpecial_M_Visor(int N,int M){ int count=0; for(int i=2;i<=N;i+=2){ if(N%i==0){ count++; } } char* ans; if(count==M){return "Yes";} return "No"; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: In a new plot by Hydra to kill the avengers, Doctor Zola comes up with a new form of poison composed of chromosomes A, C, T and G. The poison is a string of length n (where n is divisible by 4) with each of the four letters occurring exactly n/4 times. For example, GACT and AAGTGCCT are both fatal poisons.Help Doctor Zola’s plan by choosing one (maybe empty) substring of minimal length in given poision and replace it with the new string (containing A,T,G,C) to make that poison fatal quickly.The first line of input contains a single integer N. The next line of input contains a string S of size N. Constraints:- 1 <= N <= 100000 Note:- N is divisible by 4 and S will only contain {A, G, C, T}Print the length of the minimum length substring that can be replaced to detect the poison as fatal.Sample Input:- 8 GAAATAAA Sample Output:- 5 Explanation:- ATAAA can be replaced to TTCCG to get a fatal poison Sample Input:- 4 AAAA Sample Output:- 3, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { FastReader sc = new FastReader(); int n= sc.nextInt(); String str = sc.next(); int x= n/4; int l = 0; int r = n; while (l!=r){ int a = (l+r)/2; if(checkL(str,a)) r=a; else l=a+1; } System.out.print(l); } static boolean checkL(String str,int L){ int n = str.length(); int m = n/4; int g=0,a=0,t=0,c=0; for (int i = L; i < n; i++) { char x = str.charAt(i); if(x=='G') g+=1; else if (x=='A') a+=1; else if (x=='T') t+=1; else c+=1; } if (g<=m && a<=m && t<=m && c<=m) return true; for (int i = 0; i < n-L; i++) { char x = str.charAt(i); char y = str.charAt(i+L); if(x=='G') g+=1; else if (x=='A') a+=1; else if (x=='T') t+=1; else if(x=='C') c+=1; if(y=='G') g-=1; else if (y=='A') a-=1; else if (y=='T') t-=1; else if(y=='C') c-=1; if (g<=m && a<=m && t<=m && c<=m) return true; } return false; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: In a new plot by Hydra to kill the avengers, Doctor Zola comes up with a new form of poison composed of chromosomes A, C, T and G. The poison is a string of length n (where n is divisible by 4) with each of the four letters occurring exactly n/4 times. For example, GACT and AAGTGCCT are both fatal poisons.Help Doctor Zola’s plan by choosing one (maybe empty) substring of minimal length in given poision and replace it with the new string (containing A,T,G,C) to make that poison fatal quickly.The first line of input contains a single integer N. The next line of input contains a string S of size N. Constraints:- 1 <= N <= 100000 Note:- N is divisible by 4 and S will only contain {A, G, C, T}Print the length of the minimum length substring that can be replaced to detect the poison as fatal.Sample Input:- 8 GAAATAAA Sample Output:- 5 Explanation:- ATAAA can be replaced to TTCCG to get a fatal poison Sample Input:- 4 AAAA Sample Output:- 3, I have written this Solution Code: n = int(input("")) st = input("") fxmp = {'A':0,'C':0,'G':0,'T':0} mp = {'A':0,'C':0,'G':0,'T':0} for i in st: fxmp[i] +=1 l = 0 r = len(st) while l<r: for k,m in fxmp.items(): mp[k] = m md = (l+r+1)//2 for i in range(md): mp[st[i]]-=1 if (mp['A'] <= n/4) and (mp['C'] <= n/4) and (mp['G'] <= n/4) and (mp['T'] <= n/4): r = md - 1 k = 0 for i in range(md,n): mp[st[k]] += 1 mp[st[i]] -= 1 k+=1 if mp['A'] <= n/4 and mp['C'] <= n/4 and mp['G'] <= n/4 and mp['T'] <= n/4: r = md - 1 break if r != md-1: l = md print(r+1), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: In a new plot by Hydra to kill the avengers, Doctor Zola comes up with a new form of poison composed of chromosomes A, C, T and G. The poison is a string of length n (where n is divisible by 4) with each of the four letters occurring exactly n/4 times. For example, GACT and AAGTGCCT are both fatal poisons.Help Doctor Zola’s plan by choosing one (maybe empty) substring of minimal length in given poision and replace it with the new string (containing A,T,G,C) to make that poison fatal quickly.The first line of input contains a single integer N. The next line of input contains a string S of size N. Constraints:- 1 <= N <= 100000 Note:- N is divisible by 4 and S will only contain {A, G, C, T}Print the length of the minimum length substring that can be replaced to detect the poison as fatal.Sample Input:- 8 GAAATAAA Sample Output:- 5 Explanation:- ATAAA can be replaced to TTCCG to get a fatal poison Sample Input:- 4 AAAA Sample Output:- 3, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MAX 500005 typedef long longll; int ara[MAX],art[MAX]; int arc[MAX],argg[MAX]; int main() { //freopen("ou.txt", "r", stdin); int n; cin>>n; string s; cin>>s; int count_a=0,count_t=0,count_c=0,count_g=0,xox; for(int i=0;i<n;i++) { char c = s[i]; if(c=='A') { count_a++; ara[i]=count_a; } else if(c=='T') count_t++; else if(c=='C') count_c++; else count_g++; ara[i]=count_a; art[i]=count_t; arc[i]=count_c; argg[i]=count_g; } if(count_a==count_t&&count_a==count_c&&count_a==count_g&&count_t==count_c&&count_t==count_g&&count_c==count_g) { cout<< 0; return 0; } xox = n/4; count_a=xox-count_a; if(count_a>= 0) count_a = 0; else count_a = -count_a; count_t=xox-count_t; if(count_t>=0) count_t=0; else count_t = -count_t; count_c = xox-count_c; if(count_c>=0) count_c=0; else count_c = -count_c; count_g = xox-count_g; if(count_g>=0) count_g=0; else count_g = -count_g; int ans=n; for(int i=0;i<n;i++) { int index1,index2,index3,index4; if(i==0) { index1 = lower_bound(ara+i,ara+n,count_a)-ara; if(index1==n) continue; index2 = lower_bound(art+i,art+n,count_t)-art; if(index2==n) continue; index3 = lower_bound(arc+i,arc+n,count_c)-arc; if(index3==n) continue; index4 = lower_bound(argg+i,argg+n,count_g)-argg; if(index4==n) continue; } else{ index1 = lower_bound(ara+i,ara+n,ara[i-1]+count_a)-ara; if(index1==n) continue; index2 = lower_bound(art+i,art+n,art[i-1]+count_t)-art; if(index2==n) continue; index3 = lower_bound(arc+i,arc+n,arc[i-1]+count_c)-arc; if(index3==n) continue; index4 = lower_bound(argg+i,argg+n,argg[i-1]+count_g)-argg; if(index4==n) continue; } ans = min(ans,max(index1-i+1,max(index2-i+1,max(index3-i+1,index4-i+1)))); } printf("%d\n",ans); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable