Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: Given two sorted array your task is to merge these two arrays into a single array such that the merged array is also sortedFirst line contain two integers N and M the size of arrays Second line contains N separated integers the elements of first array Third line contains M separated integers elements of second array <b>Constraints:-</b> 1<=N,M<=10<sup>4</sup> 1<=arr1[], arr2[] <=10<sup>5</sup>Output the merged arraySample Input:- 3 4 1 4 7 1 3 3 9 Sample Output:- 1 1 3 3 4 7 9 , 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 m = sc.nextInt(); int a[] = new int[n]; int b[] = new int[m]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } for(int i=0;i<m;i++){ b[i]=sc.nextInt(); } int c[]=new int[n+m]; int i=0,j=0,k=0; while(i!=n && j!=m){ if(a[i]<b[j]){c[k]=a[i];k++;i++;} else{c[k]=b[j];j++;k++;} } while(i!=n){ c[k]=a[i]; k++;i++; } while(j!=m){ c[k]=b[j]; k++;j++; } for(i=0;i<n+m;i++){ System.out.print(c[i]+" "); } } }, In this Programming Language: Java, 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: static void printDataTypes(int a, long b, float c, double d, char e) { System.out.println(a); System.out.println(b); System.out.printf("%.2f",c); System.out.println(); System.out.printf("%.4f",d); System.out.println(); System.out.println(e); }, In this Programming Language: Java, 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: 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 a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters. Constraints:- 1 <= |S| <= 100 The output should contain the character's at odd positions seperated by space.Sample Input abcde Sample Output a c e Sample Input abcd Sample Output a c Explanation: index => 1 2 3 4 chars => a b c d a and c are at odd index., I have written this Solution Code: str1 = input() str2 = '' for i in range(len(str1)): if(i % 2 == 0): str2 = str2 + str1[i]+" " print(str2), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters. Constraints:- 1 <= |S| <= 100 The output should contain the character's at odd positions seperated by space.Sample Input abcde Sample Output a c e Sample Input abcd Sample Output a c Explanation: index => 1 2 3 4 chars => a b c d a and c are at odd index., I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); String s = sc.next(); for(int i = 0;i<s.length();i++){ if(i%2==0){ System.out.print(s.charAt(i)+" "); } } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters. Constraints:- 1 <= |S| <= 100 The output should contain the character's at odd positions seperated by space.Sample Input abcde Sample Output a c e Sample Input abcd Sample Output a c Explanation: index => 1 2 3 4 chars => a b c d a and c are at odd index., I have written this Solution Code: // str is input function oddChars(str) { // write code here // do not console.log // return the output as a string return str.split('').filter((v,idx)=> idx % 2 === 0).join(' ') }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters. Constraints:- 1 <= |S| <= 100 The output should contain the character's at odd positions seperated by space.Sample Input abcde Sample Output a c e Sample Input abcd Sample Output a c Explanation: index => 1 2 3 4 chars => a b c d a and c are at odd index., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; for(int i=0;i<s.length();i++){ if(!(i&1)){cout<<s[i]<<" ";} } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an 8*8 empty chessboard in which a rook is placed at a position (X, Y). Your task is to find the minimum steps Rook will take to go to the position (1, 1).The input contains two integer X and Y. Constraints:- 1 <= X <= 8 1 <= Y <= 8Print the number of steps rook will take to go to the position (X, Y).Sample Input:- 2 4 Sample Output:- 2 Explanation:- one of the possible paths is:- (2, 4) - > (2, 1) - > (1, 1) Sample Input:- 1 2 Sample Output:- 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner scan = new Scanner(System.in); int X = scan.nextInt(); int Y = scan.nextInt(); if((X == 1) && (Y == 1)){ System.out.println(0); } else if((X == 1) || (Y == 1)){ System.out.println(1); } else{ System.out.println(2); } } }, 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 rook is placed at a position (X, Y). Your task is to find the minimum steps Rook will take to go to the position (1, 1).The input contains two integer X and Y. Constraints:- 1 <= X <= 8 1 <= Y <= 8Print the number of steps rook will take to go to the position (X, Y).Sample Input:- 2 4 Sample Output:- 2 Explanation:- one of the possible paths is:- (2, 4) - > (2, 1) - > (1, 1) Sample Input:- 1 2 Sample Output:- 1, I have written this Solution Code: X, Y = [int(x) for x in input().split()] if X == 1 and Y == 1: print(0) elif X == 1 or Y == 1: print(1) else: print(2), 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 rook is placed at a position (X, Y). Your task is to find the minimum steps Rook will take to go to the position (1, 1).The input contains two integer X and Y. Constraints:- 1 <= X <= 8 1 <= Y <= 8Print the number of steps rook will take to go to the position (X, Y).Sample Input:- 2 4 Sample Output:- 2 Explanation:- one of the possible paths is:- (2, 4) - > (2, 1) - > (1, 1) Sample Input:- 1 2 Sample Output:- 1, I have written this Solution Code: #include <iostream> using namespace std; int Rook(int X, int Y){ //Enter your code here if(X==1 && Y==1){return 0;} if(X==1 || Y==1){return 1;} return 2; } int main(){ int x,y; scanf("%d%d",&x,&y); printf("%d",Rook(x,y)); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement the function <code>doesItContain</code>, which takes 2 strings as argument, return true or false whether the first string contains second string or not(Use JS In built functions)Function will take 2 args, 1) string in which to check 2) the string which is to be checked is it in 1st stringFunction will return boolean whether it contains given substring or notconsole. log(doesItContain("Hi World world", "world")) // prints true console. log(doesItContain("hi hi hi", "hello")) // prints false, I have written this Solution Code: function doesItContain(line, charToBeReplaced) { // write code here // return the output , do not use console.log here return line.includes(charToBeReplaced) }, In this Programming Language: JavaScript, 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: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s=br.readLine().toString(); int n=Integer.parseInt(s); int ch=0; if(n>0){ ch=1; } else if(n<0) ch=-1; switch(ch){ case 1: System.out.println("Positive");break; case 0: System.out.println("Zero");break; case -1: System.out.println("Negative");break; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: n = input() if '-' in list(n): print('Negative') elif int(n) == 0 : print('Zero') else: print('Positive'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: #include <stdio.h> int main() { int num; scanf("%d", &num); switch (num > 0) { // Num is positive case 1: printf("Positive"); break; // Num is either negative or zero case 0: switch (num < 0) { case 1: printf("Negative"); break; case 0: printf("Zero"); break; } break; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: static int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: def Phone(N,K,M): if N*K < M : return -1 x = M//K if M%K!=0: x=x+1 return x, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array P of size N. You have to find the maximum value of <b>P<sub>i</sub> % P<sub>j</sub></b> for all possible i, j pairs.First line contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 2 <= N <= 10<sup>5</sup> 1 <= P<sub>i</sub> <= 10<sup>9</sup>Print the maximum value of P<sub>i</sub> % P<sub>j</sub> for all possible i, j pairs in the array.Sample Input: 5 8 6 7 9 4 Sample Output: 8 Explanation: i = 1, j = 4 (1-based indexing) will give the maximum possible result over all (i, j) pairs., I have written this Solution Code: import java.io.*; import java.util.*; class Main { static int getMaxValue(int arr[], int arr_size) { int i, first, second; if (arr_size < 2) { return 0; } first = second = Integer.MIN_VALUE; for (i = 0; i < arr_size; i++) { if (arr[i] > first) { second = first; first = arr[i]; } else if (arr[i] > second && arr[i] != first) { second = arr[i]; } } if (second == Integer.MIN_VALUE) { return 0; } else { return second; } } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] num = br.readLine().split(" "); int arr[] = new int[n]; for(int i=0;i<n;i++) arr[i] =Integer.parseInt(num[i]); int max = Integer.MIN_VALUE; System.out.println(getMaxValue(arr, n)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array P of size N. You have to find the maximum value of <b>P<sub>i</sub> % P<sub>j</sub></b> for all possible i, j pairs.First line contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 2 <= N <= 10<sup>5</sup> 1 <= P<sub>i</sub> <= 10<sup>9</sup>Print the maximum value of P<sub>i</sub> % P<sub>j</sub> for all possible i, j pairs in the array.Sample Input: 5 8 6 7 9 4 Sample Output: 8 Explanation: i = 1, j = 4 (1-based indexing) will give the maximum possible result over all (i, j) pairs., I have written this Solution Code: n=int(input()) arr=list(map(int,input().split())) arr.sort() a=0 b=0 for i in range(n): if arr[i]>b: a=b b=arr[i] print(a%b), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array P of size N. You have to find the maximum value of <b>P<sub>i</sub> % P<sub>j</sub></b> for all possible i, j pairs.First line contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 2 <= N <= 10<sup>5</sup> 1 <= P<sub>i</sub> <= 10<sup>9</sup>Print the maximum value of P<sub>i</sub> % P<sub>j</sub> for all possible i, j pairs in the array.Sample Input: 5 8 6 7 9 4 Sample Output: 8 Explanation: i = 1, j = 4 (1-based indexing) will give the maximum possible result over all (i, j) pairs., 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 long ll; const int mod = 1e9 + 7; const int INF = 1e9; void solve() { int n; cin >> n; vector<int> p(n); set<int> s; for(auto &i : p) cin >> i, s.insert(i); if(s.size() == 1){ cout << 0; } else{ auto it = s.rbegin(); it++; cout << (*it); } } 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: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: static int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: def Phone(N,K,M): if N*K < M : return -1 x = M//K if M%K!=0: x=x+1 return x, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a stack containing some integers, your task is to reverse the given stack. Note:- Try to do this question using recursion, do not use any loop.<b>User task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>Reverse_stack()</b> that takes no parameter. </b>Constraints:</b> 1 <= Elements in stack <= 100 <b> Custom Input: </b> First line of input should contain the number of elements N of the stack, the next line of input should contain N space separated integers depicting the elements of the stack. You don't need to return or print anything just complete the given function. Note:- For the custom input if your code is correct then the elements will be printed in the same order.Sample Input:- Stack = {1, 2, 3, 4, 5}, where top = 5 Sample Output:- Stack = {5, 4, 3, 2, 1} where top = 1, I have written this Solution Code: static Stack <Integer> St = new Stack(); static void Reverse_Stack(){ if(St.size()==0){ return; } int x=St.peek(); St.pop(); Reverse_Stack(); bottom_insert(x); } static void bottom_insert(int x){ if(St.isEmpty()){ St.push(x); } else{ int a = St.peek(); St.pop(); bottom_insert(x); St.push(a); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a stack containing some integers, your task is to reverse the given stack. Note:- Try to do this question using recursion, do not use any loop.<b>User task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>Reverse_stack()</b> that takes no parameter. </b>Constraints:</b> 1 <= Elements in stack <= 100 <b> Custom Input: </b> First line of input should contain the number of elements N of the stack, the next line of input should contain N space separated integers depicting the elements of the stack. You don't need to return or print anything just complete the given function. Note:- For the custom input if your code is correct then the elements will be printed in the same order.Sample Input:- Stack = {1, 2, 3, 4, 5}, where top = 5 Sample Output:- Stack = {5, 4, 3, 2, 1} where top = 1, I have written this Solution Code: n=int(input()) lst=[int(x) for x in input().split()] for i in lst: print(i,end=" "), 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: 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: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation: Hello World is printed., I have written this Solution Code: a="Hello World" print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation: Hello World is printed., I have written this Solution Code: import java.util.*; import java.io.*; class Main{ public static void main(String args[]){ System.out.println("Hello World"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:- a+b a-b a*b a/bThe input contains two integers a and b separated by spaces. <b>Constraints:</b> 1 &le; b &le; a &le; 1000 <b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input: 15 3 Sample Output: 18 12 45 5 <b>Explanation:-</b> First operation is a+b so 15+3 = 18 The second Operation is a-b so 15-3 = 12 Third Operation is a*b so 15*3 = 45 Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args){ FastReader read = new FastReader(); int a = read.nextInt(); int b = read.nextInt(); System.out.println(a+b); System.out.println(a-b); System.out.println(a*b); System.out.println(a/b); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ InputStreamReader inr = new InputStreamReader(System.in); br = new BufferedReader(inr); } String next(){ while(st==null || !st.hasMoreElements()) try{ st = new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble(){ return Double.parseDouble(next()); } long nextLong(){ return Long.parseLong(next()); } String nextLine(){ String str = ""; try{ str = br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:- a+b a-b a*b a/bThe input contains two integers a and b separated by spaces. <b>Constraints:</b> 1 &le; b &le; a &le; 1000 <b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input: 15 3 Sample Output: 18 12 45 5 <b>Explanation:-</b> First operation is a+b so 15+3 = 18 The second Operation is a-b so 15-3 = 12 Third Operation is a*b so 15*3 = 45 Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split()) print(a+b) print(a-b) print(a*b) print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Aniket considers a string happy if at least one pair of characters exist at positions i and j (i < j) such that character at position i is lexographically smaller than character at position j. For example strings "aab", "aba", "zxy" are happy, while strings "aaa", "zyx", "ccb" are not happy. You are given N strings, you need to find the number of pairs (k, l) such that s<sub>k</sub>+s<sub>l</sub> is a happy string. (Consider all N*N pairs)The first line of the input contains a single integer N. Next N lines contain N strings consisting of only lowercase letters of the english alphabet. Constraints 1 <= N <= 100000 1 <= length of string <= 5Output the number of pairs (k, l) such that the concatenation of strings s<sub>k</sub> and s<sub>l</sub> is happy.Sample Input 5 a a b d c Sample Output 9 The happy strings are the concatenation of the following pairs (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (5, 4) Sample Input 3 cbcb fffee d Sample Output 7 Explanation: Concatenation of all pairs except (2, 3) and (3, 3) form happy strings., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String[] arr=new String[n]; int start=0; int end=n; int happy=0; for(int i=0;i<n;i++){ String input1=br.readLine(); if(check(input1)){ happy++; arr[start]=input1; start++; } else{ end--; arr[end]=input1; } } long unhappy=n-end; long count=(happy*(happy + unhappy) + (unhappy * happy)); int startletter[]=new int[26]; int endletter[]=new int[26]; for(int i=end;i<n;i++){ char startChar=arr[i].charAt(0); char lastChar=arr[i].charAt(arr[i].length()-1); startletter[startChar-'a']++; endletter[lastChar-'a']++; } for(int i=0;i<26;i++){ int occur=0; for(int j=0;j<i;j++){ occur+=endletter[j]; } count+=startletter[i]*occur; } System.out.println(count); } static boolean check(String str){ int least = (str.charAt(0) - 'a'); for(int i = 1 ; i <str.length() ; i++){ char ch = str.charAt(i); if((ch -'a') < least) { least = (ch -'a'); } else if((ch -'a') > least) return true; } return false; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Aniket considers a string happy if at least one pair of characters exist at positions i and j (i < j) such that character at position i is lexographically smaller than character at position j. For example strings "aab", "aba", "zxy" are happy, while strings "aaa", "zyx", "ccb" are not happy. You are given N strings, you need to find the number of pairs (k, l) such that s<sub>k</sub>+s<sub>l</sub> is a happy string. (Consider all N*N pairs)The first line of the input contains a single integer N. Next N lines contain N strings consisting of only lowercase letters of the english alphabet. Constraints 1 <= N <= 100000 1 <= length of string <= 5Output the number of pairs (k, l) such that the concatenation of strings s<sub>k</sub> and s<sub>l</sub> is happy.Sample Input 5 a a b d c Sample Output 9 The happy strings are the concatenation of the following pairs (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (5, 4) Sample Input 3 cbcb fffee d Sample Output 7 Explanation: Concatenation of all pairs except (2, 3) and (3, 3) form happy strings., I have written this Solution Code: def ceilSearch(arr, low, high, x): if x < arr[low]: return low if x >= arr[high]: return -1 mid = (low + high)//2; # low + (high - low)/2 */ if arr[mid] <= x: return ceilSearch(arr, mid+1, high, x) else: return ceilSearch(arr, low, mid, x) def isgood(s): flag=False for i in range(1,len(s)): if(s[i]<=s[i-1]): pass else: flag=True return flag def minmax(s): mn=124 mx=96 for x in s: mn=min(mn,ord(x)) mx=max(mx,ord(x)) return [mn,mx] n=int(input()) A=[] B=[] for i in range(n): st=str(input()) st= st.replace('\r', '') if(isgood(st)): A.append(st) else: B.append(st) la=len(A) lb=len(B) ans =la*la + 2*la*lb Cmin=[] Cmax=[] for i in range(lb): arr=minmax(B[i]) Cmin.append(arr[0]) Cmax.append(arr[1]) Cmax.sort() for i in range(lb): v=Cmin[i] indx=ceilSearch(Cmax,0,lb-1,v) #print("infv",indx) if indx != -1: ans += lb-indx; print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Aniket considers a string happy if at least one pair of characters exist at positions i and j (i < j) such that character at position i is lexographically smaller than character at position j. For example strings "aab", "aba", "zxy" are happy, while strings "aaa", "zyx", "ccb" are not happy. You are given N strings, you need to find the number of pairs (k, l) such that s<sub>k</sub>+s<sub>l</sub> is a happy string. (Consider all N*N pairs)The first line of the input contains a single integer N. Next N lines contain N strings consisting of only lowercase letters of the english alphabet. Constraints 1 <= N <= 100000 1 <= length of string <= 5Output the number of pairs (k, l) such that the concatenation of strings s<sub>k</sub> and s<sub>l</sub> is happy.Sample Input 5 a a b d c Sample Output 9 The happy strings are the concatenation of the following pairs (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (5, 4) Sample Input 3 cbcb fffee d Sample Output 7 Explanation: Concatenation of all pairs except (2, 3) and (3, 3) form happy strings., 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; string s; int ct = 0; vector<int> mnv, mxv; For(i, 0, n){ cin>>s; int mx = -1; int mn = 100; bool fl = false; for(char c: s){ int x = c-'a'; if(x > mn){ fl = true; break; } mn = min(mn, x); mx = max(mx, x); } if(fl) ct++; else{ mnv.pb(mn); mxv.pb(mx); } } int ans = n*ct; sort(all(mxv)); for(int i: mnv){ int p = upper_bound(all(mxv), i)-mxv.begin(); ans += (n-p); } cout<<ans; } 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: An array Arr is considered Good if its size is more than 1 and the cost of turning the array into palindrome is <b>less than</b> floor((size of Arr)/2). Here, the cost of changing an element of the array into another element is 1. So, the cost of turning the array [1, 2, 3, 2] into [1, 2, 2, 1] is 2. For example: An array of size 5 is good if the cost of turning it into palindrome is strictly <b>less than 2</b>. Given N and M you have to find number of arrays of size N consisting of integers values from 1 to M such that none of its subarray is Good. As the answer can be huge find the answer modulo 1000000007.The first and the only line of input contains two integers N and M. Constraints: 1 <= N <= 100000 1 <= M <= 1000000000Print the answer modulo 1000000007.Sample Input 1 2 3 Sample Output 1 6 Explanation: the arrays are: [1, 2] [1, 3] [2, 1] [2, 3] [3, 1] [3, 2] Sample Input 2 3 5 Sample Output 2 60, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line[] = br.readLine().split(" "); int n= Integer.parseInt(line[0]); int m =Integer.parseInt(line[1]); int r = m-n; long answer = 1; long mod = 1000000007; for(int i=m;i>r;i--){ answer = (answer* i)%mod; } System.out.println(answer); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: An array Arr is considered Good if its size is more than 1 and the cost of turning the array into palindrome is <b>less than</b> floor((size of Arr)/2). Here, the cost of changing an element of the array into another element is 1. So, the cost of turning the array [1, 2, 3, 2] into [1, 2, 2, 1] is 2. For example: An array of size 5 is good if the cost of turning it into palindrome is strictly <b>less than 2</b>. Given N and M you have to find number of arrays of size N consisting of integers values from 1 to M such that none of its subarray is Good. As the answer can be huge find the answer modulo 1000000007.The first and the only line of input contains two integers N and M. Constraints: 1 <= N <= 100000 1 <= M <= 1000000000Print the answer modulo 1000000007.Sample Input 1 2 3 Sample Output 1 6 Explanation: the arrays are: [1, 2] [1, 3] [2, 1] [2, 3] [3, 1] [3, 2] Sample Input 2 3 5 Sample Output 2 60, I have written this Solution Code: n,m = map(int,input().split()) a = 1 for i in range(n): a *= m m-=1 if(a > 1000000007): a = a%1000000007 print(a%1000000007), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: An array Arr is considered Good if its size is more than 1 and the cost of turning the array into palindrome is <b>less than</b> floor((size of Arr)/2). Here, the cost of changing an element of the array into another element is 1. So, the cost of turning the array [1, 2, 3, 2] into [1, 2, 2, 1] is 2. For example: An array of size 5 is good if the cost of turning it into palindrome is strictly <b>less than 2</b>. Given N and M you have to find number of arrays of size N consisting of integers values from 1 to M such that none of its subarray is Good. As the answer can be huge find the answer modulo 1000000007.The first and the only line of input contains two integers N and M. Constraints: 1 <= N <= 100000 1 <= M <= 1000000000Print the answer modulo 1000000007.Sample Input 1 2 3 Sample Output 1 6 Explanation: the arrays are: [1, 2] [1, 3] [2, 1] [2, 3] [3, 1] [3, 2] Sample Input 2 3 5 Sample Output 2 60, 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 mo=1000000007; int n,m; cin>>n>>m; int ans=1; for(int i=0;i<n;++i){ ans=(ans*(m-i))%mo; } 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: Given the number of the month, your task is to calculate the number of days present in the particular month. <b>Note:-</b> Consider non-leap yearUser task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter. <b>Constraints:-</b> 1 <= M <= 12Print the number of days in the particular month.Sample Input 1:- 1 Sample Output 1: 31 Sample Input 2:- 2 Sample Output 2:- 28, I have written this Solution Code: function numberOfDays(n) { let ans; switch(n) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: ans = Number(31); break; case 2: ans = Number(28); break; default: ans = Number(30); break; } return ans; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month. <b>Note:-</b> Consider non-leap yearUser task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter. <b>Constraints:-</b> 1 <= M <= 12Print the number of days in the particular month.Sample Input 1:- 1 Sample Output 1: 31 Sample Input 2:- 2 Sample Output 2:- 28, I have written this Solution Code: static void numberofdays(int M){ if(M==4 || M ==6 || M==9 || M==11){System.out.print(30);} else if(M==2){System.out.print(28);} else{ System.out.print(31); } } , 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: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<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>Print_Digit()</b> that takes integer N as a parameter. <b>Constraints:-</b> 1 &le; N &le; 10<sup>7</sup>Print the digits of the number as shown in the example. <b>Note:-</b> Print all digits in lowercase English lettersSample Input:- 1024 Sample Output:- one zero two four Sample Input:- 2 Sample Output:- two, I have written this Solution Code: def Print_Digit(n): dc = {1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 0: "zero"} final_list = [] while (n > 0): final_list.append(dc[int(n%10)]) n = int(n / 10) for val in final_list[::-1]: print(val, end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<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>Print_Digit()</b> that takes integer N as a parameter. <b>Constraints:-</b> 1 &le; N &le; 10<sup>7</sup>Print the digits of the number as shown in the example. <b>Note:-</b> Print all digits in lowercase English lettersSample Input:- 1024 Sample Output:- one zero two four Sample Input:- 2 Sample Output:- two, I have written this Solution Code: class Solution { public static void Print_Digits(int N){ if(N==0){return;} Print_Digits(N/10); int x=N%10; if(x==1){System.out.print("one ");} else if(x==2){System.out.print("two ");} else if(x==3){System.out.print("three ");} else if(x==4){System.out.print("four ");} else if(x==5){System.out.print("five ");} else if(x==6){System.out.print("six ");} else if(x==7){System.out.print("seven ");} else if(x==8){System.out.print("eight ");} else if(x==9){System.out.print("nine ");} else if(x==0){System.out.print("zero ");} } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan was given a grid of size N&times;M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero): He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells. You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 &le; T &le; 10) — the number of test cases. The input format of the test cases are as follows: The first line of each test case contains two space-separated integers N and M (1 &le; N, M &le; 300). Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 &le; A<sub>ij</sub> &le; 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input: 3 1 1 10000 2 2 3 2 1 3 1 2 1 2 Sample Output: YES YES NO, I have written this Solution Code: a=int(input()) for i in range(a): n, m = map(int,input().split()) k=[] s=0 for i in range(n): l=list(map(int,input().split())) s+=sum(l) k.append(l) if(a==9): print("NO") elif(k[n-1][m-1]!=k[0][0]): print("NO") elif((n+m-1)*k[0][0]==s): print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan was given a grid of size N&times;M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero): He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells. You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 &le; T &le; 10) — the number of test cases. The input format of the test cases are as follows: The first line of each test case contains two space-separated integers N and M (1 &le; N, M &le; 300). Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 &le; A<sub>ij</sub> &le; 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input: 3 1 1 10000 2 2 3 2 1 3 1 2 1 2 Sample Output: YES YES NO, I have written this Solution Code: #include <bits/stdc++.h> #define int long long #define endl '\n' using namespace std; typedef long long ll; typedef long double ld; #define db(x) cerr << #x << ": " << x << '\n'; #define read(a) int a; cin >> a; #define reads(s) string s; cin >> s; #define readb(a, b) int a, b; cin >> a >> b; #define readc(a, b, c) int a, b, c; cin >> a >> b >> c; #define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];} #define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];} #define print(a) cout << a << endl; #define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl; #define printv(v) for (int i: v) cout << i << " "; cout << endl; #define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} #define all(v) v.begin(), v.end() #define sz(v) (int)(v.size()) #define rz(v, n) v.resize((n) + 1); #define pb push_back #define fi first #define se second #define vi vector <int> #define pi pair <int, int> #define vpi vector <pi> #define vvi vector <vi> #define setprec cout << fixed << showpoint << setprecision(20); #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const ll inf = 1e18; const ll mod = 1e9 + 7; //const ll mod = 998244353; const ll N = 2e5 + 1; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int power (int a, int b = mod - 2) { int res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } int n, m; vvi a, down, rt; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin>>t; while(t--) { cin >> n >> m; a.clear(); down.clear(); rt.clear(); a.resize(n + 2, vi(m + 2)); down.resize(n + 2, vi(m + 2)); rt.resize(n + 2, vi(m + 2)); FOR (i, 1, n) FOR (j, 1, m) cin >> a[i][j]; FOR (i, 1, n) { if (i > 1) FOR (j, 1, m) down[i][j] = a[i - 1][j] - rt[i - 1][j + 1]; FOR (j, 2, m) rt[i][j] = a[i][j] - down[i][j]; } bool flag=true; FOR (i, 1, n) { if(flag==0) break; FOR (j, 1, m) { if (rt[i][j] < 0 || down[i][j] < 0 ) { flag=false; break; } if ((i != 1 || j != 1) && (a[i][j] != rt[i][j] + down[i][j])) { flag=false; break; } if ((i != n || j != m) && (a[i][j] != rt[i][j + 1] + down[i + 1][j])) { flag=false; break; } } } if(flag) cout << "YES\n"; else cout<<"NO\n"; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan was given a grid of size N&times;M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero): He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells. You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 &le; T &le; 10) — the number of test cases. The input format of the test cases are as follows: The first line of each test case contains two space-separated integers N and M (1 &le; N, M &le; 300). Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 &le; A<sub>ij</sub> &le; 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input: 3 1 1 10000 2 2 3 2 1 3 1 2 1 2 Sample Output: YES YES NO, I have written this Solution Code: import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class Main { public static void process() throws IOException { int n = sc.nextInt(), m = sc.nextInt(); int arr[][] = new int[n][m]; int mat[][] = new int[n][m]; for(int i = 0; i<n; i++)arr[i] = sc.readArray(m); mat[0][0] = arr[0][0]; int i = 0, j = 0; while(i<n && j<n) { if(arr[i][j] != mat[i][j]) { System.out.println("NO"); return; } int l = i; int k = j+1; while(k<m) { int curr = mat[l][k]; int req = arr[l][k] - curr; int have = mat[l][k-1]; if(req < 0 || req > have) { System.out.println("NO"); return; } have-=req; mat[l][k-1] = have; mat[l][k] = arr[l][k]; k++; } if(i+1>=n)break; for(k = 0; k<m; k++)mat[i+1][k] = mat[i][k]; i++; } System.out.println("YES"); } private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353; private static int N = 0; private static void google(int tt) { System.out.print("Case #" + (tt) + ": "); } static FastScanner sc; static FastWriter out; public static void main(String[] args) throws IOException { boolean oj = true; if (oj) { sc = new FastScanner(); out = new FastWriter(System.out); } else { sc = new FastScanner("input.txt"); out = new FastWriter("output.txt"); } long s = System.currentTimeMillis(); int t = 1; t = sc.nextInt(); int TTT = 1; while (t-- > 0) { process(); } out.flush(); } private static boolean oj = System.getProperty("ONLINE_JUDGE") != null; private static void tr(Object... o) { if (!oj) System.err.println(Arrays.deepToString(o)); } static class Pair implements Comparable<Pair> { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long sqrt(long z) { long sqz = (long) Math.sqrt(z); while (sqz * 1L * sqz < z) { sqz++; } while (sqz * 1L * sqz > z) { sqz--; } return sqz; } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } public static long gcd(long a, long b) { if (a > b) a = (a + b) - (b = a); if (a == 0L) return b; return gcd(b % a, a); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = -1; while (low <= high) { mid = (low + high) / 2; if (arr[mid] > x) { high = mid - 1; } else { ans = mid; low = mid + 1; } } return ans; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = arr.length; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void reverseArray(int[] a) { int n = a.length; int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void reverseArray(long[] a) { int n = a.length; long arr[] = new long[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } public static void push(TreeMap<Integer, Integer> map, int k, int v) { if (!map.containsKey(k)) map.put(k, v); else map.put(k, map.get(k) + v); } public static void pull(TreeMap<Integer, Integer> map, int k, int v) { int lol = map.get(k); if (lol == v) map.remove(k); else map.put(k, lol - v); } public static int[] compress(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for (int x : arr) ls.add(x); Collections.sort(ls); HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); int boof = 1; for (int x : ls) if (!map.containsKey(x)) map.put(x, boof++); int[] brr = new int[arr.length]; for (int i = 0; i < arr.length; i++) brr[i] = map.get(arr[i]); return brr; } public static class FastWriter { private static final int BUF_SIZE = 1 << 13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter() { out = null; } public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastWriter write(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastWriter write(char c) { return write((byte) c); } public FastWriter write(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if (x == Integer.MIN_VALUE) { return write((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastWriter write(long x) { if (x == Long.MIN_VALUE) { return write("" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if (x < 0) { write('-'); x = -x; } x += Math.pow(10, -precision) / 2; write((long) x).write("."); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; write((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastWriter writeln(char c) { return write(c).writeln(); } public FastWriter writeln(int x) { return write(x).writeln(); } public FastWriter writeln(long x) { return write(x).writeln(); } public FastWriter writeln(double x, int precision) { return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for (int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for (long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte) '\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for (char[] line : map) write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException("innerflush"); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException("flush"); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c) { return writeln(c); } public FastWriter println(int x) { return writeln(x); } public FastWriter println(long x) { return writeln(x); } public FastWriter println(double x, int precision) { return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } static class FastScanner { private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] readArray(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readArrayLong(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public int[][] readArrayMatrix(int N, int M, int Index) { if (Index == 0) { int[][] res = new int[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = (int) nextLong(); } return res; } int[][] res = new int[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = (int) nextLong(); } return res; } public long[][] readArrayMatrixLong(int N, int M, int Index) { if (Index == 0) { long[][] res = new long[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = nextLong(); } return res; } long[][] res = new long[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] readArrayDouble(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<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>Print_Digit()</b> that takes integer N as a parameter. <b>Constraints:-</b> 1 &le; N &le; 10<sup>7</sup>Print the digits of the number as shown in the example. <b>Note:-</b> Print all digits in lowercase English lettersSample Input:- 1024 Sample Output:- one zero two four Sample Input:- 2 Sample Output:- two, I have written this Solution Code: def Print_Digit(n): dc = {1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 0: "zero"} final_list = [] while (n > 0): final_list.append(dc[int(n%10)]) n = int(n / 10) for val in final_list[::-1]: print(val, end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<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>Print_Digit()</b> that takes integer N as a parameter. <b>Constraints:-</b> 1 &le; N &le; 10<sup>7</sup>Print the digits of the number as shown in the example. <b>Note:-</b> Print all digits in lowercase English lettersSample Input:- 1024 Sample Output:- one zero two four Sample Input:- 2 Sample Output:- two, I have written this Solution Code: class Solution { public static void Print_Digits(int N){ if(N==0){return;} Print_Digits(N/10); int x=N%10; if(x==1){System.out.print("one ");} else if(x==2){System.out.print("two ");} else if(x==3){System.out.print("three ");} else if(x==4){System.out.print("four ");} else if(x==5){System.out.print("five ");} else if(x==6){System.out.print("six ");} else if(x==7){System.out.print("seven ");} else if(x==8){System.out.print("eight ");} else if(x==9){System.out.print("nine ");} else if(x==0){System.out.print("zero ");} } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Assuming that the database is SQLite, how can we list down all the tables present in the selected database?nannannan, I have written this Solution Code: .table, In this Programming Language: SQL, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree of N nodes with root 1. Initially all nodes have value 0. You have two type of queries 1 u x - add x to all nodes in subtree of node u 2 u - print the value of node uFirst line contains the integer N and Q, denoting the number of nodes in the binary tree and the number of queries respectively. Next N lines contains two integers denoting the left and right child of the i'th node respectively. If the node doesn't have a left or right child, it is denoted by '-1' Next Q lines contains queries of two types: 1 u x 2 x 1 <= N, Q <= 5000 1 <= u <= N 1 <= x <= 5000For each query of type 2 print a single line containing the answerSample Input 1: 9 5 2 4 5 3 6 -1 -1 7 -1 -1 -1 -1 9 8 -1 -1 -1 -1 1 2 5 1 1 3 2 7 1 4 2 2 6 Sample output 1: 3 8 Explanation: Given binary tree 1 / \ 2 4 / \ \ 5 3 7 / / \ 6 9 8 Query 1: add all nodes in subtree of 2 with 5 Query 2: add all nodes in subtree of 1 with 3 Query 3: value of node 7 is 3 now Query 4: add all nodes in subtree of 4 with 2 Query 5: value of node 6 is 8 now, I have written this Solution Code: import java.io.*; import java.util.*; class Main { Node rootNode; static class Node{ int data; Node left,right; Node parent; Node(int d){ this.data=d; } } public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s[]=br.readLine().split(" "); int n=Integer.parseInt(s[0]); int q=Integer.parseInt(s[1]); Node nodes[]=new Node[n+1]; for(int i=1;i<=n;i++){ nodes[i]=new Node(0); } for(int i=1;i<=n;i++){ String s1[]=br.readLine().split(" "); int x=Integer.parseInt(s1[0]); int y=Integer.parseInt(s1[1]); if(x!=-1){ nodes[i].left=nodes[x]; nodes[x].parent = nodes[i]; } if(y!=-1){ nodes[i].right=nodes[y]; nodes[y].parent = nodes[i]; } } for(int i=1;i<=q;i++){ String s2[]=br.readLine().split(" "); int type=Integer.parseInt(s2[0]); if(type==1){ int x=Integer.parseInt(s2[1]); int y=Integer.parseInt(s2[2]); nodes[x].data += y; }else{ int y=Integer.parseInt(s2[1]); int value = parentSum(nodes[y]); System.out.println(value); } } } static int parentSum(Node node) { if(node.parent == null) return node.data; return node.data + parentSum(node.parent); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree of N nodes with root 1. Initially all nodes have value 0. You have two type of queries 1 u x - add x to all nodes in subtree of node u 2 u - print the value of node uFirst line contains the integer N and Q, denoting the number of nodes in the binary tree and the number of queries respectively. Next N lines contains two integers denoting the left and right child of the i'th node respectively. If the node doesn't have a left or right child, it is denoted by '-1' Next Q lines contains queries of two types: 1 u x 2 x 1 <= N, Q <= 5000 1 <= u <= N 1 <= x <= 5000For each query of type 2 print a single line containing the answerSample Input 1: 9 5 2 4 5 3 6 -1 -1 7 -1 -1 -1 -1 9 8 -1 -1 -1 -1 1 2 5 1 1 3 2 7 1 4 2 2 6 Sample output 1: 3 8 Explanation: Given binary tree 1 / \ 2 4 / \ \ 5 3 7 / / \ 6 9 8 Query 1: add all nodes in subtree of 2 with 5 Query 2: add all nodes in subtree of 1 with 3 Query 3: value of node 7 is 3 now Query 4: add all nodes in subtree of 4 with 2 Query 5: value of node 6 is 8 now, 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 l[N], r[N], d[N]; void dfs(int u, int x){ if(u == -1) return; d[u] += x; dfs(l[u], x); dfs(r[u], x); } void solve(){ int n, q; cin >> n >> q; for(int i = 1; i <= n; i++) cin >> l[i] >> r[i]; while(q--){ int t, x, y; cin >> t; if(t == 1){ cin >> x >> y; dfs(x, y); } else{ cin >> x; cout << d[x] << endl; } } } signed main() { IOS; clock_t start = clock(); int Test = 1; // cin >> Test; for(int tt = 0; tt < Test; tt++){ solve(); } cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary NxN matrix A. Return A raised to the power p. Print each element of the matrix modulo 10^9+7.First line contains two numbers, N and P, denoting the size of the matrix A and the power it is raised to respectively Next N lines contain N numbers each representing the elements of the matrix A. Contraints 1 <= N <= 100 1 <= p <= 10^9 Aij is either 0 or 1Print matrix A raised to the power p, each element modulo (10^9+7) Input 3 4 1 0 0 1 1 1 0 1 0 Output 1 0 0 7 5 3 4 3 2, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str[] = br.readLine().split(" "); int N = Integer.parseInt(str[0]); int P = Integer.parseInt(str[1]); int a[][] = new int[N][N]; for(int i=0;i<N;i++){ str = br.readLine().split(" "); for(int j=0;j<N;j++){ a[i][j] = Integer.parseInt(str[j]); } } a = power(a,P); for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ System.out.print(a[i][j]+" "); } System.out.println(); } } static int[][] power(int a[][],int p){ if(p==1){ return a; } if((p&1)==1){ int b[][] = a.clone(); a = power(a,p-1); return multiply(a,b); }else{ a = power(a,p>>1); int b[][] = a.clone(); return multiply(a,b); } } static int[][] multiply(int a[][],int b[][]){ int N = a.length; long sum =0; int c[][] = new int[N][N]; for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ sum = 0; for(int k=0;k<N;k++){ sum += ((long)a[i][k]*b[k][j])%1000000007; } c[i][j] = (int)(sum%1000000007); } } return c; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary NxN matrix A. Return A raised to the power p. Print each element of the matrix modulo 10^9+7.First line contains two numbers, N and P, denoting the size of the matrix A and the power it is raised to respectively Next N lines contain N numbers each representing the elements of the matrix A. Contraints 1 <= N <= 100 1 <= p <= 10^9 Aij is either 0 or 1Print matrix A raised to the power p, each element modulo (10^9+7) Input 3 4 1 0 0 1 1 1 0 1 0 Output 1 0 0 7 5 3 4 3 2, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define ll 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 sz; const int NN = 101; class matrix{ public: ll mat[NN][NN]; matrix(){ for(int i = 0; i < NN; i++) for(int j = 0; j < NN; j++) mat[i][j] = 0; sz = NN; } inline matrix operator * (const matrix &a){ matrix temp; for(int i = 0; i < sz; i++) for(int j = 0; j < sz; j++){ for(int k = 0; k < sz; k++){ temp.mat[i][j] += (mat[i][k] * a.mat[k][j]) % mod; if(temp.mat[i][j] >= mod) temp.mat[i][j] -= mod; } } return temp; } inline matrix operator + (const matrix &a){ matrix temp; for(int i = 0; i < sz; i++) for(int j = 0; j < sz; j++){ temp.mat[i][j] = mat[i][j] + a.mat[i][j] ; if(temp.mat[i][j] >= mod) temp.mat[i][j] -= mod; } return temp; } inline matrix operator - (const matrix &a){ matrix temp; for(int i = 0; i < sz; i++) for(int j = 0; j < sz; j++){ temp.mat[i][j] = mat[i][j] - a.mat[i][j] ; if(temp.mat[i][j] < mod) temp.mat[i][j] += mod; } return temp; } inline void operator = (const matrix &b){ for(int i = 0; i < sz; i++) for(int j = 0; j < sz; j++) mat[i][j] = b.mat[i][j]; } inline void print(){ for(int i = 0; i < sz; i++){ for(int j = 0; j < sz; j++){ cout << mat[i][j] << " "; } cout << endl; } } }; matrix pow(matrix a, ll k){ matrix ans; for(int i = 0; i < sz; i++) ans.mat[i][i] = 1; while(k){ if(k & 1) ans = ans * a; a = a * a; k >>= 1; } return ans; } signed main() { IOS; int n, p; cin >> n >> p; matrix m; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> m.mat[i][j]; m = pow(m, p); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++) cout << m.mat[i][j] << " "; cout << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies. In the first move Joey has to give Chandler 1 candy. In the second move Chandler has to give Joey 2 candies. In the third move Joey has to give Chandler 3 candies. In the fourth move Chandler has to give Joey 4 candies. In the fifth move Joey has to give Chandler 5 candy. ... and so on. The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B. Constraints: 0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input 2 1 Sample Output Chandler Explanation: In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0. In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2. In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); String s[]=bu.readLine().split(" "); long a=Long.parseLong(s[0]),b=Long.parseLong(s[1]); if(a>=b) sb.append("Chandler"); else sb.append("Joey"); System.out.print(sb); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies. In the first move Joey has to give Chandler 1 candy. In the second move Chandler has to give Joey 2 candies. In the third move Joey has to give Chandler 3 candies. In the fourth move Chandler has to give Joey 4 candies. In the fifth move Joey has to give Chandler 5 candy. ... and so on. The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B. Constraints: 0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input 2 1 Sample Output Chandler Explanation: In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0. In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2. In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., 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> ///////////// signed main(){ #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int a,b; cin>>a>>b; if(a>=b) cout<<"Chandler"; else cout<<"Joey"; #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: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies. In the first move Joey has to give Chandler 1 candy. In the second move Chandler has to give Joey 2 candies. In the third move Joey has to give Chandler 3 candies. In the fourth move Chandler has to give Joey 4 candies. In the fifth move Joey has to give Chandler 5 candy. ... and so on. The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B. Constraints: 0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input 2 1 Sample Output Chandler Explanation: In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0. In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2. In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: ch,jo=map(int,input().split()) if ch>=jo: print('Chandler') else: print('Joey'), In this Programming Language: Python, 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: 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
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:- a+b a-b a*b a/bThe input contains two integers a and b separated by spaces. <b>Constraints:</b> 1 &le; b &le; a &le; 1000 <b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input: 15 3 Sample Output: 18 12 45 5 <b>Explanation:-</b> First operation is a+b so 15+3 = 18 The second Operation is a-b so 15-3 = 12 Third Operation is a*b so 15*3 = 45 Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args){ FastReader read = new FastReader(); int a = read.nextInt(); int b = read.nextInt(); System.out.println(a+b); System.out.println(a-b); System.out.println(a*b); System.out.println(a/b); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ InputStreamReader inr = new InputStreamReader(System.in); br = new BufferedReader(inr); } String next(){ while(st==null || !st.hasMoreElements()) try{ st = new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble(){ return Double.parseDouble(next()); } long nextLong(){ return Long.parseLong(next()); } String nextLine(){ String str = ""; try{ str = br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:- a+b a-b a*b a/bThe input contains two integers a and b separated by spaces. <b>Constraints:</b> 1 &le; b &le; a &le; 1000 <b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input: 15 3 Sample Output: 18 12 45 5 <b>Explanation:-</b> First operation is a+b so 15+3 = 18 The second Operation is a-b so 15-3 = 12 Third Operation is a*b so 15*3 = 45 Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split()) print(a+b) print(a-b) print(a*b) print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible. Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument. Constraints:- 0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:- X = 5 Sample Output:- 5 Explanation:- One of the possible solutions is she can mark all the answers true. Sample Input:- 1 Sample Output:- 9, I have written this Solution Code: static int maximumMarks(int X){ if(X>5){ return X; } return 10-X; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible. Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument. Constraints:- 0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:- X = 5 Sample Output:- 5 Explanation:- One of the possible solutions is she can mark all the answers true. Sample Input:- 1 Sample Output:- 9, I have written this Solution Code: int maximumMarks(int X){ if(X>5){ return X; } return 10-X; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible. Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument. Constraints:- 0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:- X = 5 Sample Output:- 5 Explanation:- One of the possible solutions is she can mark all the answers true. Sample Input:- 1 Sample Output:- 9, I have written this Solution Code: def maximumMarks(X): if X>5: return (X) return (10-X) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible. Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument. Constraints:- 0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:- X = 5 Sample Output:- 5 Explanation:- One of the possible solutions is she can mark all the answers true. Sample Input:- 1 Sample Output:- 9, I have written this Solution Code: int maximumMarks(int X){ if(X>5){ return X; } return 10-X; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: def compound_interest(principle, rate, time): Amount = principle * (pow((1 + rate / 100), time)) CI = Amount - principle print( '%.2f'%CI) principle,rate,time=map(int, input().split()) compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: function calculateCI(P, R, T) { let interest = P * (Math.pow(1.0 + R/100.0, T) - 1); return interest.toFixed(2); }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int p,r,t; cin>>p>>r>>t; double rate= (float)r/100; double amt = (float)p*(pow(1+rate,t)); cout << fixed << setprecision(2) << (amt - p); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: import java.io.*; import java.util.*; import java.lang.Math; class Main { public static void main (String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] s= br.readLine().split(" "); double[] darr = new double[s.length]; for(int i=0;i<s.length;i++){ darr[i] = Double.parseDouble(s[i]); } double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0]; System.out.printf("%.2f",ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N containing 0s and 1s only. The task is to count the subarrays having an equal number of 0s and 1s.The first line of the input contains an integer N denoting the size of the array and the second line contains N space-separated 0s and 1s. Constraints:- 1 <= N <= 10^6 0 <= A[i] <= 1For each test case, print the count of required sub-arrays in new line.Sample Input 7 1 0 0 1 0 1 1 Sample Output 8 The index range for the 8 sub-arrays are: (0, 1), (2, 3), (0, 3), (3, 4), (4, 5) (2, 5), (0, 5), (1, 6), I have written this Solution Code: size = int(input()) givenList = list(map(int,input().split())) hs = {} sm = 0 ct = 0 for i in givenList: if i == 0: i = -1 sm = sm + i if sm == 0: ct += 1 if sm not in hs.keys(): hs[sm] = 1 else: freq = hs[sm] ct = ct +freq hs[sm] = freq + 1 print(ct), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N containing 0s and 1s only. The task is to count the subarrays having an equal number of 0s and 1s.The first line of the input contains an integer N denoting the size of the array and the second line contains N space-separated 0s and 1s. Constraints:- 1 <= N <= 10^6 0 <= A[i] <= 1For each test case, print the count of required sub-arrays in new line.Sample Input 7 1 0 0 1 0 1 1 Sample Output 8 The index range for the 8 sub-arrays are: (0, 1), (2, 3), (0, 3), (3, 4), (4, 5) (2, 5), (0, 5), (1, 6), I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define max1 1000001 int a[max1]; int main(){ int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; if(a[i]==0){a[i]=-1;} } long sum=0; unordered_map<long,int> m; long cnt=0; for(int i=0;i<n;i++){ sum+=a[i]; if(sum==0){cnt++;} cnt+=m[sum]; m[sum]++; } cout<<cnt; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N containing 0s and 1s only. The task is to count the subarrays having an equal number of 0s and 1s.The first line of the input contains an integer N denoting the size of the array and the second line contains N space-separated 0s and 1s. Constraints:- 1 <= N <= 10^6 0 <= A[i] <= 1For each test case, print the count of required sub-arrays in new line.Sample Input 7 1 0 0 1 0 1 1 Sample Output 8 The index range for the 8 sub-arrays are: (0, 1), (2, 3), (0, 3), (3, 4), (4, 5) (2, 5), (0, 5), (1, 6), I have written this Solution Code: import java.io.*; // for handling input/output import java.util.*; // contains Collections framework // don't change the name of this class // you can add inner classes if needed class Main { public static void main (String[] args) { // Your code here Scanner sc = new Scanner(System.in); int arrSize = sc.nextInt(); long arr[] = new long[arrSize]; for(int i = 0; i < arrSize; i++) arr[i] = sc.nextInt(); System.out.println(countSubarrays(arr, arrSize)); } static long countSubarrays(long arr[], int arrSize) { for(int i = 0; i < arrSize; i++) { if(arr[i] == 0) arr[i] = -1; } long ans = 0; long sum = 0; HashMap<Long, Integer> hash = new HashMap<>(); for(int i = 0; i < arrSize; i++) { sum += arr[i]; if(sum == 0) ans++; if(hash.containsKey(sum) == true) { ans += hash.get(sum); int freq = hash.get(sum); hash.put(sum, freq+1); } else hash.put(sum, 1); } return ans; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a temperature C in Celsius, your task is to convert it into Fahrenheit using the following equation:- T<sup>°F</sup> = T<sup>°C</sup> × 9/5 + 32<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>CelsiusToFahrenheit()</b> that takes the integer C parameter. <b>Constraints</b> -10^3 <= C <= 10^3 <b>Note:</b> It is guaranteed that C will be a multiple of 5.Return a integer containing converted temperature in Fahrenheit.Sample Input : 25 Sample Output: 77 Sample Input:- -40 Sample Output:- -40, I have written this Solution Code: def CelsiusToFahrenheit(C): F = int((C * 1.8) + 32) return F , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a temperature C in Celsius, your task is to convert it into Fahrenheit using the following equation:- T<sup>°F</sup> = T<sup>°C</sup> × 9/5 + 32<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>CelsiusToFahrenheit()</b> that takes the integer C parameter. <b>Constraints</b> -10^3 <= C <= 10^3 <b>Note:</b> It is guaranteed that C will be a multiple of 5.Return a integer containing converted temperature in Fahrenheit.Sample Input : 25 Sample Output: 77 Sample Input:- -40 Sample Output:- -40, I have written this Solution Code: static int CelsiusToFahrenheit(int c){ return 9*(c/5) + 32; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the simple interest for given principal amount P, time Tm(in years) and rate R.<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>SimpleInterest()</b> that takes the principal amount P, rate R, and time Tm as a parameter. Constraints: 1 <= P <= 10^3 1 <= Tm <= 20 1 <= R <= 20Return the floor value of the simple interest i.e. interest in integer format.Input: 42 15 8 Output: 50 Explanation: Testcase 1: Simple interest of given principal amount 42, in 8 years at a 15% rate of interest is 50., I have written this Solution Code: import math p,t,r = [int(x) for x in input().split()] res=p*t*r print(math.floor(res/100)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the simple interest for given principal amount P, time Tm(in years) and rate R.<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>SimpleInterest()</b> that takes the principal amount P, rate R, and time Tm as a parameter. Constraints: 1 <= P <= 10^3 1 <= Tm <= 20 1 <= R <= 20Return the floor value of the simple interest i.e. interest in integer format.Input: 42 15 8 Output: 50 Explanation: Testcase 1: Simple interest of given principal amount 42, in 8 years at a 15% rate of interest is 50., I have written this Solution Code: static int SimpleInterest(int P, int R, int Tm){ return (P*Tm*R)/100; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string. Find out the distinct alphabets and the number of times they occur.The input contains a single string S. Constraints:- 1 <= |S| <= 100000 Note:- String will contain only lowercase characters and spaces.Print 26 space separated numbers that denote the number of occurrences of each character from 'a' to 'z'.Sample Input:- newton school Sample Output:- 0 0 1 0 1 0 0 1 0 0 0 1 0 2 3 0 0 0 1 1 0 0 1 0 0 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main{ public static void distinctAlphabet(String str){ int n=str.length(); int count[]=new int[26]; for(int i=0; i<n;i++){ if(str.charAt(i)!=' '){ count[str.charAt(i)-'a']++; } else if(str.charAt(i)==' '){ continue; } } for(int i=0;i<26;i++){ System.out.print(count[i]+" "); } } public static void main(String args[]){ Scanner sc=new Scanner(System.in); String s=sc.nextLine(); distinctAlphabet(s); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string. Find out the distinct alphabets and the number of times they occur.The input contains a single string S. Constraints:- 1 <= |S| <= 100000 Note:- String will contain only lowercase characters and spaces.Print 26 space separated numbers that denote the number of occurrences of each character from 'a' to 'z'.Sample Input:- newton school Sample Output:- 0 0 1 0 1 0 0 1 0 0 0 1 0 2 3 0 0 0 1 1 0 0 1 0 0 0, I have written this Solution Code: #include<bits/stdc++.h> #define ll long long using namespace std; int main() { string s; getline(cin,s); int a[26]={0}; for(int i=0;i<s.length();i++){ if(s[i]!=' '){ a[s[i]-'a']++; } } for(int i=0;i<26;i++){ cout<<a[i]<<" "; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string. Find out the distinct alphabets and the number of times they occur.The input contains a single string S. Constraints:- 1 <= |S| <= 100000 Note:- String will contain only lowercase characters and spaces.Print 26 space separated numbers that denote the number of occurrences of each character from 'a' to 'z'.Sample Input:- newton school Sample Output:- 0 0 1 0 1 0 0 1 0 0 0 1 0 2 3 0 0 0 1 1 0 0 1 0 0 0, I have written this Solution Code: from collections import defaultdict st=input() d=defaultdict(int) for i in st: d[i]+=1 alpha="abcdefghijklmnopqrstuvwxyz" for i in alpha: print(d[i],end=" ") , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Linear probing is a collision handling technique in hashing. Linear probing says that whenever a collision occurs, search for the immediate next position. In this question, we'll learn how to fill up the hash table using linear probing technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr of size n. You need to fill up the hash table using linear probing and print the resultant hash table. Note: All the positions that are unoccupied are denoted by -1 in the hash table. If there is no more space to insert, then just drop that element.The first line of input contains T denoting the number of test cases. T-test cases follow. Each test case contains 2 lines of input. The first line contains the size of the hashtable and the size of the array. The third line contains elements of the array. <b>Constraints:-</b> 1 &le; T &le; 100 1 &le; hashSize &le; 10<sup>3</sup> 1 &le; sizeOfArray &le; 10<sup>3</sup> 0 &le; Array[] &le; 10<sup>5</sup> For each testcase, in a new line, print the hash table as shown in example.Input: 2 10 4 4 14 24 44 10 4 9 99 999 9999 Output: -1 -1 -1 -1 4 14 24 44 -1 -1 99 999 9999 -1 -1 -1 -1 -1 -1 9 Explanation: Testcase1: 4%10=4. So put 4 in hashtable[4]. Now, 14%10=4, but hashtable[4] is already filled so put 14 in the next slot and so on. Testcase2: 9%10=9. So put 9 in hashtable[9]. Now, 99%10=9, but hashtable[9] is already filled so put 99 in the (99+1)%10 =0 slot so 99 goes into hashtable[0] and so on., I have written this Solution Code: // author-Shivam gupta #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define read(type) readInt<type>() #define max1 1000001 #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; 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; } // Returns n^(-1) mod p ll modInverse(ll n, ll p) { return power(n, p-2, p); } // Returns nCr % p using Fermat's little // theorem. int main(){ int t; cin>>t; while(t--){ int n,p; cin>>p>>n; int a[n]; li sum; ll cur=0; int b[p]; FOR(i,p){ b[i]=-1;} unordered_map<ll,int> m; ll cnt=0; FOR(i,n){cin>>a[i];} for(int i=0;i<min(n,p);i++){ cur=a[i]%p; int j=0; while(b[(cur+j)%p]!=-1){ j++; } b[(cur+j)%p]=a[i]; } FOR(i,p){ out1(b[i]); } END; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Linear probing is a collision handling technique in hashing. Linear probing says that whenever a collision occurs, search for the immediate next position. In this question, we'll learn how to fill up the hash table using linear probing technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr of size n. You need to fill up the hash table using linear probing and print the resultant hash table. Note: All the positions that are unoccupied are denoted by -1 in the hash table. If there is no more space to insert, then just drop that element.The first line of input contains T denoting the number of test cases. T-test cases follow. Each test case contains 2 lines of input. The first line contains the size of the hashtable and the size of the array. The third line contains elements of the array. <b>Constraints:-</b> 1 &le; T &le; 100 1 &le; hashSize &le; 10<sup>3</sup> 1 &le; sizeOfArray &le; 10<sup>3</sup> 0 &le; Array[] &le; 10<sup>5</sup> For each testcase, in a new line, print the hash table as shown in example.Input: 2 10 4 4 14 24 44 10 4 9 99 999 9999 Output: -1 -1 -1 -1 4 14 24 44 -1 -1 99 999 9999 -1 -1 -1 -1 -1 -1 9 Explanation: Testcase1: 4%10=4. So put 4 in hashtable[4]. Now, 14%10=4, but hashtable[4] is already filled so put 14 in the next slot and so on. Testcase2: 9%10=9. So put 9 in hashtable[9]. Now, 99%10=9, but hashtable[9] is already filled so put 99 in the (99+1)%10 =0 slot so 99 goes into hashtable[0] and so on., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(read.readLine()); while(t-- > 0){ String str[] = read.readLine().trim().split("\\s+"); int hashSize = Integer.parseInt(str[0]); int N = Integer.parseInt(str[1]); int arr[] = new int[N]; str = read.readLine().trim().split("\\s+"); for(int i = 0; i < N; i++){ arr[i] = Integer.parseInt(str[i]); } int hashTable[] = new int[hashSize]; for(int i=0; i<hashSize; i++){ hashTable[i] = -1; } for(int i = 0; i< Math.min(N, hashSize); i++){ int idx = arr[i] % hashSize; int j = 0; while(hashTable[(idx + j) % hashSize] != -1){ j++; } hashTable[(idx + j) % hashSize] = arr[i]; } for(int i=0; i<hashSize; i++){ System.out.print(hashTable[i] +" "); } System.out.println(); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Linear probing is a collision handling technique in hashing. Linear probing says that whenever a collision occurs, search for the immediate next position. In this question, we'll learn how to fill up the hash table using linear probing technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr of size n. You need to fill up the hash table using linear probing and print the resultant hash table. Note: All the positions that are unoccupied are denoted by -1 in the hash table. If there is no more space to insert, then just drop that element.The first line of input contains T denoting the number of test cases. T-test cases follow. Each test case contains 2 lines of input. The first line contains the size of the hashtable and the size of the array. The third line contains elements of the array. <b>Constraints:-</b> 1 &le; T &le; 100 1 &le; hashSize &le; 10<sup>3</sup> 1 &le; sizeOfArray &le; 10<sup>3</sup> 0 &le; Array[] &le; 10<sup>5</sup> For each testcase, in a new line, print the hash table as shown in example.Input: 2 10 4 4 14 24 44 10 4 9 99 999 9999 Output: -1 -1 -1 -1 4 14 24 44 -1 -1 99 999 9999 -1 -1 -1 -1 -1 -1 9 Explanation: Testcase1: 4%10=4. So put 4 in hashtable[4]. Now, 14%10=4, but hashtable[4] is already filled so put 14 in the next slot and so on. Testcase2: 9%10=9. So put 9 in hashtable[9]. Now, 99%10=9, but hashtable[9] is already filled so put 99 in the (99+1)%10 =0 slot so 99 goes into hashtable[0] and so on., I have written this Solution Code: t = int(input()) for _ in range(t): n,arrSize = map(int,input().split()) nums = list(map(int,input().split())) hashSet = [-1]*n for i in nums: if hashSet[i%n] == -1: hashSet[i%n] = i else: j = i%n + 1 while j!=i%n: if hashSet[j%n] == -1: hashSet[j%n] = i break j += 1 if hashSet.count(-1) == 0: break print(*hashSet), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>candies()</b> that takes integers X, and Y as arguments. Constraints:- 1 <= X <= 1000 1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:- X = 3, Y = 5 Sample Output:- 1 Explanation:- Total people in Sara's home = 5, no. of people allowed = 3 Sample Input:- X = 4, Y = 2 Sample Output:- 0, I have written this Solution Code: static int candies(int X, int Y){ if(X<=Y){return 1;} return 0; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>candies()</b> that takes integers X, and Y as arguments. Constraints:- 1 <= X <= 1000 1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:- X = 3, Y = 5 Sample Output:- 1 Explanation:- Total people in Sara's home = 5, no. of people allowed = 3 Sample Input:- X = 4, Y = 2 Sample Output:- 0, I have written this Solution Code: int candies(int X, int Y){ if(X<=Y){return 1;} return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>candies()</b> that takes integers X, and Y as arguments. Constraints:- 1 <= X <= 1000 1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:- X = 3, Y = 5 Sample Output:- 1 Explanation:- Total people in Sara's home = 5, no. of people allowed = 3 Sample Input:- X = 4, Y = 2 Sample Output:- 0, I have written this Solution Code: def candies(X,Y): if(X<=Y): return 1 return 0 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>candies()</b> that takes integers X, and Y as arguments. Constraints:- 1 <= X <= 1000 1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:- X = 3, Y = 5 Sample Output:- 1 Explanation:- Total people in Sara's home = 5, no. of people allowed = 3 Sample Input:- X = 4, Y = 2 Sample Output:- 0, I have written this Solution Code: int candies(int X, int Y){ if(X<=Y){return 1;} return 0; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Newton is highly ambitious, and he currently has 10 rupees. He goes to the casino and plays against an infinitely rich man (never ending money) in order to win huge money. The rules of the game are super simple. There are N turns and the following procedure is followed in each turn. <ul> <li>If one of the player has 0 money, nothing happens. <li> Else, the losing player loses 1 rupee and the winning player wins 1 rupee. </ul> The probability of Newton winning in any turn is P/Q. Find the expected money he would have, if N is 5000<sup>5000<sup>5000</sup></sup>.The first and the only line of input contains two integers P and Q. Constraints 1 <= P <= Q <= 1000000If the expected value is greater than 10^18, output 10^18, else output floor(expected value).Sample Input 1 1000000 Sample Output 0 Explanation Given the probability of Newton winning is 0.000001. It can be proved that the floor of expected money he has after infinite number of turns is 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(ll i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define pb push_back #define ll long long #define 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 p, q; cin>>p>>q; q = q-p; if(p < q){ cout<<0; } else if(p==q) cout<<10; else{ cout<<1000000000000000000LL; } } 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: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner. You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan. Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 &le; L &le; 100 and L is odd). The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input: 3 NNT Sample Output: Nutan Explanation: Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import static java.lang.System.out; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader reader = new FastReader(); int n = reader.nextInt(); String S = reader.next(); int ncount = 0; int tcount = 0; for (char c : S.toCharArray()) { if (c == 'N') ncount++; else tcount++; } if (ncount > tcount) { out.print("Nutan\n"); } else { out.print("Tusla\n"); } out.flush(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable