Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static boolean isArrangementPossible(long arr[],int n,long sum){ if(n==1){ if(arr[0]==sum) return true; else return false; } return(isArrangementPossible(arr,n-1,sum-arr[n-1]) || isArrangementPossible(arr,n-1,sum+arr[n-1])); } public static void main (String[] args) throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String str1[]=br.readLine().trim().split(" "); int n=Integer.parseInt(str1[0]); long sum=Long.parseLong(str1[1]); String str[]=br.readLine().trim().split(" "); long arr[]=new long[n]; for(int i=0;i<n;i++){ arr[i]=Long.parseLong(str[i]); } if(isArrangementPossible(arr,n,sum)){ 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 a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: def checkIfGivenTargetIsPossible(nums,currSum,i,targetSum): if i == len(nums): if currSum == targetSum: return 1 return 0 if(checkIfGivenTargetIsPossible(nums,currSum + nums[i],i+1,targetSum)): return 1 return checkIfGivenTargetIsPossible(nums,currSum - nums[i], i+1,targetSum) n,k = map(int,input().split()) nums = list(map(int,input().split())) if(checkIfGivenTargetIsPossible(nums,0,0,k)): print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #define int long long int k; using namespace std; int solve(int n, int a[], int i, int curr ){ if(i==n){ if(curr==k){return 1;} return 0; } if(solve(n,a,i+1,curr+a[i])==1){return 1;} return solve(n,a,i+1,curr-a[i]); } signed main() { int n; cin>>n>>k; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } if(solve(n,a,1,a[0])){ cout<<"YES";} else{ cout<<"NO";} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: static void simpleSum(int a, int b, int c){ System.out.println(a+b+c); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: void simpleSum(int a, int b, int c){ cout<<a+b+c; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: x = input() a, b, c = x.split() a = int(a) b = int(b) c = int(c) print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter. </b>Constraints:</b> 1 <= n <= 100 <b>Note:</b> <i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:- 5 Sample Output:- 2 4 Sample Input:- 6 Sample Output:- 2 4 6, I have written this Solution Code: def For_Loop(n): string = "" for i in range(1, n+1): if i % 2 == 0: string += "%s " % i return string , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter. </b>Constraints:</b> 1 <= n <= 100 <b>Note:</b> <i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:- 5 Sample Output:- 2 4 Sample Input:- 6 Sample Output:- 2 4 6, I have written this Solution Code: public static void For_Loop(int n){ for(int i=2;i<=n;i+=2){ System.out.print(i+" "); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s=br.readLine().toString(); int n=Integer.parseInt(s); int ch=0; if(n>0){ ch=1; } else if(n<0) ch=-1; switch(ch){ case 1: System.out.println("Positive");break; case 0: System.out.println("Zero");break; case -1: System.out.println("Negative");break; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: n = input() if '-' in list(n): print('Negative') elif int(n) == 0 : print('Zero') else: print('Positive'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: #include <stdio.h> int main() { int num; scanf("%d", &num); switch (num > 0) { // Num is positive case 1: printf("Positive"); break; // Num is either negative or zero case 0: switch (num < 0) { case 1: printf("Negative"); break; case 0: printf("Zero"); break; } break; } 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 integers of size N, your task is to find the maximum parity index of this array. <b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 < = N < = 10<sup>5</sup> 1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:- 5 1 2 3 4 5 Sample Output 1:- 4 Sample Input 2:- 5 5 4 3 2 1 Sample Output 2:- -1 <b>Explanation 1:</b> The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0] , 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') { if (cnt != 0) { break; } else { continue; } } 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 N = sc.nextInt(); int[] arr = new int[N]; for(int i=0;i<N;i++){ arr[i] = sc.nextInt(); } int max=0; if(arr[0]<arr[N-1]) System.out.print(N-1); else{ for(int i=0;i<N-1;i++){ int j = N-1; while(j>i){ if(arr[i]<arr[j]){ if(max<j-i){ max = j-i; } break; } j--; } if(i==j) break; if(j==N-1) break; } if(max==0) System.out.print("-1"); else System.out.print(max); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array. <b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 < = N < = 10<sup>5</sup> 1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:- 5 1 2 3 4 5 Sample Output 1:- 4 Sample Input 2:- 5 5 4 3 2 1 Sample Output 2:- -1 <b>Explanation 1:</b> The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0] , I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long /* For a given array arr[], returns the maximum j – i such that arr[j] > arr[i] */ int maxIndexDiff(int arr[], int n) { int maxDiff; int i, j; int *LMin = new int[(sizeof(int) * n)]; int *RMax = new int[(sizeof(int) * n)]; /* Construct LMin[] such that LMin[i] stores the minimum value from (arr[0], arr[1], ... arr[i]) */ LMin[0] = arr[0]; for (i = 1; i < n; ++i) LMin[i] = min(arr[i], LMin[i - 1]); /* Construct RMax[] such that RMax[j] stores the maximum value from (arr[j], arr[j+1], ..arr[n-1]) */ RMax[n - 1] = arr[n - 1]; for (j = n - 2; j >= 0; --j) RMax[j] = max(arr[j], RMax[j + 1]); /* Traverse both arrays from left to right to find optimum j - i. This process is similar to merge() of MergeSort */ i = 0, j = 0, maxDiff = -1; while (j < n && i < n) { if (LMin[i] < RMax[j]) { maxDiff = max(maxDiff, j - i); j = j + 1; } else i = i + 1; } return maxDiff; } // Driver Code signed main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } int maxDiff = maxIndexDiff(a, n); cout << maxDiff; 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 integers of size N, your task is to find the maximum parity index of this array. <b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 < = N < = 10<sup>5</sup> 1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:- 5 1 2 3 4 5 Sample Output 1:- 4 Sample Input 2:- 5 5 4 3 2 1 Sample Output 2:- -1 <b>Explanation 1:</b> The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0] , I have written this Solution Code: n=int(input()) arr=list(map(int,input().split())) rightMax = [0] * n rightMax[n - 1] = arr[n - 1] for i in range(n - 2, -1, -1): rightMax[i] = max(rightMax[i + 1], arr[i]) maxDist = -2**31 i = 0 j = 0 while (i < n and j < n): if (rightMax[j] >= arr[i]): maxDist = max(maxDist, j - i) j += 1 else: i += 1 if maxDist==0: maxDist=-1 print(maxDist), 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 containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array. Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow. Each testcases contains two lines of input. The first line denotes the size of the array N. The second lines contains the elements of the array A separated by spaces. Constraints: 1 <= T <= 100 1 <= N <= 100000 0 <= Ai <= 2 Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input : 2 5 0 2 1 2 0 3 0 1 0 Output: 0 0 1 2 2 0 0 1 Explanation: Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output. Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out= new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t>0){ t-=1; int n=Integer.parseInt(br.readLine()); String s[]=br.readLine().split(" "); int arr[]=new int[n]; int zero_counter=0,one_counter=0,two_counter=0; for(int i=0;i<n;i++){ arr[i]=Integer.parseInt(s[i]); if(arr[i]==0) zero_counter+=1; else if(arr[i]==1) one_counter+=1; else two_counter+=1; } for(int i=0;i<zero_counter;i++){ out.print(0+" "); } for(int i=0;i<one_counter;i++){ out.print(1+" "); } for(int i=0;i<two_counter;i++){ out.print(2+" "); } out.flush(); out.println(" "); } out.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 size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array. Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow. Each testcases contains two lines of input. The first line denotes the size of the array N. The second lines contains the elements of the array A separated by spaces. Constraints: 1 <= T <= 100 1 <= N <= 100000 0 <= Ai <= 2 Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input : 2 5 0 2 1 2 0 3 0 1 0 Output: 0 0 1 2 2 0 0 1 Explanation: Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output. Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: t=int(input()) while t>0: t-=1 n=input() a=map(int,input().split()) z=o=tc=0 for i in a: if i==0:z+=1 elif i==1:o+=1 else:tc+=1 while z>0: z-=1 print(0,end=' ') while o>0: o-=1 print(1,end=' ') while tc>0: tc-=1 print(2,end=' ') print(), 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 containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array. Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow. Each testcases contains two lines of input. The first line denotes the size of the array N. The second lines contains the elements of the array A separated by spaces. Constraints: 1 <= T <= 100 1 <= N <= 100000 0 <= Ai <= 2 Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input : 2 5 0 2 1 2 0 3 0 1 0 Output: 0 0 1 2 2 0 0 1 Explanation: Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output. Testcase 2: For the given array input, output will be 0 0 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 t; cin >> t; while(t--){ int n; cin >> n; int a[3] = {0}; for(int i = 1; i <= n; i++){ int p; cin >> p; a[p]++; } a[1] += a[0]; a[2] += a[1]; for(int i = 1; i <= n; i++){ if(i <= a[0]) cout << "0 "; else if(i <= a[1]) cout << "1 "; else cout << "2 "; } cout << 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 A of size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array. Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow. Each testcases contains two lines of input. The first line denotes the size of the array N. The second lines contains the elements of the array A separated by spaces. Constraints: 1 <= T <= 100 1 <= N <= 100000 0 <= Ai <= 2 Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input : 2 5 0 2 1 2 0 3 0 1 0 Output: 0 0 1 2 2 0 0 1 Explanation: Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output. Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: function zeroOneTwoSort(arr, n) { // write code here // do not console.log the answer // return sorted array return arr.sort((a, b) => a - b) }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array. Constraints:- 1<=T<=500 1<=N,K<=10^5 -10^5<=A[i]<=10^5 Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input: 3 6 15 10 5 2 7 1 9 6 -5 -5 8 -14 2 4 12 3 6 -1 2 3 Sample Output: 4 5 0, I have written this Solution Code: def lenOfLongSubarr(arr, N, K): mydict = dict() sum = 0 maxLen = 0 for i in range(N): sum += arr[i] if (sum == K): maxLen = i + 1 elif (sum - K) in mydict: maxLen = max(maxLen, i - mydict[sum - K]) if sum not in mydict: mydict[sum] = i return maxLen if __name__ == '__main__': T = int(input()) #N,K=list(map(int,input().split())) for i in range(T): N,k= [int(N)for N in input("").split()] arr=list(map(int,input().split())) N = len(arr) print(lenOfLongSubarr(arr, N, k)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array. Constraints:- 1<=T<=500 1<=N,K<=10^5 -10^5<=A[i]<=10^5 Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input: 3 6 15 10 5 2 7 1 9 6 -5 -5 8 -14 2 4 12 3 6 -1 2 3 Sample Output: 4 5 0, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ unordered_map<long long,int> um; int n,k; cin>>n>>k; long arr[n]; int maxLen=0; for(int i=0;i<n;i++){cin>>arr[i];} long long sum=0; for(int i=0;i<n;i++){ sum += arr[i]; // when subarray starts from index '0' if (sum == k) maxLen = i + 1; // make an entry for 'sum' if it is // not present in 'um' if (um.find(sum) == um.end()) um[sum] = i; // check if 'sum-k' is present in 'um' // or not if (um.find(sum - k) != um.end()) { // update maxLength if (maxLen < (i - um[sum - k])) maxLen = i - um[sum - k]; } } cout<<maxLen<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array. Constraints:- 1<=T<=500 1<=N,K<=10^5 -10^5<=A[i]<=10^5 Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input: 3 6 15 10 5 2 7 1 9 6 -5 -5 8 -14 2 4 12 3 6 -1 2 3 Sample Output: 4 5 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ if(t%10==0){ System.gc(); } int arrsize=sc.nextInt(); int k=sc.nextInt(); int[] arr=new int[arrsize]; for(int i=0;i<arrsize;i++){ arr[i]=sc.nextInt(); } int subsize=0; int sum=0; HashMap<Integer, Integer> hash=new HashMap<>(); for(int i=0;i<arrsize;i++){ sum+=arr[i]; if(sum==k){ subsize=i+1; } if(!hash.containsKey(sum)){ hash.put(sum,i); } if(hash.containsKey(sum-k)){ if(subsize<(i-hash.get(sum-k))){ subsize=i-hash.get(sum-k); } } } System.out.println(subsize); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to become rich so he came up with an idea, So, he buys some gadgets from the future at a price of C and sells them at a price of S to his friends. Now Nobita wants to know how much he gains by selling all gadget. As we all know Nobita is weak in maths help him to find the profit he getsYou don't have to worry about the input, you just have to complete the function <b>Profit()</b> <b>Constraints:-</b> 1 <= C <= S <= 1000Print the profit Nobita gets from selling one gadget.Sample Input:- 3 5 Sample Output:- 2 Sample Input:- 9 16 Sample Output:- 7, I have written this Solution Code: def profit(C, S): print(S - C), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to become rich so he came up with an idea, So, he buys some gadgets from the future at a price of C and sells them at a price of S to his friends. Now Nobita wants to know how much he gains by selling all gadget. As we all know Nobita is weak in maths help him to find the profit he getsYou don't have to worry about the input, you just have to complete the function <b>Profit()</b> <b>Constraints:-</b> 1 <= C <= S <= 1000Print the profit Nobita gets from selling one gadget.Sample Input:- 3 5 Sample Output:- 2 Sample Input:- 9 16 Sample Output:- 7, I have written this Solution Code: static void Profit(int C, int S){ System.out.println(S-C); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements. What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array. Constraints:- 1 <= N <= 100000 1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:- 3 4 1 7 Sample Output:- 1 4 7 Explanation:- Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd Sample Input:- 2 2 4 Sample Output:- 2 4 Sample Input:- 2 5 3 Sample Output:- 5 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().trim()); String array[] = br.readLine().trim().split(" "); StringBuilder sb = new StringBuilder(""); int[] arr = new int[n]; int oddCount = 0, evenCount = 0; for(int i = 0; i < n; i++) { arr[i] = Integer.parseInt(array[i]); if(arr[i] % 2 == 0) ++evenCount; else ++oddCount; } if(evenCount > 0 && oddCount > 0) Arrays.sort(arr); for(int i = 0; i < n; i++) sb.append(arr[i] + " "); System.out.println(sb.substring(0, sb.length() - 1)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements. What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array. Constraints:- 1 <= N <= 100000 1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:- 3 4 1 7 Sample Output:- 1 4 7 Explanation:- Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd Sample Input:- 2 2 4 Sample Output:- 2 4 Sample Input:- 2 5 3 Sample Output:- 5 3, I have written this Solution Code: n=int(input()) p=[int(x) for x in input().split()[:n]] o=0;e=0 for i in range(n): if (p[i] % 2 == 1): o += 1; else: e += 1; if (o > 0 and e > 0): p.sort(); for i in range(n): print(p[i], end = " ");, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements. What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array. Constraints:- 1 <= N <= 100000 1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:- 3 4 1 7 Sample Output:- 1 4 7 Explanation:- Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd Sample Input:- 2 2 4 Sample Output:- 2 4 Sample Input:- 2 5 3 Sample Output:- 5 3, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; long long a[n]; bool win=false,win1=false; for(int i=0;i<n;i++){ cin>>a[i]; if(a[i]&1){win=true;} if(a[i]%2==0){win1=true;} } if(win==true && win1==true){sort(a,a+n);} for(int i=0;i<n;i++){ cout<<a[i]<<" "; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are N integers A[1], A[2],. , A[N]. You need to find whether their product is divisible by 4.The first line of input contains a single integer N. The next line contains N singly spaced integers, A[1], A[2],. , A[N]. Constraints 1 <= N <= 10 1 <= A[i] <= 1000000000Output "YES" if the product is divisible by 4, else output "NO". (without quotes)Sample Input 5 3 5 2 5 1 Sample Output NO Explanation: Product = 150 and 150 is not divisible by 4. Sample Input 4 1 3 8 2 Sample Output YES Explanation: Product = 48 and 48 is divisible by 4., I have written this Solution Code: n = int(input()) arr = [] x = 4 prod = 1 a = input().split() for i in range(0,n): prod = prod*int(a[i]) if prod % 4 == 0: print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are N integers A[1], A[2],. , A[N]. You need to find whether their product is divisible by 4.The first line of input contains a single integer N. The next line contains N singly spaced integers, A[1], A[2],. , A[N]. Constraints 1 <= N <= 10 1 <= A[i] <= 1000000000Output "YES" if the product is divisible by 4, else output "NO". (without quotes)Sample Input 5 3 5 2 5 1 Sample Output NO Explanation: Product = 150 and 150 is not divisible by 4. Sample Input 4 1 3 8 2 Sample Output YES Explanation: Product = 48 and 48 is divisible by 4., 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 two=0,four=0; for(int i=0;i<n;i++){ if(a[i]%2==0){ two++; } if(a[i]%4==0){ four++; } } if(four>=1 || two>=2){ System.out.print("YES"); } else{ System.out.print("NO"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are N integers A[1], A[2],. , A[N]. You need to find whether their product is divisible by 4.The first line of input contains a single integer N. The next line contains N singly spaced integers, A[1], A[2],. , A[N]. Constraints 1 <= N <= 10 1 <= A[i] <= 1000000000Output "YES" if the product is divisible by 4, else output "NO". (without quotes)Sample Input 5 3 5 2 5 1 Sample Output NO Explanation: Product = 150 and 150 is not divisible by 4. Sample Input 4 1 3 8 2 Sample Output YES Explanation: Product = 48 and 48 is divisible by 4., 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 ld long double #define mp make_pair #define F first #define S second typedef pair<int, int> pii; typedef vector<int> vi; #define pi 3.141592653589793238 #define MOD 1000000007 #define INF 1000000000000000007LL const int N = 200005; // it's swapnil07 ;) #ifdef SWAPNIL07 #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } int begtime = clock(); #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; #else #define endl '\n' #define trace(...) #define end_routine() #endif signed main() { fast #ifdef SWAPNIL07 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int n; cin>>n; int ct = 0; For(i, 0, n){ int a; cin>>a; while(a%2==0){ ct++; a/=2; } } if(ct>=2){ cout<<"YES"; } else{ cout<<"NO"; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of integers, find the number of subarrays with an odd sum.First line contains an integers N. Next line contains N space separated integers denoting elements of array. Constraints 1 <= N <= 10^5 1 <= Ai <= 10^5Print the number of subarrays with an odd sum.Sample Input 1: 3 1 3 5 Output 4 Explanation: All subarrays are [1], [1, 3], [1, 3, 5], [3], [3, 5], [5] All sub- arrays sum are [1, 4, 9, 3, 8, 5]. Odd sums are [1, 9, 3, 5] so the answer is 4. Sample Input 2: 3 2 4 6 Output 0 Explanation: All subarrays are [2], [2, 4], [2, 4, 6], [4], [4, 6], [6] All sub- arrays sum are [2, 6, 12, 4, 10, 6]. All sub- arrays have even sum and the answer is 0., I have written this Solution Code: def countOddSum(a, n): # 'odd' stores number of # odd numbers upto ith index # 'c_odd' stores number of # odd sum subarrays starting # at ith index # 'Result' stores the number # of odd sum subarrays c_odd = 0; result = 0; odd = False; # First find number of odd # sum subarrays starting at # 0th index for i in range(n): if (a[i] % 2 == 1): if(odd == True): odd = False; else: odd = True; if (odd): c_odd += 1; # Find number of odd sum # subarrays starting at ith # index add to result for i in range(n): result += c_odd; if (a[i] % 2 == 1): c_odd = (n - i - c_odd); return result; n=int(input()) arr=list(map(int,input().strip().split()))[:n] print(countOddSum(arr,n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of integers, find the number of subarrays with an odd sum.First line contains an integers N. Next line contains N space separated integers denoting elements of array. Constraints 1 <= N <= 10^5 1 <= Ai <= 10^5Print the number of subarrays with an odd sum.Sample Input 1: 3 1 3 5 Output 4 Explanation: All subarrays are [1], [1, 3], [1, 3, 5], [3], [3, 5], [5] All sub- arrays sum are [1, 4, 9, 3, 8, 5]. Odd sums are [1, 9, 3, 5] so the answer is 4. Sample Input 2: 3 2 4 6 Output 0 Explanation: All subarrays are [2], [2, 4], [2, 4, 6], [4], [4, 6], [6] All sub- arrays sum are [2, 6, 12, 4, 10, 6]. All sub- arrays have even sum and the answer is 0., 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 a[] = new long[n]; String line = br.readLine(); // to read multiple integers line String[] strs = line.trim().split("\\s+"); for (int i = 0; i < n; i++) { a[i] = Long.parseLong(strs[i]); } long[] prefix=new long[n]; prefix[0]=a[0]; for(int i=1;i<n;i++){ prefix[i]=prefix[i-1]+a[i]; } long e=1; long o=0; for(int i=0;i<n;i++){ if(prefix[i]%2==0)e++; else o++; } e*=o; System.out.print(e); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b> <b>Constraints:-</b> 1 &le; N &le; 10<sup>9</sup>Print the integer N.Sample Input:- 3 Sample Output: 3 Sample Input: 56 Sample Output: 56, I have written this Solution Code: static void printInteger(int N){ System.out.println(N); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b> <b>Constraints:-</b> 1 &le; N &le; 10<sup>9</sup>Print the integer N.Sample Input:- 3 Sample Output: 3 Sample Input: 56 Sample Output: 56, I have written this Solution Code: void printInteger(int x){ printf("%d", x); }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b> <b>Constraints:-</b> 1 &le; N &le; 10<sup>9</sup>Print the integer N.Sample Input:- 3 Sample Output: 3 Sample Input: 56 Sample Output: 56, I have written this Solution Code: void printIntger(int n) { cout<<n; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b> <b>Constraints:-</b> 1 &le; N &le; 10<sup>9</sup>Print the integer N.Sample Input:- 3 Sample Output: 3 Sample Input: 56 Sample Output: 56, I have written this Solution Code: n=int(input()) print (n), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is an integer q is given as input.You are asked q queries each of which can be of type 1 or type 2. Type 1 : Report the area of square having side length S. Type 2 : Report the area of rectangle of having side lengths L and R.The first line of the input contains single integer Q, number of queries. Next Q line contains the queries. Each query first contains type of query If query is of type one then you are given a single integer S as input. If query is of type two then you are given two integers L and R as input. Constraints 1 <= Q <= 25 1 <= T <= 2 1 <= S, L, R <= 10<sup>3</sup>Output Q line each containing answer to the asked query.Sample Input 2 2 5 4 1 5 Sample Output 20 25, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); int queries = Integer.parseInt(inputReader.readLine()); for(int q = 0; q < queries; q++) { String[] inputNums = inputReader.readLine().trim().split(" "); if(Integer.parseInt(inputNums[0]) == 1) { System.out.println(Integer.parseInt(inputNums[1]) * Integer.parseInt(inputNums[1])); } else if (Integer.parseInt(inputNums[0]) == 2) { System.out.println(Integer.parseInt(inputNums[1]) * Integer.parseInt(inputNums[2])); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is an integer q is given as input.You are asked q queries each of which can be of type 1 or type 2. Type 1 : Report the area of square having side length S. Type 2 : Report the area of rectangle of having side lengths L and R.The first line of the input contains single integer Q, number of queries. Next Q line contains the queries. Each query first contains type of query If query is of type one then you are given a single integer S as input. If query is of type two then you are given two integers L and R as input. Constraints 1 <= Q <= 25 1 <= T <= 2 1 <= S, L, R <= 10<sup>3</sup>Output Q line each containing answer to the asked query.Sample Input 2 2 5 4 1 5 Sample Output 20 25, I have written this Solution Code: q = int(input()) while q: arr = list(map(int, input().split())) if arr[0] == 1: print(arr[1]*arr[1]) else: print(arr[1]*arr[2]) q-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is an integer q is given as input.You are asked q queries each of which can be of type 1 or type 2. Type 1 : Report the area of square having side length S. Type 2 : Report the area of rectangle of having side lengths L and R.The first line of the input contains single integer Q, number of queries. Next Q line contains the queries. Each query first contains type of query If query is of type one then you are given a single integer S as input. If query is of type two then you are given two integers L and R as input. Constraints 1 <= Q <= 25 1 <= T <= 2 1 <= S, L, R <= 10<sup>3</sup>Output Q line each containing answer to the asked query.Sample Input 2 2 5 4 1 5 Sample Output 20 25, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int x; for(int i=0;i<n;i++){ cin>>x; if(x==1){ cin>>x; cout<<x*x<<endl; } else{ int a,b; cin>>a>>b; cout<<a*b<<endl; } } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a cubic dice with 6 faces. All the individual faces have a numbers printed on them. The numbers are in the range of 1 to 6, like any ordinary dice. Given a number on one face of the dice , you need to print the number on the opposite face . NOTE : In a normal dice sum of numbers on opposite faces is 7 .The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each test case contains a single line of the input containing a positive integer N. Constraints: 1 <= T <= 100 1 <= N <= 6For each testcase, print the number that is on the opposite side of the given face.Input: 2 6 2 Output: 1 5 Explanation: Testcase 1: For dice facing number 6 opposite face will have the number 1., I have written this Solution Code: def get_opposite_face(n): return 7-n t = int(input()) for n in range(t): print(get_opposite_face(int(input()))), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a cubic dice with 6 faces. All the individual faces have a numbers printed on them. The numbers are in the range of 1 to 6, like any ordinary dice. Given a number on one face of the dice , you need to print the number on the opposite face . NOTE : In a normal dice sum of numbers on opposite faces is 7 .The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each test case contains a single line of the input containing a positive integer N. Constraints: 1 <= T <= 100 1 <= N <= 6For each testcase, print the number that is on the opposite side of the given face.Input: 2 6 2 Output: 1 5 Explanation: Testcase 1: For dice facing number 6 opposite face will have the number 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 t; cin >> t; while(t--){ int n; cin >> n; cout << 7-n << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a cubic dice with 6 faces. All the individual faces have a numbers printed on them. The numbers are in the range of 1 to 6, like any ordinary dice. Given a number on one face of the dice , you need to print the number on the opposite face . NOTE : In a normal dice sum of numbers on opposite faces is 7 .The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each test case contains a single line of the input containing a positive integer N. Constraints: 1 <= T <= 100 1 <= N <= 6For each testcase, print the number that is on the opposite side of the given face.Input: 2 6 2 Output: 1 5 Explanation: Testcase 1: For dice facing number 6 opposite face will have the number 1., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t-->0){ int n=Integer.parseInt(br.readLine()); System.out.println(6-n+1); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''. Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 &le; length of S &le; 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1: Apple Sample Output 1: Gravity Sample Input 2: Mango Sample Output 2: Space Sample Input 3: AppLE Sample Output 3: Space, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main (String[] args) { FastReader sc= new FastReader(); String str= sc.nextLine(); String a="Apple"; if(a.equals(str)){ System.out.println("Gravity"); } else{ System.out.println("Space"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''. Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 &le; length of S &le; 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1: Apple Sample Output 1: Gravity Sample Input 2: Mango Sample Output 2: Space Sample Input 3: AppLE Sample Output 3: Space, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; //Work int main() { #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen ("INPUT.txt" , "r" , stdin); //freopen ("OUTPUT.txt" , "w" , stdout); } #endif //-----------------------------------------------------------------------------------------------------------// string S; cin>>S; if(S=="Apple") { cout<<"Gravity"<<endl; } else { cout<<"Space"<<endl; } //-----------------------------------------------------------------------------------------------------------// return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''. Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 &le; length of S &le; 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1: Apple Sample Output 1: Gravity Sample Input 2: Mango Sample Output 2: Space Sample Input 3: AppLE Sample Output 3: Space, I have written this Solution Code: n=input() if n=='Apple':print('Gravity') else:print('Space'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is Armstrong number or not. Now what is Armstrong number let us see below: <b>A number is said to be Armstrong if it is equal to sum of cube of its digits. </b>User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isArmstrong()</b> which contains N as a parameter. Constraints: 1 <= N <= 10^4You need to return "true" if the given number is an Armstrong number otherwise "false"Sample Input 1: 1 Sample Output 1: true Sample Input 2: 147 Sample Output 2: false Sample Input 3: 371 Sample Output 3: true , I have written this Solution Code: static boolean isArmstrong(int N) { int num = N; int sum = 0; while(N > 0) { int digit = N%10; sum += digit*digit*digit; N = N/10; } if(num == sum) return true; else return false; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is Armstrong number or not. Now what is Armstrong number let us see below: <b>A number is said to be Armstrong if it is equal to sum of cube of its digits. </b>User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isArmstrong()</b> which contains N as a parameter. Constraints: 1 <= N <= 10^4You need to return "true" if the given number is an Armstrong number otherwise "false"Sample Input 1: 1 Sample Output 1: true Sample Input 2: 147 Sample Output 2: false Sample Input 3: 371 Sample Output 3: true , I have written this Solution Code: function isArmstrong(n) { // write code here // do no console.log the answer // return the output using return keyword let sum = 0 let k = n; while(k !== 0){ sum += Math.pow( k%10,3) k = Math.floor(k/10) } return sum === n }, 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 highest power of 2 that is smaller than or equal to n.The first line of the input contains the value n. Constraints 1 <= n <= 1e18Print the highest power of 2 that is smaller than or equal to n.Sample Input 10 Sample Output 8 Explanation 8 is the highest power of 2 which is less than equal to 10, 16 is also there but it's higher than 10., I have written this Solution Code: a=int(input()) x=1 while(x<a): x=x*2 print(x//2), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number n, find the highest power of 2 that is smaller than or equal to n.The first line of the input contains the value n. Constraints 1 <= n <= 1e18Print the highest power of 2 that is smaller than or equal to n.Sample Input 10 Sample Output 8 Explanation 8 is the highest power of 2 which is less than equal to 10, 16 is also there but it's higher than 10., I have written this Solution Code: /* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Main { public static long log2(long N){ long result = (long)(Math.log(N) / Math.log(2)); return result; } public static void main (String[] args) throws java.lang.Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); long n; String s = br.readLine(); String ip[] = s.split(" "); n = Long.parseLong(ip[0]); double p = (double)log2(n); double x = 2; double res = Math.pow(x,p); System.out.println((long)res); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number n, find the highest power of 2 that is smaller than or equal to n.The first line of the input contains the value n. Constraints 1 <= n <= 1e18Print the highest power of 2 that is smaller than or equal to n.Sample Input 10 Sample Output 8 Explanation 8 is the highest power of 2 which is less than equal to 10, 16 is also there but it's higher than 10., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 2351 #endif #define int long long int32_t main() { int n; cin >> n; int p = (int)log2(n); cout << (int)pow(2, p) << "\n"; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble or not.<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>candies()</b> that takes integers X, and Y as arguments. Constraints:- 1 <= X <= 1000 1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:- X = 3, Y = 5 Sample Output:- 1 Explanation:- Total people in Sara's home = 5, no. of people allowed = 3 Sample Input:- X = 4, Y = 2 Sample Output:- 0, I have written this Solution Code: static int candies(int X, int Y){ if(X<=Y){return 1;} return 0; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble or not.<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>candies()</b> that takes integers X, and Y as arguments. Constraints:- 1 <= X <= 1000 1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:- X = 3, Y = 5 Sample Output:- 1 Explanation:- Total people in Sara's home = 5, no. of people allowed = 3 Sample Input:- X = 4, Y = 2 Sample Output:- 0, I have written this Solution Code: int candies(int X, int Y){ if(X<=Y){return 1;} return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble or not.<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>candies()</b> that takes integers X, and Y as arguments. Constraints:- 1 <= X <= 1000 1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:- X = 3, Y = 5 Sample Output:- 1 Explanation:- Total people in Sara's home = 5, no. of people allowed = 3 Sample Input:- X = 4, Y = 2 Sample Output:- 0, I have written this Solution Code: def candies(X,Y): if(X<=Y): return 1 return 0 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble or not.<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>candies()</b> that takes integers X, and Y as arguments. Constraints:- 1 <= X <= 1000 1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:- X = 3, Y = 5 Sample Output:- 1 Explanation:- Total people in Sara's home = 5, no. of people allowed = 3 Sample Input:- X = 4, Y = 2 Sample Output:- 0, I have written this Solution Code: int candies(int X, int Y){ if(X<=Y){return 1;} return 0; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:- a+b a-b a*b a/bThe input contains two integers a and b separated by spaces. <b>Constraints:</b> 1 &le; b &le; a &le; 1000 <b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input: 15 3 Sample Output: 18 12 45 5 <b>Explanation:-</b> First operation is a+b so 15+3 = 18 The second Operation is a-b so 15-3 = 12 Third Operation is a*b so 15*3 = 45 Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args){ FastReader read = new FastReader(); int a = read.nextInt(); int b = read.nextInt(); System.out.println(a+b); System.out.println(a-b); System.out.println(a*b); System.out.println(a/b); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ InputStreamReader inr = new InputStreamReader(System.in); br = new BufferedReader(inr); } String next(){ while(st==null || !st.hasMoreElements()) try{ st = new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble(){ return Double.parseDouble(next()); } long nextLong(){ return Long.parseLong(next()); } String nextLine(){ String str = ""; try{ str = br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:- a+b a-b a*b a/bThe input contains two integers a and b separated by spaces. <b>Constraints:</b> 1 &le; b &le; a &le; 1000 <b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input: 15 3 Sample Output: 18 12 45 5 <b>Explanation:-</b> First operation is a+b so 15+3 = 18 The second Operation is a-b so 15-3 = 12 Third Operation is a*b so 15*3 = 45 Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split()) print(a+b) print(a-b) print(a*b) print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and a number N, your task is to print the Nth number of the given series. Series:- 24, 37, 50, 63, 76,. .. .<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>NthNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the Nth number.Sample Input:- 1 Sample Output:- 24 Sample Input:- 3 Sample Output:- 50, I have written this Solution Code: int NthNumber(int N){ return 24+(N-1)*13; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and a number N, your task is to print the Nth number of the given series. Series:- 24, 37, 50, 63, 76,. .. .<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>NthNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the Nth number.Sample Input:- 1 Sample Output:- 24 Sample Input:- 3 Sample Output:- 50, I have written this Solution Code: int NthNumber(int N){ return 24+(N-1)*13; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and a number N, your task is to print the Nth number of the given series. Series:- 24, 37, 50, 63, 76,. .. .<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>NthNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the Nth number.Sample Input:- 1 Sample Output:- 24 Sample Input:- 3 Sample Output:- 50, I have written this Solution Code: def NthNumber(N): return 24+(N-1)*13 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and a number N, your task is to print the Nth number of the given series. Series:- 24, 37, 50, 63, 76,. .. .<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>NthNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the Nth number.Sample Input:- 1 Sample Output:- 24 Sample Input:- 3 Sample Output:- 50, I have written this Solution Code: static int NthNumber(int N){ return 24+(N-1)*13; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the roots of a quadratic equation. <b>Note</b>: Try to do it using Switch Case. <b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠ 0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c. <b>Constraints</b> 1 &le; a, b, c &le; 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2. <b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 : 4 -2 -10 Sample Output 2 : 1.85 -1.35 Sample Input 2 : 2 1 10 Sample Output 2: -0.25+i2.22 -0.25-i2.22, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s=br.readLine().toString(); String[] str = s.split(" "); float a=Float.parseFloat(str[0]); float b=Float.parseFloat(str[1]); float c=Float.parseFloat(str[2]); float div = (float)(b*b-4*a*c); if(div>0.0){ float alpha= (-b+(float)Math.sqrt(div))/(2*a); float beta= (-b-(float)Math.sqrt(div))/(2*a); System.out.printf("%.2f\n",alpha); System.out.printf("%.2f",beta); } else{ float rp=-b/(2*a); float ip=(float)Math.sqrt(-div)/(2*a); System.out.printf("%.2f+i%.2f\n",rp,ip); System.out.printf("%.2f-i%.2f\n",rp,ip); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the roots of a quadratic equation. <b>Note</b>: Try to do it using Switch Case. <b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠ 0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c. <b>Constraints</b> 1 &le; a, b, c &le; 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2. <b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 : 4 -2 -10 Sample Output 2 : 1.85 -1.35 Sample Input 2 : 2 1 10 Sample Output 2: -0.25+i2.22 -0.25-i2.22, I have written this Solution Code: import math a,b,c = map(int, input().split(' ')) disc = (b ** 2) - (4*a*c) sq = disc ** 0.5 if disc > 0: print("{:.2f}".format((-b + sq)/(2*a))) print("{:.2f}".format((-b - sq)/(2*a))) elif disc == 0: print("{:.2f}".format(-b/(2*a))) elif disc < 0: r1 = complex((-b + sq)/(2*a)) r2 = complex((-b - sq)/(2*a)) print("{:.2f}+i{:.2f}".format(r1.real, abs(r1.imag))) print("{:.2f}-i{:.2f}".format(r2.real, abs(r2.imag))), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the roots of a quadratic equation. <b>Note</b>: Try to do it using Switch Case. <b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠ 0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c. <b>Constraints</b> 1 &le; a, b, c &le; 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2. <b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 : 4 -2 -10 Sample Output 2 : 1.85 -1.35 Sample Input 2 : 2 1 10 Sample Output 2: -0.25+i2.22 -0.25-i2.22, I have written this Solution Code: /** * Author : tourist1256 * Time : 2022-01-19 02:44:22 **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 2351 #endif int main() { float a, b, c; float root1, root2, imaginary; float discriminant; scanf("%f%f%f", &a, &b, &c); discriminant = (b * b) - (4 * a * c); switch (discriminant > 0) { case 1: root1 = (-b + sqrt(discriminant)) / (2 * a); root2 = (-b - sqrt(discriminant)) / (2 * a); printf("%.2f\n%.2f", root1, root2); break; case 0: switch (discriminant < 0) { case 1: root1 = root2 = -b / (2 * a); imaginary = sqrt(-discriminant) / (2 * a); printf("%.2f + i%.2f\n%.2f - i%.2f", root1, imaginary, root2, imaginary); break; case 0: root1 = root2 = -b / (2 * a); printf("%.2f\n%.2f", root1, root2); break; } } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array. The second line of each test case contains N space separated integers denoting array elements. Constraints: 1 <= T <= 100 1 <= N <= 10^5 1 <= A[i] <= 10^6 <b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input: 3 10 2 3 4 5 6 7 8 9 10 1 5 3 4 5 1 2 8 10 20 30 45 50 60 4 6 Output: 1 1 4 Explanation: Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1. Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1. Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: def findMin(arr, low, high): if high < low: return arr[0] if high == low: return arr[low] mid = int((low + high)/2) if mid < high and arr[mid+1] < arr[mid]: return arr[mid+1] if mid > low and arr[mid] < arr[mid - 1]: return arr[mid] if arr[high] > arr[mid]: return findMin(arr, low, mid-1) return findMin(arr, mid+1, high) T =int(input()) for i in range(T): N = int(input()) arr = list(input().split()) for k in range(len(arr)): arr[k] = int(arr[k]) print(findMin(arr,0,N-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array. The second line of each test case contains N space separated integers denoting array elements. Constraints: 1 <= T <= 100 1 <= N <= 10^5 1 <= A[i] <= 10^6 <b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input: 3 10 2 3 4 5 6 7 8 9 10 1 5 3 4 5 1 2 8 10 20 30 45 50 60 4 6 Output: 1 1 4 Explanation: Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1. Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1. Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e6 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int t; cin >> t; while(t--){ int n; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; int l = 0, h = n+1; if(a[1] < a[n]){ cout << a[1] << endl; continue; } while(l+1 < h){ int m = (l + h) >> 1; if(a[m] >= a[1]) l = m; else h = m; } cout << a[h] << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array. The second line of each test case contains N space separated integers denoting array elements. Constraints: 1 <= T <= 100 1 <= N <= 10^5 1 <= A[i] <= 10^6 <b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input: 3 10 2 3 4 5 6 7 8 9 10 1 5 3 4 5 1 2 8 10 20 30 45 50 60 4 6 Output: 1 1 4 Explanation: Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1. Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1. Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main{ public static void main (String[] args) { //code Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int j=0;j<t;j++){ int al = s.nextInt(); int a[] = new int[al]; for(int i=0;i<al;i++){ a[i] = s.nextInt(); } binSearchSmallest(a); } } public static void binSearchSmallest(int a[]) { int s=0; int e = a.length - 1; int mid = 0; while(s<=e){ mid = (s+e)/2; if(a[s]<a[e]){ System.out.println(a[s]); return; } if(a[mid]>=a[s]){ s=mid+1; } else{ e=mid; } if(s == e){ System.out.println(a[s]); return; } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array. The second line of each test case contains N space separated integers denoting array elements. Constraints: 1 <= T <= 100 1 <= N <= 10^5 1 <= A[i] <= 10^6 <b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input: 3 10 2 3 4 5 6 7 8 9 10 1 5 3 4 5 1 2 8 10 20 30 45 50 60 4 6 Output: 1 1 4 Explanation: Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1. Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1. Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: // arr is the input array function findMin(arr,n) { // write code here // do not console.log // return the number let min = arr[0] for(let i=1;i<arr.length;i++){ if(min > arr[i]){ min = arr[i] } } return min }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Take an integer as input and print it.The first line contains integer as input. <b>Constraints</b> 1 <= N <= 10Print the input integer in a single lineSample Input:- 2 Sample Output:- 2 Sample Input:- 4 Sample Output:- 4, I have written this Solution Code: /* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Main { public static void printVariable(int variable){ System.out.println(variable); } public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); printVariable(num); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N). Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N. <b>Constraints:</b> 1 &le; T &le; 100 -10.00 &le; X &le;10.00 -10 &le; N &le; 10 For each test case, you need to print the value of X^N. Print up to two places of decimal. <b>Note:</b> Please take care that the output can be very large but it will not exceed double the data type value.Input: 1 2.00 -2 Output: 0.25 <b>Explanation:</b> 2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: // X and Y are numbers // ignore number of testcases variable function pow(X, Y) { // write code here // console.log the output in a single line,like example console.log(Math.pow(X, Y).toFixed(2)) } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N). Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N. <b>Constraints:</b> 1 &le; T &le; 100 -10.00 &le; X &le;10.00 -10 &le; N &le; 10 For each test case, you need to print the value of X^N. Print up to two places of decimal. <b>Note:</b> Please take care that the output can be very large but it will not exceed double the data type value.Input: 1 2.00 -2 Output: 0.25 <b>Explanation:</b> 2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: def power(N,K): return ("{0:.2f}".format(N**K)) T=int(input()) for i in range(T): X,N = map(float,input().strip().split()) print(power(X,N)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N). Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N. <b>Constraints:</b> 1 &le; T &le; 100 -10.00 &le; X &le;10.00 -10 &le; N &le; 10 For each test case, you need to print the value of X^N. Print up to two places of decimal. <b>Note:</b> Please take care that the output can be very large but it will not exceed double the data type value.Input: 1 2.00 -2 Output: 0.25 <b>Explanation:</b> 2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main { public static void main (String[] args)throws Exception { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(read.readLine()); while(t-- > 0) { String str[] = read.readLine().trim().split(" "); double X = Double.parseDouble(str[0]); int N = Integer.parseInt(str[1]); System.out.println(String.format("%.2f", myPow(X, N))); } } public static double myPow(double x, int n) { if (n == Integer.MIN_VALUE) n = - (Integer.MAX_VALUE - 1); if (n == 0) return 1.0; else if (n < 0) return 1 / myPow(x, -n); else if (n % 2 == 1) return x * myPow(x, n - 1); else { double sqrt = myPow(x, n / 2); return sqrt * sqrt; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N). Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N. <b>Constraints:</b> 1 &le; T &le; 100 -10.00 &le; X &le;10.00 -10 &le; N &le; 10 For each test case, you need to print the value of X^N. Print up to two places of decimal. <b>Note:</b> Please take care that the output can be very large but it will not exceed double the data type value.Input: 1 2.00 -2 Output: 0.25 <b>Explanation:</b> 2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: #include "bits/stdc++.h" using namespace std; #define ld long double #define int long long int #define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define endl '\n' const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; ld power(ld x, ld n){ if(n == 0) return 1; else return x*power(x, n-1); } signed main() { speed; int t; cin >> t; while(t--){ double x; int n; cin >> x >> n; if(n < 0) x = 1.0/x, n *= -1; cout << setprecision(2) << fixed << power(x, n) << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: function LeapYear(year){ // write code here // return the output using return keyword // do not use console.log here if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) { return 0; } else { return 1 } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: year = int(input()) if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0: print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int side = scanner.nextInt(); int area = LeapYear(side); if(area==1){ System.out.println("YES");} else{ System.out.println("NO");} } static int LeapYear(int year){ if(year%400==0){return 1;} if(year%100 != 0 && year%4==0){return 1;} else { return 0;} } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array of integers. Consider absolute difference between all the pairs of the the elements. You need to find Kth smallest absolute difference. If the size of the array is N then value of K will be less than N and more than or equal to 1.The first line of input contains number of test cases T. The first line of each test case contains a two integers N and K denoting the number of elements in the array A and difference you need to output. The second line of each test case contains N space separated integers denoting the elements of the array A Constraints: 1<= T <= 10 2 <= N <= 100000 1 <= K < N < 100000 0 <= A[i] <= 100000For each test case, output Kth smallest absolute difference.Input : 1 6 2 1 3 4 1 3 8 Output : 0 Explanation : Test case 1: First smallest difference is 0, between the pair (1, 1) and second smallest absolute difference difference is also 0 between the pairs (3, 3)., I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main{ public static void main(String[] args)throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(read.readLine().trim()); while (t-- > 0) { String str[] = read.readLine().trim().split(" "); int n = Integer.parseInt(str[0]); int k = Integer.parseInt(str[1]); int arr[] = new int[n]; str = read.readLine().trim().split(" "); for (int i = 0; i < n; i++) arr[i] = Integer.parseInt(str[i]); System.out.println(Math.abs(small(arr, k))); } } public static int small(int arr[], int k) { Arrays.sort(arr); int l = 0, r = arr[arr.length - 1] - arr[0]; while (r > l) { int mid = l + (r - l) / 2; if (count(arr, mid) < k) { l = mid + 1; } else { r = mid; } } return r; } public static int count(int arr[], int mid) { int ans = 0, j = 0; for (int i = 1; i < arr.length; ++i) { while (j < i && arr[i] - arr[j] > mid) { ++j; } ans += i - j; } return ans; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Take an integer as input and print it.The first line contains integer as input. <b>Constraints</b> 1 <= N <= 10Print the input integer in a single lineSample Input:- 2 Sample Output:- 2 Sample Input:- 4 Sample Output:- 4, I have written this Solution Code: /* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Main { public static void printVariable(int variable){ System.out.println(variable); } public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); printVariable(num); } } , 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 whether there exists three consecutive same integers in the array.The first line of the input contains an integer N. The second line contains N space separated integers of the array A. Constraints 3 <= N <= 1000 1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input 5 1 2 2 2 4 Sample Output Yes Explanation: The segment [2, 2, 2] follows the criterion. Sample Input 5 1 2 2 3 4 Sample Output No, I have written this Solution Code: n=int(input()) li = list(map(int,input().strip().split())) for i in range(0,n-2): if li[i]==li[i+1] and li[i+1]==li[i+2]: print("Yes",end="") exit() print("No",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 N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N. The second line contains N space separated integers of the array A. Constraints 3 <= N <= 1000 1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input 5 1 2 2 2 4 Sample Output Yes Explanation: The segment [2, 2, 2] follows the criterion. Sample Input 5 1 2 2 3 4 Sample Output No, 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(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define pb push_back #define ll long long #define ld long double #define int long long #define double long double #define mp make_pair #define F first #define S second typedef pair<int, int> pii; typedef vector<int> vi; #define pi 3.141592653589793238 const int MOD = 1e9+7; const int INF = 1LL<<60; const int N = 2e5+5; // 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 void solve(){ int n; cin>>n; vector<int> a(n); bool fl = false; For(i, 0, n){ cin>>a[i]; if(i>=2){ if(a[i]==a[i-1] && a[i]==a[i-2]){ fl = true; } } } if(fl){ cout<<"Yes"; } else cout<<"No"; } signed main() { fast #ifdef SWAPNIL07 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t=1; // cin>>t; while(t--){ solve(); cout<<"\n"; } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N. The second line contains N space separated integers of the array A. Constraints 3 <= N <= 1000 1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input 5 1 2 2 2 4 Sample Output Yes Explanation: The segment [2, 2, 2] follows the criterion. Sample Input 5 1 2 2 3 4 Sample Output No, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[] = new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } for(int i=0;i<n-2;i++){ if(a[i]==a[i+1] && a[i+1]==a[i+2]){ System.out.print("Yes"); return; } } System.out.print("No"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments. Constraints:- 1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input 6 20 Sample Output 3 Sample Input 8 5 Sample Output -1, I have written this Solution Code: function Charity(n,m) { // write code here // do no console.log the answer // return the output using return keyword const per = Math.floor(m / n) return per > 1 ? per : -1 }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments. Constraints:- 1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input 6 20 Sample Output 3 Sample Input 8 5 Sample Output -1, I have written this Solution Code: static int Charity(int n, int m){ int x= m/n; if(x<=1){return -1;} return x; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments. Constraints:- 1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input 6 20 Sample Output 3 Sample Input 8 5 Sample Output -1, I have written this Solution Code: int Charity(int n, int m){ int x= m/n; if(x<=1){return -1;} return x; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments. Constraints:- 1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input 6 20 Sample Output 3 Sample Input 8 5 Sample Output -1, I have written this Solution Code: def Charity(N,M): x = M//N if x<=1: return -1 return x , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments. Constraints:- 1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input 6 20 Sample Output 3 Sample Input 8 5 Sample Output -1, I have written this Solution Code: int Charity(int n, int m){ int x= m/n; if(x<=1){return -1;} return x; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:- a+b a-b a*b a/bThe input contains two integers a and b separated by spaces. <b>Constraints:</b> 1 &le; b &le; a &le; 1000 <b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input: 15 3 Sample Output: 18 12 45 5 <b>Explanation:-</b> First operation is a+b so 15+3 = 18 The second Operation is a-b so 15-3 = 12 Third Operation is a*b so 15*3 = 45 Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args){ FastReader read = new FastReader(); int a = read.nextInt(); int b = read.nextInt(); System.out.println(a+b); System.out.println(a-b); System.out.println(a*b); System.out.println(a/b); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ InputStreamReader inr = new InputStreamReader(System.in); br = new BufferedReader(inr); } String next(){ while(st==null || !st.hasMoreElements()) try{ st = new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble(){ return Double.parseDouble(next()); } long nextLong(){ return Long.parseLong(next()); } String nextLine(){ String str = ""; try{ str = br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:- a+b a-b a*b a/bThe input contains two integers a and b separated by spaces. <b>Constraints:</b> 1 &le; b &le; a &le; 1000 <b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input: 15 3 Sample Output: 18 12 45 5 <b>Explanation:-</b> First operation is a+b so 15+3 = 18 The second Operation is a-b so 15-3 = 12 Third Operation is a*b so 15*3 = 45 Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split()) print(a+b) print(a-b) print(a*b) print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>Arr</b> of <b>N</b> integers arranged in a circular fashion. Your task is to find the <b>minimum absolute difference between adjacent elements</b>.The input line contains T, denoting the number of testcases. Each testcase contains two lines. The first line contains N(size of array). The second line contains N elements of array separated by space. <b>Constraint:</b> 1 <= T <= 100 2 <= N <= 10^5 -10^6 <= Arr[i] <= 10^6 Sum of N over all testcases is less than equal to 10^6For each testcase in new line print the minimum absolute difference.Input: 3 7 8 -8 9 -9 10 -11 12 8 10 -3 -4 7 6 5 -4 -1 8 -1 40 -14 7 6 5 -4 -1 Output: 4 1 0 Explanation: Testcase 1: The absolute difference between adjacent elements in the given array are as such: 16 17 18 19 21 23 4(first and last). Among the calculated absolute difference the minimum is 4. Testcase 2: The absolute difference between adjacent elements in the given array are as such: 13 1 11 1 1 9 3 11(first and last). Among the calculated absolute difference, the minimum is 1. Testcase 3: The absolute difference between adjacent elements in the given array are as such: 41 54 21 1 1 9 3 0(first and last). Among the calculated absolute difference, the minimum is 0., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); while(T-- > 0) { int n = Integer.parseInt(br.readLine()); String str[] = br.readLine().split(" "); int minDiff = Math.abs(Integer.parseInt(str[1]) - Integer.parseInt(str[0])); for(int i = 2; i < n; i++) { minDiff = Math.min(minDiff, Math.abs(Integer.parseInt(str[i]) - Integer.parseInt(str[i-1]))); } minDiff = Math.min(minDiff, Math.abs(Integer.parseInt(str[n-1]) - Integer.parseInt(str[0]))); System.out.println(minDiff); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>Arr</b> of <b>N</b> integers arranged in a circular fashion. Your task is to find the <b>minimum absolute difference between adjacent elements</b>.The input line contains T, denoting the number of testcases. Each testcase contains two lines. The first line contains N(size of array). The second line contains N elements of array separated by space. <b>Constraint:</b> 1 <= T <= 100 2 <= N <= 10^5 -10^6 <= Arr[i] <= 10^6 Sum of N over all testcases is less than equal to 10^6For each testcase in new line print the minimum absolute difference.Input: 3 7 8 -8 9 -9 10 -11 12 8 10 -3 -4 7 6 5 -4 -1 8 -1 40 -14 7 6 5 -4 -1 Output: 4 1 0 Explanation: Testcase 1: The absolute difference between adjacent elements in the given array are as such: 16 17 18 19 21 23 4(first and last). Among the calculated absolute difference the minimum is 4. Testcase 2: The absolute difference between adjacent elements in the given array are as such: 13 1 11 1 1 9 3 11(first and last). Among the calculated absolute difference, the minimum is 1. Testcase 3: The absolute difference between adjacent elements in the given array are as such: 41 54 21 1 1 9 3 0(first and last). Among the calculated absolute difference, the minimum is 0., I have written this Solution Code: def minDiff(arr, n): if(n < 2): return res = abs(arr[1] - arr[0]) for i in range(2, n): res = min(res, abs(arr[i] - arr[i-1])) res = min(res, abs(arr[n-1] - arr[0])) return res for _ in range(int(input())): n=int(input()) arr = list(map(int, input().split())) print(minDiff(arr, n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>Arr</b> of <b>N</b> integers arranged in a circular fashion. Your task is to find the <b>minimum absolute difference between adjacent elements</b>.The input line contains T, denoting the number of testcases. Each testcase contains two lines. The first line contains N(size of array). The second line contains N elements of array separated by space. <b>Constraint:</b> 1 <= T <= 100 2 <= N <= 10^5 -10^6 <= Arr[i] <= 10^6 Sum of N over all testcases is less than equal to 10^6For each testcase in new line print the minimum absolute difference.Input: 3 7 8 -8 9 -9 10 -11 12 8 10 -3 -4 7 6 5 -4 -1 8 -1 40 -14 7 6 5 -4 -1 Output: 4 1 0 Explanation: Testcase 1: The absolute difference between adjacent elements in the given array are as such: 16 17 18 19 21 23 4(first and last). Among the calculated absolute difference the minimum is 4. Testcase 2: The absolute difference between adjacent elements in the given array are as such: 13 1 11 1 1 9 3 11(first and last). Among the calculated absolute difference, the minimum is 1. Testcase 3: The absolute difference between adjacent elements in the given array are as such: 41 54 21 1 1 9 3 0(first and last). Among the calculated absolute difference, the minimum is 0., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ int n; cin>>n; int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; } int mi=INT_MAX; for(int i=0;i<n-1;i++){ mi=min(mi,abs(a[i]-a[i-1])); } mi=min(abs(a[0]-a[n-1]),mi); cout<<mi<<endl; }} , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array of <b>N</b> integers A<sub>1</sub>, A<sub>2</sub>,. . A<sub>N</sub>. You need to answer Q queries. In each query you are given three integers l, r and k. You need to find the minimum mean of the subarray of length at least k of the array A<sub>l</sub>, A<sub>l+1</sub>.. , A<sub>r</sub>.The first line contains two space- separated integers – N and Q. The second line contains N space- separated integers A<sub>1</sub>, A<sub>2</sub>,. . A<sub>N</sub>. Next Q lines contains three integers each L, R and K. <b> Constraints: </b> 1 ≤ N ≤ 200000 1 ≤ Q ≤ 100000 1 ≤ A<sub>i</sub> ≤ 10<sup>9</sup> 1 ≤ L ≤ R ≤ N 1 ≤ K ≤ min(10, R- L+1)Qutput Q lines each containing a single integer the <b>floor</b> of the minimum mean.INPUT 4 2 8 62 2 4 1 3 2 1 4 2 OUTPUT 32 3, I have written this Solution Code: //HEADER FILES AND NAMESPACES #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC target("popcnt") using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; using cd = complex<double>; const double PI = acos(-1); // DEFINE STATEMENTS const long long infty = 1e18; #define num1 1000000007 #define num2 998244353 #define REP(i,a,n) for(ll i=a;i<n;i++) #define REPd(i,a,n) for(ll i=a; i>=n; i--) #define pb push_back #define pob pop_back #define fr first #define sc second #define int long long #define fix(f,n) std::fixed<<std::setprecision(n)<<f #define all(x) x.begin(), x.end() #define M_PI 3.14159265358979323846 #define epsilon (double)(0.000000001) #define popcount __builtin_popcountll #define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout); #define out(x) cout << ((x) ? "Yes\n" : "No\n") #define sz(x) x.size() typedef long long ll; // typedef long long unsigned int llu; typedef vector<long long> vll; typedef pair<long long, long long> pll; typedef vector<pair<long long, long long>> vpll; typedef vector<int> vii; // DEBUG FUNCTIONS #ifndef ONLINE_JUDGE template<typename T> void __p(T a) { cout<<a; } template<typename T, typename F> void __p(pair<T, F> a) { cout<<"{"; __p(a.first); cout<<","; __p(a.second); cout<<"}"; } template<typename T> void __p(std::vector<T> a) { cout<<"{"; for(auto it=a.begin(); it<a.end(); it++) __p(*it),cout<<",}"[it+1==a.end()]; } template<typename T> void __p(std::set<T> a) { cout<<"{"; for(auto it=a.begin(); it!=a.end();){ __p(*it); cout<<",}"[++it==a.end()]; } } template<typename T> void __p(std::multiset<T> a) { cout<<"{"; for(auto it=a.begin(); it!=a.end();){ __p(*it); cout<<",}"[++it==a.end()]; } } template<typename T, typename F> void __p(std::map<T,F> a) { cout<<"{\n"; for(auto it=a.begin(); it!=a.end();++it) { __p(it->first); cout << ": "; __p(it->second); cout<<"\n"; } cout << "}\n"; } template<typename T, typename ...Arg> void __p(T a1, Arg ...a) { __p(a1); __p(a...); } template<typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "; __p(arg1); cout<<endl; } template<typename Arg1, typename ... Args> void __f(const char *names, Arg1 &&arg1, Args &&... args) { int bracket=0,i=0; for(;; i++) if(names[i]==','&&bracket==0) break; else if(names[i]=='(') bracket++; else if(names[i]==')') bracket--; const char *comma=names+i; cout.write(names,comma-names)<<" : "; __p(arg1); cout<<" | "; __f(comma+1,args...); } #define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) #define error(...) #endif struct SegTree { vector<int> tree; SegTree(int N){ tree.resize(4*N+5); } int merge(int a, int b){ return min(a,b); } void build(vector<int> &A, int v, int lx, int rx){ if(lx == rx) { tree[v] = A[lx]; return; } int mid = (lx + rx)/2; build(A, 2*v+1, lx, mid); build(A, 2*v+2, mid+1, rx); tree[v] = merge(tree[2*v+1], tree[2*v+2]); } void point_update(int v, int lx, int rx, int pos, int val) { if(lx == rx){ tree[v] = val; return; } int mid = (lx + rx)/2; if(pos <= mid) point_update(2*v+1, lx, mid, pos, val); else point_update(2*v+2, mid+1, rx, pos, val); tree[v] = merge(tree[2*v+1], tree[2*v+2]); } int range_query(int v, int lx, int rx, int ql, int qr){ //lx <= ql <= qr <= rx if(lx == ql && rx == qr) { return tree[v]; } int mid = (lx + rx)/2; int left_ans = 1e18, right_ans = 1e18; if(mid >= ql) left_ans = range_query(2*v+1, lx, mid, ql, min(qr, mid)); if(qr > mid) right_ans = range_query(2*v+2, mid+1, rx, max(mid+1, ql), qr); return merge(left_ans, right_ans); } }; void solve(){ int n,q; cin >> n >> q; vector<int>a(n); for(int i = 0;i<n;i++)cin >> a[i]; trace(a); vector<SegTree>S(20,n); vector<int>b = a; for(int i = 1;i<20;i++){ S[i].build(b,0,0,n-1); for(int j = 0;j<n-i;j++)b[j] = b[j] + a[j+i]; trace(b); } // trace(b); while(q--){ int l,r,k; cin >> l >> r >> k; l--; r--; int ans = 1e18; for(int i = k;i<=min(2*k-1,r-l+1);i++){ ans = min(ans,S[i].range_query(0,0,n-1,l,r-i+1)/i); } cout << ans << "\n"; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // cout.tie(NULL); #ifdef LOCALFLAG freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t = 1; // cin >> t; while(t--){ solve(); } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array <b>prices</b> where <b>prices[i]</b> is the price of a given stock on the i<sup>th</sup> day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Print the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.First line contains n, denoting the number of days for transaction. Next line contains n space separated integers denoting price on each day. <b>Constraints</b> 1 <= n <= 10<sup>5</sup> 0 <= prices[i] <= 10<sup>9</sup>A single integer denoting the maximum profit.Input: 6 7 1 5 3 6 4 Output: 5 Explanation : buy on 2nd day and sell on 5th day. profit = sell - buy = 6 - 1 = 5, 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 ans=0; int mn=a[0]; for(int i=1;i<n;i++){ int sell=a[i] - mn; ans=Math.max(ans,sell); mn=Math.min(mn,a[i]); } out.print(ans); out.close(); } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void println(int i) { writer.println(i); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number <b>N</b>, find the count of pairs(x, y) such that the absolute value of sum of x<sup>3</sup> and y<sup>3</sup> is equal to N, i. e |x<sup>3</sup> + y<sup>3</sup>|=N<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pairs()</b> that takes the integer N as parameter <b>Constraints</b> 1 <= N <= 10<sup>8</sup>Return the <b>count of pairs</b> which satisfies the given condition.Sample Input:- 8 Sample Output:- 2 Explanation:- The required pairs are (0, -2), (0, 2) Sample Input:- 3 Sample Output:- 0, I have written this Solution Code: def Pairs(N): cnt=0 for i in range(-1000, 1001): for j in range (i,1001): a=i*i*i b=j*j*j if abs(a+b)==N: cnt=cnt+1 return cnt, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number <b>N</b>, find the count of pairs(x, y) such that the absolute value of sum of x<sup>3</sup> and y<sup>3</sup> is equal to N, i. e |x<sup>3</sup> + y<sup>3</sup>|=N<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pairs()</b> that takes the integer N as parameter <b>Constraints</b> 1 <= N <= 10<sup>8</sup>Return the <b>count of pairs</b> which satisfies the given condition.Sample Input:- 8 Sample Output:- 2 Explanation:- The required pairs are (0, -2), (0, 2) Sample Input:- 3 Sample Output:- 0, I have written this Solution Code: int Pairs(long N){ int cnt=0; long int sum=0,a,b,i,j; for(i=-6000 ;i<=6000;i++){ for(j=i; j<=6000;j++){ a=i*i*i; b=j*j*j; if((a+b)>0 && (a+b)==N){ cnt++;} else if((a+b)<0 && (a+b) ==(-N)){cnt++;} }} return cnt; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number <b>N</b>, find the count of pairs(x, y) such that the absolute value of sum of x<sup>3</sup> and y<sup>3</sup> is equal to N, i. e |x<sup>3</sup> + y<sup>3</sup>|=N<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pairs()</b> that takes the integer N as parameter <b>Constraints</b> 1 <= N <= 10<sup>8</sup>Return the <b>count of pairs</b> which satisfies the given condition.Sample Input:- 8 Sample Output:- 2 Explanation:- The required pairs are (0, -2), (0, 2) Sample Input:- 3 Sample Output:- 0, I have written this Solution Code: public static int Pairs(int N){ int cnt=0; long sum=0,a,b,i; for(i=-6000 ;i<=6000;i++){ for(long j=i; j<=6000;j++){ a=i*i*i; b=j*j*j; if(Math.abs(a+b)==N){ cnt++;} } } return cnt; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number <b>N</b>, find the count of pairs(x, y) such that the absolute value of sum of x<sup>3</sup> and y<sup>3</sup> is equal to N, i. e |x<sup>3</sup> + y<sup>3</sup>|=N<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pairs()</b> that takes the integer N as parameter <b>Constraints</b> 1 <= N <= 10<sup>8</sup>Return the <b>count of pairs</b> which satisfies the given condition.Sample Input:- 8 Sample Output:- 2 Explanation:- The required pairs are (0, -2), (0, 2) Sample Input:- 3 Sample Output:- 0, I have written this Solution Code: int Pairs(long N){ int cnt=0; long int sum=0,a,b,i,j; for(i=-6000 ;i<=6000;i++){ for(j=i; j<=6000;j++){ a=i*i*i; b=j*j*j; if(abs(a+b)==N){ cnt++;} } } return cnt; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: static void simpleSum(int a, int b, int c){ System.out.println(a+b+c); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: void simpleSum(int a, int b, int c){ cout<<a+b+c; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: x = input() a, b, c = x.split() a = int(a) b = int(b) c = int(c) print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given any number S ending with 1. What will be the last 2 digits of the resultant number when raised to the power P?The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of string S and power P. Constraints: 1 <= T <= 2*10^3 1 <= |S| <= 60 1 <= P <= 10^6Print the last 2 digit of the resultant. If answer is 1 digit number X, print 0X.Input: 2 1231 213 43591 194 Output: 91 61 Explanation: Testcase 1: When (1231)^213 is calculated the last 2 digits appeared to be 91., I have written this Solution Code: t = int(input()) while (t): n, e = map(int, input().split()) d = (((n // 10) % 10) * (e % 10)) % 10 print(d, 1, sep='') t -= 1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given any number S ending with 1. What will be the last 2 digits of the resultant number when raised to the power P?The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of string S and power P. Constraints: 1 <= T <= 2*10^3 1 <= |S| <= 60 1 <= P <= 10^6Print the last 2 digit of the resultant. If answer is 1 digit number X, print 0X.Input: 2 1231 213 43591 194 Output: 91 61 Explanation: Testcase 1: When (1231)^213 is calculated the last 2 digits appeared to be 91., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define pu push_back #define fi first #define se second #define mp make_pair #define int long long #define pii pair<int,int> #define mm (s+e)/2 #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define sz 200000 signed main() { int t; cin>>t; while(t>0) { t--; string s; cin>>s; int yy; cin>>yy; int n=s.size(); if(n==1) { cout<<"01"<<endl; continue; } int p=s[n-2]-'0'; int q=(p*yy)%10LL; //if(q==0 ) cout<<1<<endl; cout<<q<<1<<endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable