Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: Some Data types are given below:- Integer Long float Double char Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input. Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:- 2 2312351235 1.21 543.1321 c Sample Output:- 2 2312351235 1.21 543.1321 c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){ cout<<a<<endl; cout<<b<<endl; cout <<fixed<< std::setprecision(2) << c << '\n'; cout <<fixed<< std::setprecision(4) << d << '\n'; cout<<e<<endl; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Some Data types are given below:- Integer Long float Double char Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input. Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:- 2 2312351235 1.21 543.1321 c Sample Output:- 2 2312351235 1.21 543.1321 c, I have written this Solution Code: a=int(input()) b=int(input()) x=float(input()) g = "{:.2f}".format(x) d=float(input()) e = "{:.4f}".format(d) u=input() print(a) print(b) print(g) print(e) print(u), 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: 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: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<b>User Task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>quickSort()</b> which contains following arguments. <b>A[]:</b> input array <b>start:</b> starting index of array <b>end</b>: ending index of array Constraints 1 <= T <= 1000 1 <= N <= 10^4 1 <= A[i] <= 10^5 <b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.Sample Input: 2 3 3 1 2 3 4 5 6 Sample Output: 1 2 3 4 5 6, I have written this Solution Code: def partition(array, low, high): pivot = array[high] i = low - 1 for j in range(low, high): if array[j] <= pivot: i = i + 1 (array[i], array[j]) = (array[j], array[i]) (array[i + 1], array[high]) = (array[high], array[i + 1]) return i + 1 def quick_sort(array, low, high): if low < high: pi = partition(array, low, high) quick_sort(array, low, pi - 1) quick_sort(array, pi + 1, high) t=int(input()) for i in range(t): n=int(input()) a=input().strip().split() a=[int(i) for i in a] quick_sort(a, 0, n - 1) for i in a: print(i,end=" ") print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<b>User Task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>quickSort()</b> which contains following arguments. <b>A[]:</b> input array <b>start:</b> starting index of array <b>end</b>: ending index of array Constraints 1 <= T <= 1000 1 <= N <= 10^4 1 <= A[i] <= 10^5 <b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.Sample Input: 2 3 3 1 2 3 4 5 6 Sample Output: 1 2 3 4 5 6, I have written this Solution Code: public static int[] quickSort(int arr[], int low, int high) { if (low < high) { /* pi is partitioning index, arr[pi] is now at right place */ int pi = partition(arr, low, high); // Recursively sort elements before // partition and after partition quickSort(arr, low, pi-1); quickSort(arr, pi+1, high); } return arr; } public static int partition(int arr[], int low, int high) { int pivot = arr[high]; int i = (low-1); // index of smaller element for (int j=low; j<high; j++) { // If current element is smaller than the pivot if (arr[j] < pivot) { i++; // swap arr[i] and arr[j] int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } // swap arr[i+1] and arr[high] (or pivot) int temp = arr[i+1]; arr[i+1] = arr[high]; arr[high] = temp; return i+1; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<b>User Task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>quickSort()</b> which contains following arguments. <b>A[]:</b> input array <b>start:</b> starting index of array <b>end</b>: ending index of array Constraints 1 <= T <= 1000 1 <= N <= 10^4 1 <= A[i] <= 10^5 <b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.Sample Input: 2 3 3 1 2 3 4 5 6 Sample Output: 1 2 3 4 5 6, I have written this Solution Code: function quickSort(arr, low, high) { if(low < high) { let pi = partition(arr, low, high); quickSort(arr, low, pi-1); quickSort(arr, pi+1, high); } return arr; } function partition(arr, low, high) { let pivot = arr[high]; let i = (low-1); // index of smaller element for (let j=low; j<high; j++) { // If current element is smaller than the pivot if (arr[j] < pivot) { i++; // swap arr[i] and arr[j] let temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } // swap arr[i+1] and arr[high] (or pivot) let temp = arr[i+1]; arr[i+1] = arr[high]; arr[high] = temp; return i+1; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Newton wants to take revenge from two apples fallen on his head. So, he applies force F<sub>1</sub> on first apple (mass M<sub>1</sub>) resulting in acceleration of A<sub>1</sub> and F<sub>2</sub> on second apple (mass M<sub>2</sub>) resulting in acceleration of A<sub>2</sub>. Given M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>. Calculate total force applied by him on two apples. <b>Note:</b> F = M*A is the equation of relation between force, mass and acceleration.First line contains four integers M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>. 1 <= M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub> <= 100Output total force applied by Newton.INPUT: 1 2 3 4 OUTPUT: 14 Explanation: Total force is equal to 1*2 + 3*4 = 14., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; int main(){ int m1,a1,m2,a2; cin >> m1 >> a1 >> m2 >> a2; cout << (m1*a1)+(m2*a2) << endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Phoebe is a big GCD fan. Being bored, she starts counting number of pairs of integers (A, B) such that following conditions are satisfied: <li> GCD(A, B) = X (As X is Phoebe's favourite integer) <li> A <= B <= L As Phoebe's performance is coming up, she needs your help to find the number of such pairs possible. Note: GCD refers to the <a href="https://en.wikipedia.org/wiki/Greatest_common_divisor">Greatest common divisor</a>.Input contains two integers L and X. Constraints: 1 <= L, X <= 1000000000Print a single integer denoting number of pairs possible.Sample Input 5 2 Sample Output 2 Explanation: Pairs satisfying all conditions are: (2, 2), (2, 4) Sample Input 5 3 Sample Output 1 Explanation: Pairs satisfying all conditions are: (3, 3), I have written this Solution Code: import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; class Main { InputStream is; PrintWriter out; String INPUT = ""; void solve() { out.println(sumTotient(ni()/ni())); } public static int[] enumTotientByLpf(int n, int[] lpf) { int[] ret = new int[n+1]; ret[1] = 1; for(int i = 2;i <= n;i++){ int j = i/lpf[i]; if(lpf[j] != lpf[i]){ ret[i] = ret[j] * (lpf[i]-1); }else{ ret[i] = ret[j] * lpf[i]; } } return ret; } public static int[] enumLowestPrimeFactors(int n) { int tot = 0; int[] lpf = new int[n+1]; int u = n+32; double lu = Math.log(u); int[] primes = new int[(int)(u/lu+u/lu/lu*1.5)]; for(int i = 2;i <= n;i++)lpf[i] = i; for(int p = 2;p <= n;p++){ if(lpf[p] == p)primes[tot++] = p; int tmp; for(int i = 0;i < tot && primes[i] <= lpf[p] && (tmp = primes[i]*p) <= n;i++){ lpf[tmp] = primes[i]; } } return lpf; } public static long sumTotient(int n) { if(n == 0)return 0L; if(n == 1)return 1L; int s = (int)Math.sqrt(n); long[] cacheu = new long[n/s]; long[] cachel = new long[s+1]; int X = (int)Math.pow(n, 0.66); int[] lpf = enumLowestPrimeFactors(X); int[] tot = enumTotientByLpf(X, lpf); long sum = 0; int p = cacheu.length-1; for(int i = 1;i <= X;i++){ sum += tot[i]; if(i <= s){ cachel[i] = sum; }else if(p > 0 && i == n/p){ cacheu[p] = sum; p--; } } for(int i = p;i >= 1;i--){ int x = n/i; long all = (long)x*(x+1)/2; int ls = (int)Math.sqrt(x); for(int j = 2;x/j > ls;j++){ long lval = i*j < cacheu.length ? cacheu[i*j] : cachel[x/j]; all -= lval; } for(int v = ls;v >= 1;v--){ long w = x/v-x/(v+1); all -= cachel[v]*w; } cacheu[(int)i] = all; } return cacheu[1]; } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new Main().run(); } private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Phoebe is a big GCD fan. Being bored, she starts counting number of pairs of integers (A, B) such that following conditions are satisfied: <li> GCD(A, B) = X (As X is Phoebe's favourite integer) <li> A <= B <= L As Phoebe's performance is coming up, she needs your help to find the number of such pairs possible. Note: GCD refers to the <a href="https://en.wikipedia.org/wiki/Greatest_common_divisor">Greatest common divisor</a>.Input contains two integers L and X. Constraints: 1 <= L, X <= 1000000000Print a single integer denoting number of pairs possible.Sample Input 5 2 Sample Output 2 Explanation: Pairs satisfying all conditions are: (2, 2), (2, 4) Sample Input 5 3 Sample Output 1 Explanation: Pairs satisfying all conditions are: (3, 3), I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// template<class C> void mini(C&a4, C b4){a4=min(a4,b4);} typedef unsigned long long ull; auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define mod 1000000007ll #define pii pair<int,int> ///////////// ull X[20000001]; ull cmp(ull N){ return N*(N+1)/2; } ull solve(ull N){ if(N==1) return 1; if(N < 20000001 && X[N] != 0) return X[N]; ull res = 0; ull q = floor(sqrt(N)); for(int k=2;k<N/q+1;++k){ res += solve(N/k); } for(int m=1;m<q;++m){ res += (N/m - N/(m+1)) * solve(m); } res = cmp(N) - res; if(N < 20000001) X[N] = res; return res; } signed main(){ #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int l,x; cin>>l>>x; if(l<x) cout<<0; else cout<<solve(l/x); #ifdef ANIKET_GOYAL cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:- T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b> Constraints:- -10^3 <= F <= 10^3 <b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1: 77 Sample Output 1: 25 Sample Input 2:- -40 Sample Output 2:- -40 <b>Explanation 1</b>: T(°c) = (T(°f) - 32)*5/9 T(°c) = (77-32)*5/9 T(°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){ n-=32; n/=9; n*=5; cout<<n; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:- T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b> Constraints:- -10^3 <= F <= 10^3 <b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1: 77 Sample Output 1: 25 Sample Input 2:- -40 Sample Output 2:- -40 <b>Explanation 1</b>: T(°c) = (T(°f) - 32)*5/9 T(°c) = (77-32)*5/9 T(°c) =25, I have written this Solution Code: Fahrenheit= int(input()) Celsius = int(((Fahrenheit-32)*5)/9 ) print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:- T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b> Constraints:- -10^3 <= F <= 10^3 <b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1: 77 Sample Output 1: 25 Sample Input 2:- -40 Sample Output 2:- -40 <b>Explanation 1</b>: T(°c) = (T(°f) - 32)*5/9 T(°c) = (77-32)*5/9 T(°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit) { int celsius = ((farhrenheit-32)*5)/9; System.out.println(celsius); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T. The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting. Constraints: 1 <= T <= 100 0 <= N <= 100 0 <= X <= 30Output the waiting time of last patient.Input: 5 4 5 5 3 6 5 7 6 8 2 Output: 15 28 25 24 56, I have written this Solution Code: for i in range(int(input())): n, x = map(int, input().split()) if x >= 10: print(0) else: print((10-x)*(n-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T. The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting. Constraints: 1 <= T <= 100 0 <= N <= 100 0 <= X <= 30Output the waiting time of last patient.Input: 5 4 5 5 3 6 5 7 6 8 2 Output: 15 28 25 24 56, 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, x; cin >> n >> x; if(x >= 10) cout << 0 << endl; else cout << (10-x)*(n-1) << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T. The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting. Constraints: 1 <= T <= 100 0 <= N <= 100 0 <= X <= 30Output the waiting time of last patient.Input: 5 4 5 5 3 6 5 7 6 8 2 Output: 15 28 25 24 56, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); while (T -->0){ String s[] = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int p = Integer.parseInt(s[1]); if (p<10) System.out.println(Math.abs(n-1)*(10-p)); else System.out.println(0); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a row of N shops. Each shop sells A[i] candies. Your friend made an array B of (N-1) integers where B[i] = max(A[i], A[i+1]) for i from 1 to (N-1). You are given array B. You want to generate the array A such that the sum of values of the candies in A is maximum. Find the maximum possible sum of candies of array A.The first line of input contains a single integer N. The second line of input contains (N-1) integers denoting array B. <b>Constraints:</b> 2 &le; N &le; 10<sup>5</sup> 1 &le; B[i] &le; 10<sup>9</sup>Print the maximum possible sum of the candies in array A.Sample Input 4 1 3 4 Sample Output 9 <b>Explanation:</b> Optimal Array A will be [1, 1, 3, 4], I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long b[] = new long[n-1]; long sum=0; for(int i=0;i<n-1;i++) { b[i] = sc.nextLong(); } for(int i=0;i<n-2;i++) { if(b[i]>b[i+1]) { sum += b[i+1]; } else { sum += b[i]; } } sum += b[n-2]; System.out.println(sum+b[0]); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a row of N shops. Each shop sells A[i] candies. Your friend made an array B of (N-1) integers where B[i] = max(A[i], A[i+1]) for i from 1 to (N-1). You are given array B. You want to generate the array A such that the sum of values of the candies in A is maximum. Find the maximum possible sum of candies of array A.The first line of input contains a single integer N. The second line of input contains (N-1) integers denoting array B. <b>Constraints:</b> 2 &le; N &le; 10<sup>5</sup> 1 &le; B[i] &le; 10<sup>9</sup>Print the maximum possible sum of the candies in array A.Sample Input 4 1 3 4 Sample Output 9 <b>Explanation:</b> Optimal Array A will be [1, 1, 3, 4], I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> #define rep(i,n) for (int i=0; i<(n); i++) ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; int a[n]; --n; for(int i=0;i<n;++i){ cin>>a[i]; } int ans=a[0]+a[n-1]; int v=0; for(int i=1;i<n;++i){ ans+=min(a[i],a[i-1]); } cout<<ans; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a row of N shops. Each shop sells A[i] candies. Your friend made an array B of (N-1) integers where B[i] = max(A[i], A[i+1]) for i from 1 to (N-1). You are given array B. You want to generate the array A such that the sum of values of the candies in A is maximum. Find the maximum possible sum of candies of array A.The first line of input contains a single integer N. The second line of input contains (N-1) integers denoting array B. <b>Constraints:</b> 2 &le; N &le; 10<sup>5</sup> 1 &le; B[i] &le; 10<sup>9</sup>Print the maximum possible sum of the candies in array A.Sample Input 4 1 3 4 Sample Output 9 <b>Explanation:</b> Optimal Array A will be [1, 1, 3, 4], I have written this Solution Code: n=int(input()) arr=list(map(int,input().split())) summ=arr[-1] for i in reversed(range(1,len(arr))): if arr[i]>arr[i-1]: summ+=arr[i-1] else: summ+=arr[i] summ+=arr[0] print(summ), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number String S, Your task is to find the sum of the numbers.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Sum()</b> that takes the String S as a parameter. Constraints:- 1 <= |S| <= 1000 Note:- String will contain only numbers from 0-9.Return the sum of the string.Sample Input:- 123 Sample Output:- 6 Sample Input:- 123456789 Sample Output:- 45, I have written this Solution Code: a=input() b=0 for i in a: b=b+int(i) print(b), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number String S, Your task is to find the sum of the numbers.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Sum()</b> that takes the String S as a parameter. Constraints:- 1 <= |S| <= 1000 Note:- String will contain only numbers from 0-9.Return the sum of the string.Sample Input:- 123 Sample Output:- 6 Sample Input:- 123456789 Sample Output:- 45, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); String s = sc.next(); System.out.print(StringLength(s)); } static int StringLength(String S){ int n = S.length(); int sum=0; for(int i=0;i<n;i++){ sum+=(int)S.charAt(i)-(int)'0'; } return sum; } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number String S, Your task is to find the sum of the numbers.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Sum()</b> that takes the String S as a parameter. Constraints:- 1 <= |S| <= 1000 Note:- String will contain only numbers from 0-9.Return the sum of the string.Sample Input:- 123 Sample Output:- 6 Sample Input:- 123456789 Sample Output:- 45, I have written this Solution Code: // str is input string function Sum(str) { // write code here // do not console.log // return the sum return str.split('').map(Number).reduce((a,b)=>a+b,0) }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: 0s and 1s are super cool. You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string. For example, if the initial string is "011010", it will transform in the following manner: <b>01</b>1010 -> 1<b>01</b>0 -> 10 Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S. Constraints 1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input 011010 Sample Output 10 Explanation: Available in the question text. Sample Input 001101 Sample Output -1 , I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer st; st = new StringTokenizer(br.readLine()); String s = st.nextToken(); int curzeroes = 0; StringBuilder sb = new StringBuilder(); int len = s.length(); for(int i = 0;i<len;i++){ if(s.charAt(i) == '1'){ if(curzeroes == 0){ sb.append("1"); } else{ curzeroes--; } } else{ curzeroes++; } } for(int i = 0;i<curzeroes;i++){ sb.append("0"); } if(sb.length() == 0 && curzeroes == 0){ bw.write("-1\n"); } else{ bw.write(sb.toString()+"\n"); } bw.flush(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: 0s and 1s are super cool. You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string. For example, if the initial string is "011010", it will transform in the following manner: <b>01</b>1010 -> 1<b>01</b>0 -> 10 Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S. Constraints 1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input 011010 Sample Output 10 Explanation: Available in the question text. Sample Input 001101 Sample Output -1 , I have written this Solution Code: arr = input() c = 0 res = "" n =len(arr) for i in range(n): if arr[i]=='0': c+=1 else: if c==0: res+='1' else: c-=1 for i in range(c): res+='0' if len(res)==0: print(-1) else: print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: 0s and 1s are super cool. You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string. For example, if the initial string is "011010", it will transform in the following manner: <b>01</b>1010 -> 1<b>01</b>0 -> 10 Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S. Constraints 1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input 011010 Sample Output 10 Explanation: Available in the question text. Sample Input 001101 Sample Output -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; string s; cin >> s; stack<int> st; for(int i = 0; i < (int)s.length(); i++){ if(!st.empty() && s[st.top()] == '0' && s[i] == '1'){ st.pop(); } else st.push(i); } string res = ""; while(!st.empty()){ res += s[st.top()]; st.pop(); } reverse(res.begin(), res.end()); if(res == "") res = "-1"; cout << res; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B. The next two lines contain the input of arrays A and B. <b>Constraints</b> 1 &le; n, m &le; 1000 -10<sup>6</sup> &le; A[i], B[i] &le; 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input : 2 1 1 3 2 Sample Output : 2.00, I have written this Solution Code: import java.io.*; import java.util.*; import java.util.Arrays; class Main { public static double getMedia(long[]a,long[]b){ if(a.length>b.length){ long[]temp; temp=a; a=b;b=temp; } int lo=0; int hi=a.length; int tl=a.length+b.length; while(lo<=hi){ int al=(lo+hi)/2; int bl=((tl+1)/2)-al; long alm1=(al==0)? Long.MIN_VALUE:a[al-1]; long alf=(al==a.length)? Long.MAX_VALUE:a[al]; long blm1=(bl==0)? Long.MIN_VALUE:b[bl-1]; long blf=(bl==b.length)? Long.MAX_VALUE:b[bl]; if(alm1<=blf && blm1<=alf){ double median = 0.0; if(tl%2==0){ long lmax=Math.max(alm1,blm1); long rmin=Math.min(alf,blf); median=(lmax+rmin)/2.0; return median; }else{ long lmax=Math.max(alm1,blm1); median=lmax; return median; } } else if(alm1>blf){ hi=al-1; }else if(blm1>alf){ lo=al+1; } } return 0; } public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str = br.readLine().split(" "); int n=Integer.parseInt(str[0]); int m=Integer.parseInt(str[1]); long[] a=new long[n]; long[] b=new long[m]; str=br.readLine().split(" "); for(int i=0;i<n;i++){ a[i]=Long.parseLong(str[i]); } str=br.readLine().split(" "); for(int i=0;i<m;i++){ b[i]=Long.parseLong(str[i]); } System.out.format("%.2f",getMedia(a,b)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B. The next two lines contain the input of arrays A and B. <b>Constraints</b> 1 &le; n, m &le; 1000 -10<sup>6</sup> &le; A[i], B[i] &le; 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input : 2 1 1 3 2 Sample Output : 2.00, I have written this Solution Code: def getMedian(arr1, arr2, n, m): i=j=0 sort=[] while i<n and j<m: if arr1[i] < arr2[j]: sort.append(arr1[i]) i+=1 else: sort.append(arr2[j]) j+=1 while i<n: sort.append(arr1[i]) i+=1 while j<m: sort.append(arr2[j]) j+=1 if (n+m)%2==1: ind=(len(sort)//2)+1 num=sort[ind-1] else: mid=len(sort)//2 num=(sort[mid-1]+sort[mid])/2 return num n, m= input().split() n, m= int(n),int(m) ar1=list(map(int, input().split())) ar2=list(map(int, input().split())) print("%.2f" %getMedian(ar1, ar2, n, m)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B. The next two lines contain the input of arrays A and B. <b>Constraints</b> 1 &le; n, m &le; 1000 -10<sup>6</sup> &le; A[i], B[i] &le; 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input : 2 1 1 3 2 Sample Output : 2.00, I have written this Solution Code: /** * Author : tourist1256 * Time : 2022-02-02 14:05:28 **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 2351 #endif double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { if (nums2.size() < nums1.size()) return findMedianSortedArrays(nums2, nums1); int n1 = nums1.size(); int n2 = nums2.size(); int lo = 0, hi = n1; while (lo <= hi) { int cut1 = (lo + hi) / 2; int cut2 = (n1 + n2 + 1) / 2 - cut1; int left1 = cut1 == 0 ? INT_MIN : nums1[cut1 - 1]; int left2 = cut2 == 0 ? INT_MIN : nums2[cut2 - 1]; int right1 = cut1 == n1 ? INT_MAX : nums1[cut1]; int right2 = cut2 == n2 ? INT_MAX : nums2[cut2]; if (left1 <= right2 && left2 <= right1) { if ((n1 + n2) % 2 == 0) return (max(left1, left2) + min(right1, right2)) / 2.0; else return max(left1, left2); } else if (left1 > right2) { hi = cut1 - 1; } else lo = cut1 + 1; } return 0.0; } int main() { int n, m; cin >> n >> m; vector<int> a(n), b(m); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } printf("%0.2f", findMedianSortedArrays(a, b)); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N). You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building. You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings. The next line contains N space seperated integers denoting heights of the buildings from left to right. Constraints 1 <= N <= 100000 1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input: 5 1 2 2 4 3 Sample output: 3 Explanation:- the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4 Sample input: 5 1 2 3 4 5 Sample output: 5 , I have written this Solution Code: n=int(input()) a=map(int,input().split()) b=[] mx=-200000 cnt=0 for i in a: if i>mx: cnt+=1 mx=i print(cnt), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N). You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building. You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings. The next line contains N space seperated integers denoting heights of the buildings from left to right. Constraints 1 <= N <= 100000 1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input: 5 1 2 2 4 3 Sample output: 3 Explanation:- the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4 Sample input: 5 1 2 3 4 5 Sample output: 5 , I have written this Solution Code: function numberOfRoofs(arr) { let count=1; let max = arr[0]; for(let i=1;i<arrSize;i++) { if(arr[i] > max) { count++; max = arr[i]; } } return count; } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N). You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building. You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings. The next line contains N space seperated integers denoting heights of the buildings from left to right. Constraints 1 <= N <= 100000 1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input: 5 1 2 2 4 3 Sample output: 3 Explanation:- the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4 Sample input: 5 1 2 3 4 5 Sample output: 5 , I have written this Solution Code: import java.util.*; import java.io.*; class Main{ public static void main(String args[]){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int []a=new int[n]; for(int i=0;i<n;i++){ a[i]=s.nextInt(); } int count=1; int max = a[0]; for(int i=1;i<n;i++) { if(a[i] > max) { count++; max = a[i]; } } System.out.println(count); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order. Constraints 1<=N<=1000 -10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input: 6 3 1 2 7 9 87 Sample Output: 87 9 7 3 2 1, I have written this Solution Code: function bubbleSort(arr, n) { // write code here // do not console.log the answer // return sorted array return arr.sort((a, b) => b - a) } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order. Constraints 1<=N<=1000 -10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input: 6 3 1 2 7 9 87 Sample Output: 87 9 7 3 2 1, I have written this Solution Code: def bubbleSort(arr): arr.sort(reverse = True) return arr , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order. Constraints 1<=N<=1000 -10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input: 6 3 1 2 7 9 87 Sample Output: 87 9 7 3 2 1, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int a[] = new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } int t; for(int i=1;i<n;i++){ if(a[i]>a[i-1]){ for(int j=i;j>0;j--){ if(a[j]>a[j-1]){ t=a[j]; a[j]=a[j-1]; a[j-1]=t; } } } } for(int i=0;i<n;i++){ System.out.print(a[i]+" "); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order. Constraints 1<=N<=1000 -10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input: 6 3 1 2 7 9 87 Sample Output: 87 9 7 3 2 1, I have written this Solution Code: // author-Shivam gupta #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 const int N = 3e5+5; #define read(type) readInt<type>() #define max1 100001 #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' const double pi=acos(-1.0); typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<string> VS; typedef vector<PII> VII; typedef vector<VI> VVI; typedef map<int,int> MPII; typedef set<int> SETI; typedef multiset<int> MSETI; typedef long int li; typedef unsigned long int uli; typedef long long int ll; typedef unsigned long long int ull; const ll inf = 0x3f3f3f3f3f3f3f3f; const ll mod = 998244353; using vl = vector<ll>; bool isPowerOfTwo (int x) { /* First x in the below expression is for the case when x is 0 */ return x && (!(x&(x-1))); } void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } ll power(ll x, ll y, ll p) { ll res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) % p; // y must be even now y = y>>1; // y = y/2 x = (x*x) % p; } return res; } long long phi[max1], result[max1],F[max1]; // Precomputation of phi[] numbers. Refer below link // for details : https://goo.gl/LUqdtY void computeTotient() { // Refer https://goo.gl/LUqdtY phi[1] = 1; for (int i=2; i<max1; i++) { if (!phi[i]) { phi[i] = i-1; for (int j = (i<<1); j<max1; j+=i) { if (!phi[j]) phi[j] = j; phi[j] = (phi[j]/i)*(i-1); } } } for(int i=1;i<=100000;i++) { for(int j=i;j<=100000;j+=i) { int p=j/i; F[j]+=(i*phi[p])%mod; F[j]%=mod; } } } int gcd(int a, int b, int& x, int& y) { if (b == 0) { x = 1; y = 0; return a; } int x1, y1; int d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } bool find_any_solution(int a, int b, int c, int &x0, int &y0, int &g) { g = gcd(abs(a), abs(b), x0, y0); if (c % g) { return false; } x0 *= c / g; y0 *= c / g; if (a < 0) x0 = -x0; if (b < 0) y0 = -y0; return true; } int main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } sort(a,a+n,greater<int>()); FOR(i,n){ out1(a[i]);} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You must have solved the problem 'Tribonacci Numbers'. Now its time for Tribonacci strings. Given three strings T[1] = "p", T[2] = "q", T[3] = "r", String T[i] = T[i-1] + T[i-2] + T[i-3] Find the character at K'th index in string T[N] (assuming 1-indexing) Solve for Q independent queriesFirst line of input contains a single integer Q Q lines follow, each containing two space separated numbers N and K 1 <= Q <= 10^5 1 <= N <= 60 1 <= K <= 10^16Print Q lines, each containing the character at K-th index of string T[N]. If K exceeds the length of string, print xSample Input 1: 3 6 2 6 8 6 12 Sample Output 1: q p x Explanation: T[1] = p T[2] = q T[3] = r T[4] = rqp T[5] = rqprq T[6] = rqprqrqpr, I have written this Solution Code: import java.util.*; import java.io.*; class Main{ public static char tribonacci(long arr[],int n,long k) { if(arr[n]<k) return 'x'; if(n==1) return 'p'; if(n==2) return 'q'; if(n==3) return 'r'; if(arr[n-1]>=k) { char ans=tribonacci(arr,n-1,k); return ans; } else if(arr[n-1]+arr[n-2]>=k) { char ans=tribonacci(arr,n-2,k-arr[n-1]); return ans; } else if(arr[n-1]+arr[n-2]+arr[n-3]>=k) { char ans=tribonacci(arr,n-3,k-arr[n-1]-arr[n-2]); return ans; } return 'x'; } public static void main(String args[])throws IOException { InputStreamReader r=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(r); int t; t=Integer.parseInt(br.readLine()); while(t-->0) { String ar1[]=br.readLine().split(" "); int n; n=Integer.parseInt(ar1[0]); long k; k=Long.parseLong(ar1[1]); long arr[]=new long[61]; arr[1]=1; arr[2]=1; arr[3]=1; for(int i=4;i<61;i++) { arr[i]=arr[i-1]+arr[i-2]+arr[i-3]; } char ans=tribonacci(arr,n,k); System.out.println(ans); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You must have solved the problem 'Tribonacci Numbers'. Now its time for Tribonacci strings. Given three strings T[1] = "p", T[2] = "q", T[3] = "r", String T[i] = T[i-1] + T[i-2] + T[i-3] Find the character at K'th index in string T[N] (assuming 1-indexing) Solve for Q independent queriesFirst line of input contains a single integer Q Q lines follow, each containing two space separated numbers N and K 1 <= Q <= 10^5 1 <= N <= 60 1 <= K <= 10^16Print Q lines, each containing the character at K-th index of string T[N]. If K exceeds the length of string, print xSample Input 1: 3 6 2 6 8 6 12 Sample Output 1: q p x Explanation: T[1] = p T[2] = q T[3] = r T[4] = rqp T[5] = rqprq T[6] = rqprqrqpr, I have written this Solution Code: #include "bits/stdc++.h" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; char rec(int n, int k){ if(k > a[n]) return 'x'; if(n == 1) return 'p'; if(n == 2) return 'q'; if(n == 3) return 'r'; if(k <= a[n-1]) return rec(n-1, k); k -= a[n-1]; if(k <= a[n-2]) return rec(n-2, k); k -= a[n-2]; return rec(n-3, k); } signed main() { IOS; clock_t start = clock(); int t; cin >> t; a[1] = a[2] = a[3] = 1; for(int i = 4; i <= 60; i++) a[i] = a[i-1] + a[i-2] + a[i-3]; while(t--){ int n, k; cin >> n >> k; cout << rec(n, k) << endl; } cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: In the morning assembly, there are N students standing in a line, such that the ith student from the front has height H[i]. In one move, you can pick any two students and swap their positions. If you are allowed to do only one swap, can you arrange the students in increasing order of their hieghts?The first line of input contains T, the number of test cases. The first line of each test case contains N, the number of students in the line. The second line of each test case contains the heights of N students, where the ith index is the height of ith student. <b>Constraints:</b> 1 <= T <= 10<sup>3</sup> 1 <= N <= 10<sup>4</sup> 1 <= H_i <= 10<sup>5</sup>For each test case, output YES or NOSample Input 2 3 1 2 3 4 2 1 4 3 Sample Output YES NO Explanation: The students are already standing in increasing order in the first test case, hence the answer is YES., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner input=new Scanner(System.in); int t = input.nextInt(); for(int i = 0; i< t; i++){ int n = input.nextInt(); int[] arr = new int[n]; for (int j = 0; j < n; j++) { arr[j] = input.nextInt(); } System.out.println(arrStu(arr, n)); } } public static String arrStu(int[] arr, int n ){ int[] newArr = new int[n]; for(int i = 0; i<n ;i++){ newArr[i] = arr[i]; } Arrays.sort(newArr); int count = 0; for(int i = 0 ; i< n ;i++){ if(arr[i] != newArr[i]) count++; } if(count > 2) return "NO"; else return "YES"; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: In the morning assembly, there are N students standing in a line, such that the ith student from the front has height H[i]. In one move, you can pick any two students and swap their positions. If you are allowed to do only one swap, can you arrange the students in increasing order of their hieghts?The first line of input contains T, the number of test cases. The first line of each test case contains N, the number of students in the line. The second line of each test case contains the heights of N students, where the ith index is the height of ith student. <b>Constraints:</b> 1 <= T <= 10<sup>3</sup> 1 <= N <= 10<sup>4</sup> 1 <= H_i <= 10<sup>5</sup>For each test case, output YES or NOSample Input 2 3 1 2 3 4 2 1 4 3 Sample Output YES NO Explanation: The students are already standing in increasing order in the first test case, hence the answer is YES., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; signed main(){ int t=1; cin>>t; while(t--){ int n; cin>>n; vector<int> v(n); for(int i=0;i<n;i++){ cin>>v[i]; } vector<int> b= v; sort(b.begin(),b.end()); int cnt=0; for(int i=0;i<n;i++){ if(b[i]!=v[i]) cnt++; } if(cnt==0 or cnt==2){ cout<<"YES\n"; }else cout<<"NO\n"; } return 0; } , 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: 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 an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K. Constraints: 1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input: 28 Sample Output: 4 Explaination: 4<sup>2</sup> + 3*4 = 28 There is no other positive integer that will give such result., I have written this Solution Code: def FindIt(n): sqrt_n = int(K**0.5) check = -1 for i in range(sqrt_n - 1, sqrt_n - 2, -1): check = i**2 + (i * 3) if check == n: return i return -1 K = int(input()) print(FindIt(K)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K. Constraints: 1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input: 28 Sample Output: 4 Explaination: 4<sup>2</sup> + 3*4 = 28 There is no other positive integer that will give such result., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); #define int long long #define pb push_back #define ff first #define ss second #define endl '\n' #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using T = pair<int, int>; typedef long double ld; const int mod = 1e9 + 7; const int INF = 1e9; void solve(){ int n; cin >> n; int l = 1, r = 1e9, ans = -1; while(l <= r){ int m = (l + r)/2; int val = m*m + 3*m; if(val == n){ ans = m; break; } if(val < n){ l = m + 1; } else r = m - 1; } cout << ans; } signed main(){ fast int t = 1; // cin >> t; for(int i = 1; i <= t; i++){ solve(); if(i != t) cout << endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K. Constraints: 1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input: 28 Sample Output: 4 Explaination: 4<sup>2</sup> + 3*4 = 28 There is no other positive integer that will give such result., 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)); long K = Long.parseLong(br.readLine()); long ans = -1; for(long x =0;((x*x)+(3*x))<=K;x++){ if(K==((x*x)+(3*x))){ ans = x; break; } } System.out.println(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A. Constraints 1 <= T <= 100 1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input 3 5 9 13 Output Yes No Yes, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int testcase = Integer.parseInt(br.readLine()); for(int t=0;t<testcase;t++){ int num = Integer.parseInt(br.readLine().trim()); if(num==1) System.out.println("No"); else if(num<=3) System.out.println("Yes"); else{ if((num%2==0)||(num%3==0)) System.out.println("No"); else{ int flag=0; for(int i=5;i*i<=num;i+=6){ if(((num%i)==0)||(num%(i+2)==0)){ System.out.println("No"); flag=1; break; } } if(flag==0) System.out.println("Yes"); } } } }catch (Exception e) { System.out.println("I caught: " + e); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A. Constraints 1 <= T <= 100 1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input 3 5 9 13 Output Yes No Yes, I have written this Solution Code: t=int(input()) for i in range(t): number = int(input()) if number > 1: i=2 while i*i<=number: if (number % i) == 0: print("No") break i+=1 else: print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A. Constraints 1 <= T <= 100 1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input 3 5 9 13 Output Yes No Yes, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ long long n,k; cin>>n; long x=sqrt(n); int cnt=0; vector<int> v; for(long long i=2;i<=x;i++){ if(n%i==0){ cout<<"No"<<endl; goto f; }} cout<<"Yes"<<endl; f:; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N Constraints: 1 <= T <= 50 1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input: 2 9 8 Output 0 3, I have written this Solution Code: import math n = int(input()) for i in range(n): x = int(input()) count = 0 for i in range(1, int(math.sqrt(x))+1): if x % i == 0: if (i%2 == 0): count+=1 if ((x/i) %2 == 0): count+=1 print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N Constraints: 1 <= T <= 50 1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input: 2 9 8 Output 0 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 t = Integer.parseInt(br.readLine()); while(t-->0){ int n = Integer.parseInt(br.readLine()); int count=0; for(int i=1;i<=Math.sqrt(n);i++){ if(n%i == 0) { if(i%2==0) { count++; } if(i*i != n && (n/i)%2==0) { count++; } } } System.out.println(count); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N Constraints: 1 <= T <= 50 1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input: 2 9 8 Output 0 3, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ long long n; cin>>n; if(n&1){cout<<0<<endl;continue;} long x=sqrt(n); int cnt=0; for(long long i=1;i<=x;i++){ if(!(n%i)){ if(!(i%2)){cnt++;} if(i*i!=n){ if(!((n/i)%2)){cnt++;} } } } cout<<cnt<<endl;} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move . Note:- Rows and Columns are numbered through 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 function <b>Knight()</b> that takes integers X and Y as arguments. Constraints:- 1 <= X <= 8 1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:- 4 5 Sample Output:- 8 Explanation:- Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4) Sample input:- 1 1 Sample Output:- 2 Explanation:- Positions:- (3, 2), (2, 3), I have written this Solution Code: def Knight(X,Y): cnt=0 if(X>2): if(Y>1): cnt=cnt+1 if(Y<8): cnt=cnt+1 if(Y>2): if(X>1): cnt=cnt+1 if(X<8): cnt=cnt+1 if(X<7): if(Y>1): cnt=cnt+1 if(Y<8): cnt=cnt+1 if(Y<7): if(X>1): cnt=cnt+1 if(X<8): 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 an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move . Note:- Rows and Columns are numbered through 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 function <b>Knight()</b> that takes integers X and Y as arguments. Constraints:- 1 <= X <= 8 1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:- 4 5 Sample Output:- 8 Explanation:- Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4) Sample input:- 1 1 Sample Output:- 2 Explanation:- Positions:- (3, 2), (2, 3), I have written this Solution Code: static int Knight(int X, int Y){ int cnt=0; if(X>2){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y<7){ if(X>1){cnt++;} if(X<8){cnt++;} } if(X<7){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y>2){ if(X>1){cnt++;} if(X<8){cnt++;} } return cnt; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move . Note:- Rows and Columns are numbered through 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 function <b>Knight()</b> that takes integers X and Y as arguments. Constraints:- 1 <= X <= 8 1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:- 4 5 Sample Output:- 8 Explanation:- Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4) Sample input:- 1 1 Sample Output:- 2 Explanation:- Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){ int cnt=0; if(X>2){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y<7){ if(X>1){cnt++;} if(X<8){cnt++;} } if(X<7){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y>2){ if(X>1){cnt++;} if(X<8){cnt++;} } return cnt; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move . Note:- Rows and Columns are numbered through 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 function <b>Knight()</b> that takes integers X and Y as arguments. Constraints:- 1 <= X <= 8 1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:- 4 5 Sample Output:- 8 Explanation:- Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4) Sample input:- 1 1 Sample Output:- 2 Explanation:- Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){ int cnt=0; if(X>2){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y<7){ if(X>1){cnt++;} if(X<8){cnt++;} } if(X<7){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y>2){ if(X>1){cnt++;} if(X<8){cnt++;} } return cnt; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Insertion is a basic but frequently used operation. Arrays in most languages cannot be dynamically shrinked or expanded. Here, we will work with such arrays and try to insert an element at some index. You are given an array arr. The size of the array is given by sizeOfArray. You need to insert an element at given index and print the modified array.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains size of the array denoted by sizeOfArray, element to be inserted and index. The third line contains sizeOfArray-1 elements separated by spaces. Constraints: 1 <= T <= 100 2 <= sizeOfArray <= 10^4 0 <= element, arr(i) <= 10^6 0 <= index <= sizeOfArray-1For each testcase, in a new line, print the modified array.Input: 2 6 90 5 1 2 3 4 5 6 90 2 1 2 3 4 5 Output: 1 2 3 4 5 90 1 2 90 3 4 5 Explanation: Testcase 1: 90 in inserted at index 5(0-based indexing). After inserting, array elements are like 1, 2, 3, 4, 5, 90. Testcase 2: 90 in inserted at index 2(0-based indexing). After inserting, array elements are like 1, 2, 90, 3, 4, 5., 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(" "); int N = Integer.parseInt(str[0]); int ele = Integer.parseInt(str[1]); int index = Integer.parseInt(str[2]); str = read.readLine().trim().split(" "); int arr[] = new int[N]; for(int i = 0; i < N-1; i++) arr[i] = Integer.parseInt(str[i]); insertAtIndex(arr, N, index, ele); for(int i = 0; i < N; i++) System.out.print(arr[i] + " "); System.out.println(); } } public static void insertAtIndex(int arr[],int sizeOfArray,int index,int element) { // if index is last index // then insert the element if(index==sizeOfArray-1) { arr[index]=element; return; } // else shift the elements, and then insert for(int i=sizeOfArray-1;i>index;i--) { int temp=arr[i]; arr[i]=arr[i-1]; arr[i-1]=temp; } arr[index]=element; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Insertion is a basic but frequently used operation. Arrays in most languages cannot be dynamically shrinked or expanded. Here, we will work with such arrays and try to insert an element at some index. You are given an array arr. The size of the array is given by sizeOfArray. You need to insert an element at given index and print the modified array.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains size of the array denoted by sizeOfArray, element to be inserted and index. The third line contains sizeOfArray-1 elements separated by spaces. Constraints: 1 <= T <= 100 2 <= sizeOfArray <= 10^4 0 <= element, arr(i) <= 10^6 0 <= index <= sizeOfArray-1For each testcase, in a new line, print the modified array.Input: 2 6 90 5 1 2 3 4 5 6 90 2 1 2 3 4 5 Output: 1 2 3 4 5 90 1 2 90 3 4 5 Explanation: Testcase 1: 90 in inserted at index 5(0-based indexing). After inserting, array elements are like 1, 2, 3, 4, 5, 90. Testcase 2: 90 in inserted at index 2(0-based indexing). After inserting, array elements are like 1, 2, 90, 3, 4, 5., I have written this Solution Code: t=int(input()) while t>0: t-=1 li = list(map(int,input().strip().split())) n=li[0] num=li[1] i=li[2] a= list(map(int,input().strip().split())) a.insert(i,num) for i in a: print(i,end=" ") print(), 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: 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: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it. The pattern for height 6:- 0 4 8 12 16 20 6 10 14 18 22 26 12 16 20 24 28 32 18 22 26 30 34 38 24 28 32 36 40 44 30 34 38 42 46 50<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument. Constraints:- 1 <= N <= 100Print the given pattern.Sample Input:- 3 Sample Output:- 0 4 8 6 10 14 12 16 20 Sample Input:- 5 Sample Output:- 0 4 8 12 16 6 10 14 18 22 12 16 20 24 28 18 22 26 30 34 24 28 32 36 40, I have written this Solution Code: static void Pattern(int N){ int x=0; for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ System.out.print(x+4*j+" "); } System.out.println(); x+=6; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it. The pattern for height 6:- 0 4 8 12 16 20 6 10 14 18 22 26 12 16 20 24 28 32 18 22 26 30 34 38 24 28 32 36 40 44 30 34 38 42 46 50<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument. Constraints:- 1 <= N <= 100Print the given pattern.Sample Input:- 3 Sample Output:- 0 4 8 6 10 14 12 16 20 Sample Input:- 5 Sample Output:- 0 4 8 12 16 6 10 14 18 22 12 16 20 24 28 18 22 26 30 34 24 28 32 36 40, I have written this Solution Code: def Pattern(N): x=0 for i in range (0,N): for j in range (0,N): print(x+4*j,end=' ') print() x = x+6 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it. The pattern for height 6:- 0 4 8 12 16 20 6 10 14 18 22 26 12 16 20 24 28 32 18 22 26 30 34 38 24 28 32 36 40 44 30 34 38 42 46 50<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument. Constraints:- 1 <= N <= 100Print the given pattern.Sample Input:- 3 Sample Output:- 0 4 8 6 10 14 12 16 20 Sample Input:- 5 Sample Output:- 0 4 8 12 16 6 10 14 18 22 12 16 20 24 28 18 22 26 30 34 24 28 32 36 40, I have written this Solution Code: void Pattern(int N){ int x=0; for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ printf("%d ",x+4*j); } printf("\n"); x+=6; } }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it. The pattern for height 6:- 0 4 8 12 16 20 6 10 14 18 22 26 12 16 20 24 28 32 18 22 26 30 34 38 24 28 32 36 40 44 30 34 38 42 46 50<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument. Constraints:- 1 <= N <= 100Print the given pattern.Sample Input:- 3 Sample Output:- 0 4 8 6 10 14 12 16 20 Sample Input:- 5 Sample Output:- 0 4 8 12 16 6 10 14 18 22 12 16 20 24 28 18 22 26 30 34 24 28 32 36 40, I have written this Solution Code: void Pattern(int N){ int x=0; for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ printf("%d ",x+4*j); } printf("\n"); x+=6; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N). You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building. You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings. The next line contains N space seperated integers denoting heights of the buildings from left to right. Constraints 1 <= N <= 100000 1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input: 5 1 2 2 4 3 Sample output: 3 Explanation:- the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4 Sample input: 5 1 2 3 4 5 Sample output: 5 , I have written this Solution Code: n=int(input()) a=map(int,input().split()) b=[] mx=-200000 cnt=0 for i in a: if i>mx: cnt+=1 mx=i print(cnt), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N). You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building. You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings. The next line contains N space seperated integers denoting heights of the buildings from left to right. Constraints 1 <= N <= 100000 1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input: 5 1 2 2 4 3 Sample output: 3 Explanation:- the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4 Sample input: 5 1 2 3 4 5 Sample output: 5 , I have written this Solution Code: function numberOfRoofs(arr) { let count=1; let max = arr[0]; for(let i=1;i<arrSize;i++) { if(arr[i] > max) { count++; max = arr[i]; } } return count; } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N). You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building. You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings. The next line contains N space seperated integers denoting heights of the buildings from left to right. Constraints 1 <= N <= 100000 1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input: 5 1 2 2 4 3 Sample output: 3 Explanation:- the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4 Sample input: 5 1 2 3 4 5 Sample output: 5 , I have written this Solution Code: import java.util.*; import java.io.*; class Main{ public static void main(String args[]){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int []a=new int[n]; for(int i=0;i<n;i++){ a[i]=s.nextInt(); } int count=1; int max = a[0]; for(int i=1;i<n;i++) { if(a[i] > max) { count++; max = a[i]; } } System.out.println(count); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) . Your task is to check whether the queen can attack the king in one move or not. The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments. Constraints:- 1 <= X, Y, P, Q <= 8 Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:- 1 1 5 5 Sample Output:- 1 Sample Input:- 3 4 6 6 Sample Output:- 0, I have written this Solution Code: def QueenAttack(X, Y, P, Q): if X==P or Y==Q or abs(X-P)==abs(Y-Q): return 1 return 0, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) . Your task is to check whether the queen can attack the king in one move or not. The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments. Constraints:- 1 <= X, Y, P, Q <= 8 Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:- 1 1 5 5 Sample Output:- 1 Sample Input:- 3 4 6 6 Sample Output:- 0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){ if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){ return 1; } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) . Your task is to check whether the queen can attack the king in one move or not. The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments. Constraints:- 1 <= X, Y, P, Q <= 8 Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:- 1 1 5 5 Sample Output:- 1 Sample Input:- 3 4 6 6 Sample Output:- 0, I have written this Solution Code: static int QueenAttack(int X, int Y, int P, int Q){ if(X==P || Y==Q || Math.abs(X-P)==Math.abs(Y-Q) ){ return 1; } return 0; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) . Your task is to check whether the queen can attack the king in one move or not. The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments. Constraints:- 1 <= X, Y, P, Q <= 8 Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:- 1 1 5 5 Sample Output:- 1 Sample Input:- 3 4 6 6 Sample Output:- 0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){ if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){ return 1; } return 0; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, find the number of distinct arrays A, such that the sum of integers in the array is N and each integer in the array is greater than or equal to 3. As the answer can be large, output it modulo 10<sup>9</sup>+7.The first and the only line of input contains an integer N. Constraints 1 <= N <= 1000Output a single integer, the number of arrays modulo 1000000007.Sample Input 8 Sample Output 4 Explanation: Following are the possible arrays: [3, 5], [4, 4], [5, 3], [8]. Sample Input 2 Sample Output 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().trim()); long[] arr = new long[n+1]; for(int i = 3; i <= n; i++) arr[i] = -1; if(n < 3) { System.out.println(0); } else { long out = findRandomSequences(n, arr); System.out.println(out); } } public static long findRandomSequences(int n, long arr[]) { if(n >= 3 && n < 6) return 1; if(arr[n] != -1) return arr[n]; long count = 0; for(int i = n-3; i >= 3; i--) { count += (findRandomSequences(i, arr) % 1000000007); } arr[n] = (count+1) % 1000000007; return arr[n]; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, find the number of distinct arrays A, such that the sum of integers in the array is N and each integer in the array is greater than or equal to 3. As the answer can be large, output it modulo 10<sup>9</sup>+7.The first and the only line of input contains an integer N. Constraints 1 <= N <= 1000Output a single integer, the number of arrays modulo 1000000007.Sample Input 8 Sample Output 4 Explanation: Following are the possible arrays: [3, 5], [4, 4], [5, 3], [8]. Sample Input 2 Sample Output 0, I have written this Solution Code: n = int(input()) memoArray = [0]*(n+1) def findWays(n): memoArray[3], memoArray[4], memoArray [5] = 1,1,1 for i in range(6,n+1): memoArray[i] = (memoArray[i-1]+memoArray[i-3])%1000000007 return memoArray[n] if n<3: print(0) elif n==3 or n == 4: print(1) else: print(findWays(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, find the number of distinct arrays A, such that the sum of integers in the array is N and each integer in the array is greater than or equal to 3. As the answer can be large, output it modulo 10<sup>9</sup>+7.The first and the only line of input contains an integer N. Constraints 1 <= N <= 1000Output a single integer, the number of arrays modulo 1000000007.Sample Input 8 Sample Output 4 Explanation: Following are the possible arrays: [3, 5], [4, 4], [5, 3], [8]. Sample Input 2 Sample Output 0, 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> dp(n+1, 0); dp[0]=1; For(i, 3, n+1){ For(j, 3, i+1){ dp[i] += dp[i-j]; } dp[i]%=MOD; } cout<<dp[n]; } 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 a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring. For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases. The first and the only line of each test case contains the string S. Constraints: 1 ≤ T ≤ 100 1 ≤ length of S ≤ 1000Print length of longest substring having such that all characters are unique . Sample Input: 2 abababcdefababcdab gccksfvrgccks Sample Output: 6 7, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t>0) { t--; char [] arr = br.readLine().toCharArray(); int [] hash = new int[256]; int i = 0,j=0,max=0; while(j != arr.length) { hash[arr[j]]++; while (hash[arr[j]] > 1) { hash[arr[i]]--; i++; } max = Math.max(max, j-i+1); j++; } System.out.println(max); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring. For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases. The first and the only line of each test case contains the string S. Constraints: 1 ≤ T ≤ 100 1 ≤ length of S ≤ 1000Print length of longest substring having such that all characters are unique . Sample Input: 2 abababcdefababcdab gccksfvrgccks Sample Output: 6 7, I have written this Solution Code: def longestUniqueSubsttr(string): last_idx = {} max_len = 0 start_idx = 0 for i in range(0, len(string)): if string[i] in last_idx: start_idx = max(start_idx, last_idx[string[i]] + 1) max_len = max(max_len, i-start_idx + 1) last_idx[string[i]] = i return max_len t=int(input()) while t > 0: s=input() print(longestUniqueSubsttr(s)) t -= 1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring. For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases. The first and the only line of each test case contains the string S. Constraints: 1 ≤ T ≤ 100 1 ≤ length of S ≤ 1000Print length of longest substring having such that all characters are unique . Sample Input: 2 abababcdefababcdab gccksfvrgccks Sample Output: 6 7, I have written this Solution Code: // str is input string function longestDistinctSubstr(s) { const mostRecent = new Map(); // Stores the most recent idx let startIdx = 0, res = 0; for (let i = 0; i < s.length; i++) { if (mostRecent.has(s[i]) && mostRecent.get(s[i]) >= startIdx) { res = Math.max(res, i - startIdx); startIdx = mostRecent.get(s[i]) + 1; } mostRecent.set(s[i], i); } return Math.max(res, s.length - startIdx); }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring. For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases. The first and the only line of each test case contains the string S. Constraints: 1 ≤ T ≤ 100 1 ≤ length of S ≤ 1000Print length of longest substring having such that all characters are unique . Sample Input: 2 abababcdefababcdab gccksfvrgccks Sample Output: 6 7, I have written this Solution Code: // C++ program to find the length of the longest substring // without repeating characters #include <bits/stdc++.h> using namespace std; int longestUniqueSubsttr(string str) { int n = str.size(); int res = 0; // result // last index of all characters is initialized // as -1 vector<int> lastIndex(256, -1); // Initialize start of current window int i = 0; // Move end of current window for (int j = 0; j < n; j++) { // Find the last index of str[j] // Update i (starting index of current window) // as maximum of current value of i and last // index plus 1 i = max(i, lastIndex[str[j]] + 1); // Update result if we get a larger window res = max(res, j - i + 1); // Update last index of j. lastIndex[str[j]] = j; } return res; } // Driver code int main() { int t; cin>>t; while(t>0) { t--; string s; cin>>s; int len = longestUniqueSubsttr(s); cout<<len<<endl; } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: def ispangram(str): alphabet = "abcdefghijklmnopqrstuvwxyz" for char in alphabet: if char not in str.lower(): return False return True N = int(input()) arr = [] for i in range(N): arr.append(input()) for i in range(N): if(ispangram(arr[i]) == True): print(1) else: print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: function pangrams(s) { // write code here // do not console.log it // return 1 or 0 let alphabet = "abcdefghijklmnopqrstuvwxyz"; let regex = /\s/g; let lowercase = s.toLowerCase().replace(regex, ""); for(let i = 0; i < alphabet.length; i++){ if(lowercase.indexOf(alphabet[i]) === -1){ return 0; } } return 1; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ String s = sc.next(); int check = 1; int p =0; for(char ch = 'a';ch<='z';ch++){ p=0; for(int i = 0;i<s.length();i++){ if(s.charAt(i)==ch){p=1;} } if(p==0){check=0;} } System.out.println(check); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define pu push_back #define fi first #define se second #define mp make_pair #define int long long #define pii pair<int,int> #define mm (s+e)/2 #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define sz 200000 int A[26],B[26]; signed main() { int t; cin>>t; string p; getline(cin,p); while(t>0) { t--; string s; getline(cin,s); int n=s.size(); memset(A,0,sizeof(A)); int ch=1; for(int i=0;i<n;i++) { int x=s[i]-'a'; if(x>=0 && x<26) { A[x]++; } x=s[i]-'A'; if(x>=0 && x<26) { A[x]++; } } for(int i=0;i<26;i++) { if(A[i]==0) ch=0; } cout<<ch<<endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a Singly linked list and an integer K. Your task is to insert the integer K at the head of the given linked list<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>addElement()</b> that takes head node and the element K as a parameter. Constraints: 1 <=N<= 1000 1 <=K, value<= 1000Return the head of the modified linked listSample Input:- 5 2 1 2 3 4 5 Sample Output: 2 1 2 3 4 5 , I have written this Solution Code: public static Node addElement(Node head,int k) { Node temp =new Node(k); temp.next=head; return temp; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element. Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A. <b>Constraints:</b> 1 <= T <= 100 3 <= N <= 10<sup>6</sup> 1 <= A[i] <= 10<sup>9</sup> <b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input: 3 5 1 4 2 4 5 6 1 3 5 7 9 8 7 11 22 33 44 55 66 77 Sample Output: 5 4 4 9 8 7 77 66 55 <b>Explanation:</b> Testcase 1: [1 4 2 4 5] First max = 5 Second max = 4 Third max = 4, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc =new Scanner(System.in); int T= sc.nextInt(); for(int i=0;i<T;i++){ int arrsize=sc.nextInt(); int max=0,secmax=0,thirdmax=0,j; for(int k=0;k<arrsize;k++){ j=sc.nextInt(); if(j>max){ thirdmax=secmax; secmax=max; max=j; } else if(j>secmax){ thirdmax=secmax; secmax=j; } else if(j>thirdmax){ thirdmax=j; } if(k%10000==0){ System.gc(); } } System.out.println(max+" "+secmax+" "+thirdmax+" "); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element. Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A. <b>Constraints:</b> 1 <= T <= 100 3 <= N <= 10<sup>6</sup> 1 <= A[i] <= 10<sup>9</sup> <b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input: 3 5 1 4 2 4 5 6 1 3 5 7 9 8 7 11 22 33 44 55 66 77 Sample Output: 5 4 4 9 8 7 77 66 55 <b>Explanation:</b> Testcase 1: [1 4 2 4 5] First max = 5 Second max = 4 Third max = 4, I have written this Solution Code: t=int(input()) while t>0: t-=1 n=int(input()) l=list(map(int,input().strip().split())) li=[0,0,0] for i in l: x=i for j in range(0,3): y=min(x,li[j]) li[j]=max(x,li[j]) x=y print(li[0],end=" ") print(li[1],end=" ") print(li[2]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element. Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A. <b>Constraints:</b> 1 <= T <= 100 3 <= N <= 10<sup>6</sup> 1 <= A[i] <= 10<sup>9</sup> <b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input: 3 5 1 4 2 4 5 6 1 3 5 7 9 8 7 11 22 33 44 55 66 77 Sample Output: 5 4 4 9 8 7 77 66 55 <b>Explanation:</b> Testcase 1: [1 4 2 4 5] First max = 5 Second max = 4 Third max = 4, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin>>t; while(t--){ long long n; cin>>n; vector<long> a(n); long ans[3]={0}; long x,y; for(int i=0;i<n;i++){ cin>>a[i]; x=a[i]; for(int j=0;j<3;j++){ y=min(x,ans[j]); ans[j]=max(x,ans[j]); // cout<<ans[j]<<" "; x=y; } } if(ans[1]<ans[0]){ swap(ans[1],ans[0]); } if(ans[2]<ans[1]){ swap(ans[1],ans[2]); } if(ans[1]<ans[0]){ swap(ans[1],ans[0]); } cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element. Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A. <b>Constraints:</b> 1 <= T <= 100 3 <= N <= 10<sup>6</sup> 1 <= A[i] <= 10<sup>9</sup> <b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input: 3 5 1 4 2 4 5 6 1 3 5 7 9 8 7 11 22 33 44 55 66 77 Sample Output: 5 4 4 9 8 7 77 66 55 <b>Explanation:</b> Testcase 1: [1 4 2 4 5] First max = 5 Second max = 4 Third max = 4, I have written this Solution Code: function maxNumbers(arr,n) { // write code here // do not console.log the answer // return the answer as an array of 3 numbers return arr.sort((a,b)=>b-a).slice(0,3) }; , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare 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>Rare()</b> that takes integer N and K as arguments. Constraints:- 1 <= N <= 100000 1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:- 2468 2 Sample Output:- 1 Sample Input:- 234 2 Sample Output:- 0 Explanation : 3 is not divisible by 2., I have written this Solution Code: class Solution { public static int Rare(int n, int k){ while(n>0){ if((n%10)%k!=0){ return 0; } n/=10; } return 1; } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare 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>Rare()</b> that takes integer N and K as arguments. Constraints:- 1 <= N <= 100000 1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:- 2468 2 Sample Output:- 1 Sample Input:- 234 2 Sample Output:- 0 Explanation : 3 is not divisible by 2., I have written this Solution Code: def Rare(N,K): while N>0: if(N%10)%K!=0: return 0 N=N//10 return 1 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare 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>Rare()</b> that takes integer N and K as arguments. Constraints:- 1 <= N <= 100000 1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:- 2468 2 Sample Output:- 1 Sample Input:- 234 2 Sample Output:- 0 Explanation : 3 is not divisible by 2., I have written this Solution Code: int Rare(int n, int k){ while(n){ if((n%10)%k!=0){ return 0; } n/=10; } return 1; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare 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>Rare()</b> that takes integer N and K as arguments. Constraints:- 1 <= N <= 100000 1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:- 2468 2 Sample Output:- 1 Sample Input:- 234 2 Sample Output:- 0 Explanation : 3 is not divisible by 2., I have written this Solution Code: int Rare(int n, int k){ while(n){ if((n%10)%k!=0){ return 0; } n/=10; } return 1; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers your task is to calculate the maximum integer among the given integers.The input contains three integers a, b, and c <b>Constraint:</b> 1<=integers<=10000Print the maximum integer among the given integers.Sample Input:- 2 6 3 Sample Output:- 6 Sample Input:- 48 100 100 Sample Output: 100, I have written this Solution Code: a,b,c=[int(a) for a in input().split()] print(max(a,b,c)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers your task is to calculate the maximum integer among the given integers.The input contains three integers a, b, and c <b>Constraint:</b> 1<=integers<=10000Print the maximum integer among the given integers.Sample Input:- 2 6 3 Sample Output:- 6 Sample Input:- 48 100 100 Sample Output: 100, 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 p = scanner.nextInt(); int tm = scanner.nextInt(); int r = scanner.nextInt(); int intrst = MaxInteger(p,tm,r); System.out.println(intrst); } static int MaxInteger(int a ,int b, int c){ if(a>=b && a>=c){return a;} if(b>=a && b>=c){return b;} return c;} }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: static void pattern(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ System.out.print(j + " "); } System.out.println(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: void patternPrinting(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ printf("%d ",j); } printf("\n"); } } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: function pattern(n) { // write code herenum for(let i = 1;i<=n;i++){ let str = '' for(let k = 1; k <= i;k++){ if(k === 1) { str += `${k}` }else{ str += ` ${k}` } } console.log(str) } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: void patternPrinting(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ printf("%d ",j); } printf("\n"); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: def patternPrinting(n): for i in range(1,n+1): for j in range (1,i+1): print(j,end=' ') print() , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable