Instruction
stringlengths
261
35k
Response
stringclasses
1 value
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 an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation. <b>Note:-</b> The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array. <b>Constraints:</b> 1 <= T <= 50 3 <= N <= 10^3 1 <= A[i] <= 10^4 Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input: 2 4 3 4 1 2 3 1 3 2 Sample Output: Yes Yes <b>Explanation:</b> Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2). Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; bool check_increasing(int n){ int id = 0; for(int i = 2; i <= n; i++){ if(a[i] < a[i-1]){ id = i; break; } } if(id == 0) return 0; int cur = id+1; while(cur != id+n){ if(a[cur] <= a[cur-1]) return 0; cur++; } return 1; } bool check_decreasing(int n){ int id = 0; for(int i = 2; i <= n; i++){ if(a[i] > a[i-1]){ id = i; break; } } if(id == 0) return 0; int cur = id+1; while(cur != id+n){ if(a[cur] >= a[cur-1]) return 0; cur++; } return 1; } signed main() { IOS; int t; cin >> t; while(t--){ int n; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i], a[i+n] = a[i]; if(check_increasing(n)) cout << "Yes" << endl; else if(check_decreasing(n)) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation. <b>Note:-</b> The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array. <b>Constraints:</b> 1 <= T <= 50 3 <= N <= 10^3 1 <= A[i] <= 10^4 Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input: 2 4 3 4 1 2 3 1 3 2 Sample Output: Yes Yes <b>Explanation:</b> Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2). Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., I have written this Solution Code: cases = int(input()) for _ in range(cases): size = int(input()) orig = list(map(int,input().split())) givenList = orig.copy() givenList.sort() flag = False for _ in range(size-1): ele = givenList.pop() givenList.insert(0,ele) if givenList == orig: print("Yes") flag = True break if not flag: givenList.sort() givenList.reverse() for _ in range(size-1): ele = givenList.pop() givenList.insert(0,ele) if givenList == orig: print("Yes") flag = True break if not flag: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation. <b>Note:-</b> The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array. <b>Constraints:</b> 1 <= T <= 50 3 <= N <= 10^3 1 <= A[i] <= 10^4 Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input: 2 4 3 4 1 2 3 1 3 2 Sample Output: Yes Yes <b>Explanation:</b> Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2). Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine().trim()); //Inputting the testcases while(t-->0){ long n = Long.parseLong(br.readLine()); int arr[] = new int[(int)n]; String inputLine[] = br.readLine().trim().split("\\s+"); for(long i=0; i<n; i++){ arr[(int)i] = Integer.parseInt(inputLine[(int)i]); } long mini = Integer.MAX_VALUE, maxi = Integer.MIN_VALUE; long max_index = 0, min_index = 0; for(long i=0; i<n; i++){ if(maxi < arr[(int)i]){ maxi = arr[(int)i]; max_index = i; } if(mini > arr[(int)i]){ mini = arr[(int)i]; min_index = i; } } int flag = 0; if(max_index == min_index -1) flag = 1; else if(min_index == max_index - 1) flag = -1; if(flag == 1){ for(long i = 1; flag==1 && i<=max_index; ++i){ if(arr[(int)i-1] >= arr[(int)i]) flag = 0; } for(long i = min_index+1; flag==1 && i<n; ++i){ if(arr[(int)i-1] >= arr[(int)i]) flag = 0; } if(arr[0]<=arr[(int)n-1]) flag = 0; } else if(flag == -1){ for(long i = 1; flag ==-1 && i<=min_index; ++i){ if(arr[(int)i-1] <= arr[(int)i]) flag = 0; } for(long i = max_index+1; flag==-1 && i<n; ++i){ if(arr[(int)i-1] <= arr[(int)i]) flag = 0; } if(arr[0]>=arr[(int)n-1]) flag = 0; } if(flag == 0) System.out.println("No"); else System.out.println("Yes"); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: void pattern_making(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ cout<<j<<" "; } for(int j=i-1;j>=1;j--){ cout<<j<<" "; } cout<<endl; } for(int i=n-1;i>=1;i--){ for(int j=1;j<=i;j++){ cout<<j<<" "; } for(int j=i-1;j>=1;j--){ cout<<j<<" "; } cout<<endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: void pattern_making(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ printf("%d ",j); } for(int j=i-1;j>=1;j--){ printf("%d ",j); } printf("\n"); } for(int i=n-1;i>=1;i--){ for(int j=1;j<=i;j++){ printf("%d ",j); } for(int j=i-1;j>=1;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 an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: public static void pattern_making(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); } for(int j=i-1;j>=1;j--){ System.out.print(j+" "); } System.out.println(); } for(int i=n-1;i>=1;i--){ for(int j=1;j<=i;j++){ System.out.print(j+" "); } for(int j=i-1;j>=1;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 an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: function patternMaking(N) { for(let j=1; j <= 2*N - 1; j++) { let k; if(j<= N) { k = j; } else { k = 2*N - j; } let res = ""; for(let i=1; i<=2*k-1; i++) { if(i<=k) { res += i + " "; } else { res += 2*k - i + " "; } } console.log(res); } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: def pattern_making(n): for i in range(1, n+1): for j in range(1, i+1): print(j,end=" ") for j in range (1,i): print(i-j,end=" ") print("\r") i=n-1 while i>=1 : for j in range(1, i+1): print(j,end=" ") for j in range (1,i): print(i-j,end=" ") print("\r") i=i-1 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax. Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input <b>Constarints</b> 1&le; a,b,c &le;1000The number resulting after the multiplication of 3 input numbersSample input:- 1 5 2 Sample output:- 10 <b>Explanation:-</b> 1*5*2 = 10, I have written this Solution Code: function mul (x) { return function (y) { // anonymous function return function (z) { // anonymous function console.log(x*y*z); }; }; } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax. Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input <b>Constarints</b> 1&le; a,b,c &le;1000The number resulting after the multiplication of 3 input numbersSample input:- 1 5 2 Sample output:- 10 <b>Explanation:-</b> 1*5*2 = 10, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); System.out.println(a*b*c); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax. Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input <b>Constarints</b> 1&le; a,b,c &le;1000The number resulting after the multiplication of 3 input numbersSample input:- 1 5 2 Sample output:- 10 <b>Explanation:-</b> 1*5*2 = 10, I have written this Solution Code: x,y,z= map(int,input().split()) print(x*y*z), 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: Complete the function <code>countBy</code> Such that it takes a initial number which is the defualt value of out counter. And returns a function which also takes a number and returns the initialCount + number supplied to second function. Ex:- <code> const count = countBy(4) // initial value of counter 4, returns a function <br> console. log(count(2)) // prints 6 because 4 + 2 <br> console. log(count(-4)) // prints 2 because 6 - 4 <br> console. log(count(8)) // prints 10 because 2 + 8 <br> </code> You have to return implement countBy function such that it can be run like that.<code>countBy</code> will take one number as input which will be the initial count.<code>countBy</code> will return a function which can be run many times and takes a number as input and returns the sum of it with previously maintained counter values<code> const count = countBy(4) // initial value of counter 4, returns a function <br> console. log(count(2)) // prints 6 because 4 + 2 <br> console. log(count(-4)) // prints 2 because 6 - 4 <br> console. log(count(8)) // prints 10 because 2 + 8 <br> </code>, I have written this Solution Code: function countBy(initial){ let copy = initial return (y)=>{ copy += y return copy } // return the output using return keyword // do not console.log it }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T. The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting. Constraints: 1 <= T <= 100 0 <= N <= 100 0 <= X <= 30Output the waiting time of last patient.Input: 5 4 5 5 3 6 5 7 6 8 2 Output: 15 28 25 24 56, I have written this Solution Code: for i in range(int(input())): n, x = map(int, input().split()) if x >= 10: print(0) else: print((10-x)*(n-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T. The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting. Constraints: 1 <= T <= 100 0 <= N <= 100 0 <= X <= 30Output the waiting time of last patient.Input: 5 4 5 5 3 6 5 7 6 8 2 Output: 15 28 25 24 56, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; signed main() { IOS; int t; cin >> t; while(t--){ int n, x; cin >> n >> x; if(x >= 10) cout << 0 << endl; else cout << (10-x)*(n-1) << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T. The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting. Constraints: 1 <= T <= 100 0 <= N <= 100 0 <= X <= 30Output the waiting time of last patient.Input: 5 4 5 5 3 6 5 7 6 8 2 Output: 15 28 25 24 56, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); while (T -->0){ String s[] = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int p = Integer.parseInt(s[1]); if (p<10) System.out.println(Math.abs(n-1)*(10-p)); else System.out.println(0); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K. Constraints: 1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input: 28 Sample Output: 4 Explaination: 4<sup>2</sup> + 3*4 = 28 There is no other positive integer that will give such result., I have written this Solution Code: def FindIt(n): sqrt_n = int(K**0.5) check = -1 for i in range(sqrt_n - 1, sqrt_n - 2, -1): check = i**2 + (i * 3) if check == n: return i return -1 K = int(input()) print(FindIt(K)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K. Constraints: 1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input: 28 Sample Output: 4 Explaination: 4<sup>2</sup> + 3*4 = 28 There is no other positive integer that will give such result., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); #define int long long #define pb push_back #define ff first #define ss second #define endl '\n' #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using T = pair<int, int>; typedef long double ld; const int mod = 1e9 + 7; const int INF = 1e9; void solve(){ int n; cin >> n; int l = 1, r = 1e9, ans = -1; while(l <= r){ int m = (l + r)/2; int val = m*m + 3*m; if(val == n){ ans = m; break; } if(val < n){ l = m + 1; } else r = m - 1; } cout << ans; } signed main(){ fast int t = 1; // cin >> t; for(int i = 1; i <= t; i++){ solve(); if(i != t) cout << endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K. Constraints: 1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input: 28 Sample Output: 4 Explaination: 4<sup>2</sup> + 3*4 = 28 There is no other positive integer that will give such result., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); long K = Long.parseLong(br.readLine()); long ans = -1; for(long x =0;((x*x)+(3*x))<=K;x++){ if(K==((x*x)+(3*x))){ ans = x; break; } } System.out.println(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B. The next two lines contain the input of arrays A and B. <b>Constraints</b> 1 &le; n, m &le; 1000 -10<sup>6</sup> &le; A[i], B[i] &le; 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input : 2 1 1 3 2 Sample Output : 2.00, I have written this Solution Code: import java.io.*; import java.util.*; import java.util.Arrays; class Main { public static double getMedia(long[]a,long[]b){ if(a.length>b.length){ long[]temp; temp=a; a=b;b=temp; } int lo=0; int hi=a.length; int tl=a.length+b.length; while(lo<=hi){ int al=(lo+hi)/2; int bl=((tl+1)/2)-al; long alm1=(al==0)? Long.MIN_VALUE:a[al-1]; long alf=(al==a.length)? Long.MAX_VALUE:a[al]; long blm1=(bl==0)? Long.MIN_VALUE:b[bl-1]; long blf=(bl==b.length)? Long.MAX_VALUE:b[bl]; if(alm1<=blf && blm1<=alf){ double median = 0.0; if(tl%2==0){ long lmax=Math.max(alm1,blm1); long rmin=Math.min(alf,blf); median=(lmax+rmin)/2.0; return median; }else{ long lmax=Math.max(alm1,blm1); median=lmax; return median; } } else if(alm1>blf){ hi=al-1; }else if(blm1>alf){ lo=al+1; } } return 0; } public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str = br.readLine().split(" "); int n=Integer.parseInt(str[0]); int m=Integer.parseInt(str[1]); long[] a=new long[n]; long[] b=new long[m]; str=br.readLine().split(" "); for(int i=0;i<n;i++){ a[i]=Long.parseLong(str[i]); } str=br.readLine().split(" "); for(int i=0;i<m;i++){ b[i]=Long.parseLong(str[i]); } System.out.format("%.2f",getMedia(a,b)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B. The next two lines contain the input of arrays A and B. <b>Constraints</b> 1 &le; n, m &le; 1000 -10<sup>6</sup> &le; A[i], B[i] &le; 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input : 2 1 1 3 2 Sample Output : 2.00, I have written this Solution Code: def getMedian(arr1, arr2, n, m): i=j=0 sort=[] while i<n and j<m: if arr1[i] < arr2[j]: sort.append(arr1[i]) i+=1 else: sort.append(arr2[j]) j+=1 while i<n: sort.append(arr1[i]) i+=1 while j<m: sort.append(arr2[j]) j+=1 if (n+m)%2==1: ind=(len(sort)//2)+1 num=sort[ind-1] else: mid=len(sort)//2 num=(sort[mid-1]+sort[mid])/2 return num n, m= input().split() n, m= int(n),int(m) ar1=list(map(int, input().split())) ar2=list(map(int, input().split())) print("%.2f" %getMedian(ar1, ar2, n, m)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B. The next two lines contain the input of arrays A and B. <b>Constraints</b> 1 &le; n, m &le; 1000 -10<sup>6</sup> &le; A[i], B[i] &le; 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input : 2 1 1 3 2 Sample Output : 2.00, I have written this Solution Code: /** * Author : tourist1256 * Time : 2022-02-02 14:05:28 **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 2351 #endif double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { if (nums2.size() < nums1.size()) return findMedianSortedArrays(nums2, nums1); int n1 = nums1.size(); int n2 = nums2.size(); int lo = 0, hi = n1; while (lo <= hi) { int cut1 = (lo + hi) / 2; int cut2 = (n1 + n2 + 1) / 2 - cut1; int left1 = cut1 == 0 ? INT_MIN : nums1[cut1 - 1]; int left2 = cut2 == 0 ? INT_MIN : nums2[cut2 - 1]; int right1 = cut1 == n1 ? INT_MAX : nums1[cut1]; int right2 = cut2 == n2 ? INT_MAX : nums2[cut2]; if (left1 <= right2 && left2 <= right1) { if ((n1 + n2) % 2 == 0) return (max(left1, left2) + min(right1, right2)) / 2.0; else return max(left1, left2); } else if (left1 > right2) { hi = cut1 - 1; } else lo = cut1 + 1; } return 0.0; } int main() { int n, m; cin >> n >> m; vector<int> a(n), b(m); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } printf("%0.2f", findMedianSortedArrays(a, b)); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A circular array is called good if, for every index i (0 to N-1), there exists an index j such that i != j and sum of all the numbers in the clockwise direction from i to j is equal to the sum of all numbers in the anticlockwise direction from i to j. You are given an circular array of size N, Your task is to check whether the given array is good or not.First line of input contains a single integer N, the next line of input contains N space separated integes depicting values of the array. Constraints:- 1 <= N <= 100000 1 <= Arr[i] <= 1000000Print "Yes" if array is good else print "No"Sample Input:- 4 1 4 1 4 Sample Output:- Yes Explanation:- for index 1, j will be 3, then sum of elements from index 1 to 3 in clockwise direction will be 1 + 4 + 1 = 6 and the sum of elements from index 1 to 3 in anticlockwise direction will be 1 + 4 + 1 = 6. For index 2, j will be 4 For index 3, j will be 1 For index 4, j will be 2 Sample Input:- 4 1 2 3 4 Sample Output:- No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 10001 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int INF = 4557430888798830399ll; signed main() { fast(); int n; cin>>n; int a[n]; FOR(i,n){ cin>>a[i];} if(n&1){out("No");return 0;} FOR(i,n/2){ if(a[i]!=a[n/2+i]){out("No");return 0;} } out("Yes"); } , In this Programming Language: Unknown, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given two numbers n and p. You need to find n raised to the power p.<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>RecursivePower</b> that takes the integer n and p as a parameter. Constraints: 1 <= T <= 10 1 <= n, p <= 9Return n^p.Sample Input: 3 2 3 9 9 2 9 Sample Output: 8 387420489‬ 512 Explanation: Test case 2: 387420489 is the value obtained when 9 is raised to the power of 9. Test case 3: 512 is the value obtained when 2 is raised to the power of 9, I have written this Solution Code: static int Power(int n,int p) { if(p==0) return 1; return n*Power(n,p-1); }, 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: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: int LastDigit(int N){ return N%10; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: static int LastDigit(int N){ return N%10; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: int LastDigit(int N){ return N%10; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: def LastDigit(N): return N%10, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), 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 IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] st = bf.readLine().split(" "); if(Integer.parseInt(st[1])==0) System.out.print(-1); else { int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1])); System.out.print(f); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split() D = int(D) Q = int(Q) if(0<=D and Q<=100 and Q >0): print(int(D/Q)) else: print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream> using namespace std; int main(){ int n,m; cin>>n>>m; if(m==0){cout<<-1;return 0;} cout<<n/m; }, 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: 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 two integers a and b, your task is to check following conditions:- 1. If a <= 10 and b >= 10 (Logical AND). 2. Atleast one from a or b will be even (Logical OR). 3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b. <b>Constraints:</b> 1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> . Sample Input:- 3 12 Sample Output:- true true true Explanation So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true. Sample Input:- 10 10 Sample Output:- true true false , I have written this Solution Code: a, b = list(map(int, input().split(" "))) print(str(a <= 10 and b >= 10).lower(), end=' ') print(str(a % 2 == 0 or b % 2 == 0).lower(), end=' ') print(str(not a == b).lower()), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers a and b, your task is to check following conditions:- 1. If a <= 10 and b >= 10 (Logical AND). 2. Atleast one from a or b will be even (Logical OR). 3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b. <b>Constraints:</b> 1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> . Sample Input:- 3 12 Sample Output:- true true true Explanation So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true. Sample Input:- 10 10 Sample Output:- true true false , I have written this Solution Code: import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; class Main { static boolean Logical_AND(int a, int b){ if(a<=10 && b>=10){ return true;} return false;} static boolean Logical_OR(int a, int b){ if(a%2==0 || b%2==0){ return true;} return false;} static boolean Logical_NOT(int a, int b){ if(a!=b){ return true;} return false;} public static void main(String[] args) { Scanner in = new Scanner(System.in); int a=in.nextInt(); int b=in.nextInt(); System.out.print(Logical_AND(a, b)+" "); System.out.print(Logical_OR(a,b)+" "); System.out.print(Logical_NOT(a,b)+" "); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: People prefer smartness over anything. You know N people and their smartness level. You need to place people in a circle one by one in any order. The happiness that a person gets is equal to the minimum smartness value of its clockwise neighbour and its anti-clockwise neighbour at the time when he enters the circle. You can ask the person to stand at any position of the circle that you like. The happiness of the first person to enter is 0 since he has no neighbours. Find the maximum value of total happiness that can be achieved (sum of happiness of all the people).The first line of the input contains an integer N, the number of people you know. The second line of the input contains N integers, the smartness of the N people that you know. Constraints 2 <= N <= 200000 1 <= smartness of any person <= 10<sup>9</sup>Output a single integer the maximum value of total happiness.Sample Input 4 2 2 1 3 Sample Output 7 Explanation We ask the persons to enter the circle in this particular order of smartness [3, 2, 2, 1]. Step 1: 3 Happiness attained = 0 Step 2 3 2 Happiness attained = 3 Step 3 3 2 2 Happiness attained = 2 Step 4 3 1 2 2 Happiness attained = 2 Total Happiness = 0 + 3 + 2 + 2 = 7. Sample Input 2 1 1 Sample Output 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String s[]=(br.readLine()).split(" "); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=Integer.parseInt(s[i]); } Arrays.sort(a); long sum=a[n-1]; for(int i=n-2,j=1;j<n-2;j+=2,i--) { sum=sum+2*a[i]; } System.out.print(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: People prefer smartness over anything. You know N people and their smartness level. You need to place people in a circle one by one in any order. The happiness that a person gets is equal to the minimum smartness value of its clockwise neighbour and its anti-clockwise neighbour at the time when he enters the circle. You can ask the person to stand at any position of the circle that you like. The happiness of the first person to enter is 0 since he has no neighbours. Find the maximum value of total happiness that can be achieved (sum of happiness of all the people).The first line of the input contains an integer N, the number of people you know. The second line of the input contains N integers, the smartness of the N people that you know. Constraints 2 <= N <= 200000 1 <= smartness of any person <= 10<sup>9</sup>Output a single integer the maximum value of total happiness.Sample Input 4 2 2 1 3 Sample Output 7 Explanation We ask the persons to enter the circle in this particular order of smartness [3, 2, 2, 1]. Step 1: 3 Happiness attained = 0 Step 2 3 2 Happiness attained = 3 Step 3 3 2 2 Happiness attained = 2 Step 4 3 1 2 2 Happiness attained = 2 Total Happiness = 0 + 3 + 2 + 2 = 7. Sample Input 2 1 1 Sample Output 1, I have written this Solution Code: n=int(input()) lst=[int(x) for x in input().split()] lst.sort() m=n-1 ans=lst[n-1] i=n-2 while(m>1): ans+=lst[i] ans+=lst[i] i-=1 m-=2 print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: People prefer smartness over anything. You know N people and their smartness level. You need to place people in a circle one by one in any order. The happiness that a person gets is equal to the minimum smartness value of its clockwise neighbour and its anti-clockwise neighbour at the time when he enters the circle. You can ask the person to stand at any position of the circle that you like. The happiness of the first person to enter is 0 since he has no neighbours. Find the maximum value of total happiness that can be achieved (sum of happiness of all the people).The first line of the input contains an integer N, the number of people you know. The second line of the input contains N integers, the smartness of the N people that you know. Constraints 2 <= N <= 200000 1 <= smartness of any person <= 10<sup>9</sup>Output a single integer the maximum value of total happiness.Sample Input 4 2 2 1 3 Sample Output 7 Explanation We ask the persons to enter the circle in this particular order of smartness [3, 2, 2, 1]. Step 1: 3 Happiness attained = 0 Step 2 3 2 Happiness attained = 3 Step 3 3 2 2 Happiness attained = 2 Step 4 3 1 2 2 Happiness attained = 2 Total Happiness = 0 + 3 + 2 + 2 = 7. Sample Input 2 1 1 Sample Output 1, 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 n; cin>>n; vector<int> a(n); For(i, 0, n){ cin>>a[i]; } sort(all(a)); reverse(all(a)); int ans = 0; ans += a[0]; int cur = 2; For(i, 1, n){ if(cur < n){ cur++; ans += a[i]; } if(cur < n){ cur++; ans += a[i]; } } 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: You are given an array of integers. Consider absolute difference between all the pairs of the the elements. You need to find Kth smallest absolute difference. If the size of the array is N then value of K will be less than N and more than or equal to 1.The first line of input contains number of test cases T. The first line of each test case contains a two integers N and K denoting the number of elements in the array A and difference you need to output. The second line of each test case contains N space separated integers denoting the elements of the array A Constraints: 1<= T <= 10 2 <= N <= 100000 1 <= K < N < 100000 0 <= A[i] <= 100000For each test case, output Kth smallest absolute difference.Input : 1 6 2 1 3 4 1 3 8 Output : 0 Explanation : Test case 1: First smallest difference is 0, between the pair (1, 1) and second smallest absolute difference difference is also 0 between the pairs (3, 3)., I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main{ public static void main(String[] args)throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(read.readLine().trim()); while (t-- > 0) { String str[] = read.readLine().trim().split(" "); int n = Integer.parseInt(str[0]); int k = Integer.parseInt(str[1]); int arr[] = new int[n]; str = read.readLine().trim().split(" "); for (int i = 0; i < n; i++) arr[i] = Integer.parseInt(str[i]); System.out.println(Math.abs(small(arr, k))); } } public static int small(int arr[], int k) { Arrays.sort(arr); int l = 0, r = arr[arr.length - 1] - arr[0]; while (r > l) { int mid = l + (r - l) / 2; if (count(arr, mid) < k) { l = mid + 1; } else { r = mid; } } return r; } public static int count(int arr[], int mid) { int ans = 0, j = 0; for (int i = 1; i < arr.length; ++i) { while (j < i && arr[i] - arr[j] > mid) { ++j; } ans += i - j; } return ans; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a linked list consisting of N nodes and an integer K, your task is to delete the Kth node from the end of the linked list<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>deleteElement()</b> that takes head node and K as parameter. Constraints: 1 <=K<=N<= 1000 1 <=Node.data<= 1000Return the head of the modified linked listInput 1: 5 3 1 2 3 4 5 Output 1: 1 2 4 5 Explanation: After deleting 3rd node from the end of the linked list, 3 will be deleted and the list will be as 1, 2, 4, 5. Input 2:- 5 5 8 1 8 3 6 Output 2:- 1 8 3 6 , I have written this Solution Code: public static Node deleteElement(Node head,int k) { int cnt=0; Node temp=head; while(temp!=null){ cnt++; temp=temp.next; } temp=head; k=cnt-k; if(k==0){head=head.next; return head;} temp=head; cnt=0; while(cnt!=k-1){ temp=temp.next; cnt++; } temp.next=temp.next.next; return head; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: void pattern_making(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ cout<<j<<" "; } for(int j=i-1;j>=1;j--){ cout<<j<<" "; } cout<<endl; } for(int i=n-1;i>=1;i--){ for(int j=1;j<=i;j++){ cout<<j<<" "; } for(int j=i-1;j>=1;j--){ cout<<j<<" "; } cout<<endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: void pattern_making(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ printf("%d ",j); } for(int j=i-1;j>=1;j--){ printf("%d ",j); } printf("\n"); } for(int i=n-1;i>=1;i--){ for(int j=1;j<=i;j++){ printf("%d ",j); } for(int j=i-1;j>=1;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 an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: public static void pattern_making(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); } for(int j=i-1;j>=1;j--){ System.out.print(j+" "); } System.out.println(); } for(int i=n-1;i>=1;i--){ for(int j=1;j<=i;j++){ System.out.print(j+" "); } for(int j=i-1;j>=1;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 an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: function patternMaking(N) { for(let j=1; j <= 2*N - 1; j++) { let k; if(j<= N) { k = j; } else { k = 2*N - j; } let res = ""; for(let i=1; i<=2*k-1; i++) { if(i<=k) { res += i + " "; } else { res += 2*k - i + " "; } } console.log(res); } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: def pattern_making(n): for i in range(1, n+1): for j in range(1, i+1): print(j,end=" ") for j in range (1,i): print(i-j,end=" ") print("\r") i=n-1 while i>=1 : for j in range(1, i+1): print(j,end=" ") for j in range (1,i): print(i-j,end=" ") print("\r") i=i-1 , 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: 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 integer N, find all the numbers less than N which contains only digits 3, 4, and 5. Each digit should be present at least one time.The input contains a single integer N. Constraints:- 1 <= N <= 1000000000Print the count of such numbers which contains only digits 3, 4, and 5.Sample Input:- 500 Sample Output:- 4 Explanation:- 345. 435. 453, 354 Sample Input:- 1000 Sample Output:- 6, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); int count = recursive(n, 0, false, false, false); System.out.println(count); } private static int recursive(long n, long num, boolean three, boolean four, boolean five) { if(num > n){ return 0; } int count = 0; if(three && four && five){ count ++; } count += recursive(n, num*10 + 3, true, four, five); count += recursive(n, num*10 + 4, three, true, five); count += recursive(n, num*10 + 5, three, four, true); return count; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, find all the numbers less than N which contains only digits 3, 4, and 5. Each digit should be present at least one time.The input contains a single integer N. Constraints:- 1 <= N <= 1000000000Print the count of such numbers which contains only digits 3, 4, and 5.Sample Input:- 500 Sample Output:- 4 Explanation:- 345. 435. 453, 354 Sample Input:- 1000 Sample Output:- 6, I have written this Solution Code: #include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using ll = long long; int ans = 0; int n = 0; int ok; void dfs(ll x,int ok){ if(x > n) return; if(ok==7) ans++; dfs(x * 10 + 3,ok|1); dfs(x * 10 + 4,ok|2); dfs(x * 10 + 5,ok|4); return; } int main(){ cin >> n; int x = 0; dfs(x,0); cout << ans << endl; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: def ispangram(str): alphabet = "abcdefghijklmnopqrstuvwxyz" for char in alphabet: if char not in str.lower(): return False return True N = int(input()) arr = [] for i in range(N): arr.append(input()) for i in range(N): if(ispangram(arr[i]) == True): print(1) else: print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: function pangrams(s) { // write code here // do not console.log it // return 1 or 0 let alphabet = "abcdefghijklmnopqrstuvwxyz"; let regex = /\s/g; let lowercase = s.toLowerCase().replace(regex, ""); for(let i = 0; i < alphabet.length; i++){ if(lowercase.indexOf(alphabet[i]) === -1){ return 0; } } return 1; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ String s = sc.next(); int check = 1; int p =0; for(char ch = 'a';ch<='z';ch++){ p=0; for(int i = 0;i<s.length();i++){ if(s.charAt(i)==ch){p=1;} } if(p==0){check=0;} } System.out.println(check); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define pu push_back #define fi first #define se second #define mp make_pair #define int long long #define pii pair<int,int> #define mm (s+e)/2 #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define sz 200000 int A[26],B[26]; signed main() { int t; cin>>t; string p; getline(cin,p); while(t>0) { t--; string s; getline(cin,s); int n=s.size(); memset(A,0,sizeof(A)); int ch=1; for(int i=0;i<n;i++) { int x=s[i]-'a'; if(x>=0 && x<26) { A[x]++; } x=s[i]-'A'; if(x>=0 && x<26) { A[x]++; } } for(int i=0;i<26;i++) { if(A[i]==0) ch=0; } cout<<ch<<endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square. <b>Constraints:</b> 1 <= side <=100You just have to print the area of a squareSample Input:- 3 Sample Output:- 9 Sample Input:- 6 Sample Output:- 36, I have written this Solution Code: def area(side_of_square): print(side_of_square*side_of_square) def main(): N = int(input()) area(N) if __name__ == '__main__': main(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square. <b>Constraints:</b> 1 <= side <=100You just have to print the area of a squareSample Input:- 3 Sample Output:- 9 Sample Input:- 6 Sample Output:- 36, 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 side = Integer.parseInt(br.readLine()); System.out.print(side*side); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N. N lines follow each containing N space seperated integers. Constraints:- 2 <= N <= 500 1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Sample output 1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7 Explanation: We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion . Sample Input 3 1 2 3 4 5 6 7 8 9 Sample output 1 4 7 8 9 6 3 2 5 , I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main{ public static void main(String args[])throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); int x, y, start, end, num=n, firstcond, secondcond, thirdcond, fourthcond, flag; if(n%2!=0) num++; num = num/2; int[][] a = new int[n][n]; for(x=0; x<n; x++){ String nextLine[] = in.readLine().split(" "); for(y=0; y<n; y++){ a[x][y] = Integer.parseInt(nextLine[y]); } } start = 0; end = n-1; while(num>=1){ flag=0; firstcond = secondcond = thirdcond = fourthcond = 1; for(x=start, y=start; (firstcond==1 || secondcond==1 || thirdcond==1 || fourthcond==1) && (x>=start && y>=start && x<=end && y<=end); ){ System.out.print(a[x][y] + " "); if(firstcond==1){ x++; if(x==end+1){ firstcond=0; x--; y++; } }else if(secondcond==1){ y++; if(y==end+1){ secondcond=0; y--; x--; } }else if(thirdcond==1){ x--; if(x==start-1){ if(flag==0) break; thirdcond=0; x++; y--; } flag=1; }else{ y--; if(y==start){ fourthcond=0; x++; y++; } } } start++; end--; num--; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N. N lines follow each containing N space seperated integers. Constraints:- 2 <= N <= 500 1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Sample output 1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7 Explanation: We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion . Sample Input 3 1 2 3 4 5 6 7 8 9 Sample output 1 4 7 8 9 6 3 2 5 , I have written this Solution Code: n = int(input()) arr = [] for i in range(n): j = input().split() arr.append([int(xx) for xx in j]) def counterClockspiralPrint(m, n, arr) : k = 0; l = 0 cnt = 0 total = m * n while (k < m and l < n) : if (cnt == total) : break for i in range(k, m) : print(arr[i][l], end = " ") cnt += 1 l += 1 if (cnt == total) : break for i in range (l, n) : print( arr[m - 1][i], end = " ") cnt += 1 m -= 1 if (cnt == total) : break if (k < m) : for i in range(m - 1, k - 1, -1) : print(arr[i][n - 1], end = " ") cnt += 1 n -= 1 if (cnt == total) : break if (l < n) : for i in range(n - 1, l - 1, -1) : print( arr[k][i], end = " ") cnt += 1 k += 1 counterClockspiralPrint(n, n, arr), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N. N lines follow each containing N space seperated integers. Constraints:- 2 <= N <= 500 1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Sample output 1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7 Explanation: We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion . Sample Input 3 1 2 3 4 5 6 7 8 9 Sample output 1 4 7 8 9 6 3 2 5 , I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define N 1000 void counterClockspiralPrint( int m, int n, int arr[][N]) { int i, k = 0, l = 0; // k - starting row index // m - ending row index // l - starting column index // n - ending column index // i - iterator // initialize the count int cnt = 0; // total number of // elements in matrix int total = m * n; while (k < m && l < n) { if (cnt == total) break; // Print the first column // from the remaining columns for (i = k; i < m; ++i) { cout << arr[i][l] << " "; cnt++; } l++; if (cnt == total) break; // Print the last row from // the remaining rows for (i = l; i < n; ++i) { cout << arr[m - 1][i] << " "; cnt++; } m--; if (cnt == total) break; // Print the last column // from the remaining columns if (k < m) { for (i = m - 1; i >= k; --i) { cout << arr[i][n - 1] << " "; cnt++; } n--; } if (cnt == total) break; // Print the first row // from the remaining rows if (l < n) { for (i = n - 1; i >= l; --i) { cout << arr[k][i] << " "; cnt++; } k++; } } } int main() { int n; cin>>n; int arr[n][N]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>arr[i][j]; }} counterClockspiralPrint(n,n, arr); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N. N lines follow each containing N space seperated integers. Constraints:- 2 <= N <= 500 1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Sample output 1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7 Explanation: We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion . Sample Input 3 1 2 3 4 5 6 7 8 9 Sample output 1 4 7 8 9 6 3 2 5 , I have written this Solution Code: function printAntiClockWise(mat) { let i, k = 0, l = 0; let m = N; let n = N; let cnt = 0, total = m*n; while(k < m && l < n) { if (cnt == total) break; // Print the first column // from the remaining columns for (i = k; i < m; ++i) { process.stdout.write(mat[i][l] + " "); cnt++; } l++; if (cnt == total) break; // Print the last row from // the remaining rows for (i = l; i < n; ++i) { process.stdout.write(mat[m - 1][i] + " "); cnt++; } m--; if (cnt == total) break; // Print the last column // from the remaining columns if (k < m) { for (i = m - 1; i >= k; --i) { process.stdout.write(mat[i][n - 1] + " "); cnt++; } n--; } if (cnt == total) break; // Print the first row // from the remaining rows if (l < n) { for (i = n - 1; i >= l; --i) { process.stdout.write(mat[k][i] + " "); cnt++; } k++; } } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers L and R, where L and R represent the lower and upper limits of a range, find the count of lucky numbers in that range. A lucky number is defined as a number whose last digit is 7, 2, or 9. Please calculate the number of lucky numbers in the range L to R. Constraints : 1 <= L <= R <= 100000In the first line, enter the first positive integer L, where L represents the lower limit of the range. In the second line, enter the second positive integer R, where R represents the upper limit of the range. Print the count of integers that ends with 7,2,9 within the given range.Sample1: Input : 1 10 Output : 3 Sample2: Input: 1 1000000 Output: Invalid inputs. Check the constraints for L and R Sample3: Input: -1 100 Output: Invalid inputs. Check the constraints for L and R, I have written this Solution Code: def Newton_lucky(L,R): count = 0 num = L if L<1 or R>10**5 or L>R: print("Invalid inputs. Check the constraints for L and R") else: for num in range(L, R): if num%10 == 2 or num%10 == 7 or num%10 == 9: count+=1 num+=1 print(count) Newton_lucky(int(input()), int(input())) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you have to perform only two types of operations on the number:- 1) If N is odd increase it by 1 2) If N is even divide it by 2 Your task is to find the number of operations it takes to make N equal to 1.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MakeOne()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations it takes to make the number N equal to 1.Sample Input:- 7 Sample Output:- 4 Explanation:- 7 - > 8 - > 4 - > 2 - > 1 Sample Input:- 3 Sample Output:- 3, I have written this Solution Code: int MakeOne(int N){ int cnt=0; int a =N; while(a!=1){ if(a&1){a++;} else{a/=2;} cnt++; } return cnt; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you have to perform only two types of operations on the number:- 1) If N is odd increase it by 1 2) If N is even divide it by 2 Your task is to find the number of operations it takes to make N equal to 1.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MakeOne()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations it takes to make the number N equal to 1.Sample Input:- 7 Sample Output:- 4 Explanation:- 7 - > 8 - > 4 - > 2 - > 1 Sample Input:- 3 Sample Output:- 3, I have written this Solution Code: static int MakeOne(int N){ int cnt=0; int a =N; while(a!=1){ if(a%2==1){a++;} else{a/=2;} cnt++; } return cnt; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you have to perform only two types of operations on the number:- 1) If N is odd increase it by 1 2) If N is even divide it by 2 Your task is to find the number of operations it takes to make N equal to 1.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MakeOne()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations it takes to make the number N equal to 1.Sample Input:- 7 Sample Output:- 4 Explanation:- 7 - > 8 - > 4 - > 2 - > 1 Sample Input:- 3 Sample Output:- 3, I have written this Solution Code: int MakeOne(int N){ int cnt=0; int a =N; while(a!=1){ if(a&1){a++;} else{a/=2;} cnt++; } return cnt; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you have to perform only two types of operations on the number:- 1) If N is odd increase it by 1 2) If N is even divide it by 2 Your task is to find the number of operations it takes to make N equal to 1.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MakeOne()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations it takes to make the number N equal to 1.Sample Input:- 7 Sample Output:- 4 Explanation:- 7 - > 8 - > 4 - > 2 - > 1 Sample Input:- 3 Sample Output:- 3, I have written this Solution Code: def MakeOne(N): cnt=0 while N!=1: if N%2==1: N=N+1 else: N=N//2 cnt=cnt+1 return cnt , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments. Constraints:- 1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:- 3 4 5 Sample Output:- 4 Sample Input:- 3 4 4 Sample Output:- 3, I have written this Solution Code: def Average(A,B,C): return (A+B+C)//3 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments. Constraints:- 1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:- 3 4 5 Sample Output:- 4 Sample Input:- 3 4 4 Sample Output:- 3, I have written this Solution Code: int Average(int A,int B, int C){ return (A+B+C)/3; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments. Constraints:- 1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:- 3 4 5 Sample Output:- 4 Sample Input:- 3 4 4 Sample Output:- 3, I have written this Solution Code: static int Average(int A,int B, int C){ return (A+B+C)/3; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments. Constraints:- 1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:- 3 4 5 Sample Output:- 4 Sample Input:- 3 4 4 Sample Output:- 3, I have written this Solution Code: int Average(int A,int B, int C){ return (A+B+C)/3; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b> Complete the function <b>LeapYear()</b> that takes integer n as a parameter. <b>Constraint:</b> 1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: n = int(input()) if (n%4==0 and n%100!=0 or n%400==0): print("YES") elif n==0: print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b> Complete the function <b>LeapYear()</b> that takes integer n as a parameter. <b>Constraint:</b> 1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int n = scanner.nextInt(); LeapYear(n); } static void LeapYear(int year){ if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");} else { System.out.println("NO");} } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: 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: 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: You have been given a graph consisting of N nodes and M edges. The nodes in this graph are enumerated from 1 to N . The graph can consist of self-loops as well as multiple edges. This graph consists of a special node called the head node. You need to consider this and the entry point of this graph. You need to find and print the number of nodes that are unreachable from this head node. (Using DFS)The first line consists of a 2 integers N and M denoting the number of nodes and edges in this graph. The next M lines consist of 2 integers a and b denoting an undirected edge between node a and b. The next line consists of a single integer x denoting the index of the head node. Constraints 1<=N=100000 1<=M<=100000 1<=x<=NYou need to print a single integer denoting the number of nodes that are unreachable from the given head node. Sample Input: 10 10 8 1 8 3 7 4 7 5 2 6 10 7 2 8 10 9 2 10 5 10 2 Sample Output : 0 Explanation : As from node 2 we can reach all vertices. Unreachable vertices are zero., 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)); ArrayList<ArrayList<Integer>>list=new ArrayList<>(); String str[] = br.readLine().trim().split(" "); int v = Integer.parseInt(str[0]); int e = Integer.parseInt(str[1]); for(int i=0;i<=v;i++) { list.add(i,new ArrayList<>()); } for(int i=0;i<e;i++) { String st[] = br.readLine().trim().split(" "); int s = Integer.parseInt(st[0]); int d = Integer.parseInt(st[1]); list.get(s).add(d); list.get(d).add(s); } String stp[] = br.readLine().trim().split(" "); int head=Integer.parseInt(stp[0]); boolean visit[]=new boolean[v+1]; for(int i=0;i<=v;i++) { visit[i]=false; } long count=0; dfs(list,visit,head); for(int i=0;i<=v;i++) { if(visit[i]==false) { count++; } } System.out.println(count-1); } static void dfs(ArrayList<ArrayList<Integer>>list,boolean visi[],int k) { visi[k]=true; Iterator<Integer> i = list.get(k).listIterator(); while (i.hasNext()) { int n = i.next(); if (!visi[n]) dfs(list,visi,n); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have been given a graph consisting of N nodes and M edges. The nodes in this graph are enumerated from 1 to N . The graph can consist of self-loops as well as multiple edges. This graph consists of a special node called the head node. You need to consider this and the entry point of this graph. You need to find and print the number of nodes that are unreachable from this head node. (Using DFS)The first line consists of a 2 integers N and M denoting the number of nodes and edges in this graph. The next M lines consist of 2 integers a and b denoting an undirected edge between node a and b. The next line consists of a single integer x denoting the index of the head node. Constraints 1<=N=100000 1<=M<=100000 1<=x<=NYou need to print a single integer denoting the number of nodes that are unreachable from the given head node. Sample Input: 10 10 8 1 8 3 7 4 7 5 2 6 10 7 2 8 10 9 2 10 5 10 2 Sample Output : 0 Explanation : As from node 2 we can reach all vertices. Unreachable vertices are zero., I have written this Solution Code: def dfs(grapg,s): stack=[] visited={} for v in grapg: visited[v]=0 stack.append(s) visited[s]=1 while(stack): s=stack.pop(-1) if(s in visited): visited[s]=1 for i in grapg[s]: if(visited[str(i)]==0): stack.append(i) visited[i]=1 count=0 for i in visited: if(visited[i]==1): count+=1 return count dic={} n,m=input().split() n=int(n) m=int(m) for i in range(0,m): a,b=input().split() if(a not in dic): dic[a]=[b] else: dic[a].append(b) if(b not in dic): dic[b]=[a] else: dic[b].append(a) s=input() ans=dfs(dic,s) print(n-ans), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have been given a graph consisting of N nodes and M edges. The nodes in this graph are enumerated from 1 to N . The graph can consist of self-loops as well as multiple edges. This graph consists of a special node called the head node. You need to consider this and the entry point of this graph. You need to find and print the number of nodes that are unreachable from this head node. (Using DFS)The first line consists of a 2 integers N and M denoting the number of nodes and edges in this graph. The next M lines consist of 2 integers a and b denoting an undirected edge between node a and b. The next line consists of a single integer x denoting the index of the head node. Constraints 1<=N=100000 1<=M<=100000 1<=x<=NYou need to print a single integer denoting the number of nodes that are unreachable from the given head node. Sample Input: 10 10 8 1 8 3 7 4 7 5 2 6 10 7 2 8 10 9 2 10 5 10 2 Sample Output : 0 Explanation : As from node 2 we can reach all vertices. Unreachable vertices are zero., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define pu push_back #define fi first #define se second #define mp make_pair #define int long long #define pii pair<int,int> #define mm (s+e)/2 #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define sz 200000 int vis[sz]; int cnt=0; vector<int> NEB[sz]; void dfs(int s) { vis[s]=1; cnt++; for(auto it:NEB[s]) { if(vis[it]==0) { dfs(it); } } } signed main() { int n,m; cin>>n>>m; for(int i=0;i<m;i++) { int a,b; cin>>a>>b; NEB[a].pu(b); NEB[b].pu(a); } int x; cin>>x; dfs(x); cout<<n-cnt; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is an array having unique elements is given as input. Find the index of an element k if present in the array, else -1.There is an integer n is given(size of array nums). In second line, n space seperated integers are given. in third line, an integer k is given. 1 <= n <= 10<sup>5</sup> 0 <= nums[i] <= 10<sup>6</sup> 0 <= i <= n-1Find the index of an element k if present in the array, else -1.Sample Input: 5 1 4 3 2 5 3 Sample Output: 2 Explanation: Index of element 3 is 2. So the answer will be 2., I have written this Solution Code: import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n = sc.nextInt(); ArrayList<Integer> v=new ArrayList<>(); for(int i=0;i<n;i++){ int a=sc.nextInt(); v.add(a); } int k=sc.nextInt(); int ans=v.indexOf(k); System.out.println(ans); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces. Constraints:- 1 <= A, B, V <= 1000 Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan. Note:- Remember Distance can not be negativeSample Input:- 5 2 3 Sample Output:- 1 Explanation:- Distance = 5-2 = 3, Speed = 3 Time = Distance/Speed Sample Input:- 9 1 2 Sample Output:- 4, I have written this Solution Code: a, b, v = map(int, input().strip().split(" ")) c = abs(a-b) t = c//v print(t), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces. Constraints:- 1 <= A, B, V <= 1000 Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan. Note:- Remember Distance can not be negativeSample Input:- 5 2 3 Sample Output:- 1 Explanation:- Distance = 5-2 = 3, Speed = 3 Time = Distance/Speed Sample Input:- 9 1 2 Sample Output:- 4, I have written this Solution Code: /* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); System.out.print(Time(n,m,k)); } static int Time(int A, int B, int S){ if(B>A){ return (B-A)/S; } return (A-B)/S; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and an integer N, your task is to print the sum of it's first N terms. Series:- 3, 5, 9, 17, 33.<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>SeriesSum()</b> that takes the integer N as parameter. <b>Constraints:</b> 1 <= N <= 20Return the sum of N terms.Sample Input:- 3 Sample Output:- 17 Sample Input:- 2 Sample Output:- 8, I have written this Solution Code: int SeriesSum(int N){ int n=1; int ans=3; int res=3; for(int i=1;i<N;i++){ n*=2; res+=n; ans+=res; } return ans; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and an integer N, your task is to print the sum of it's first N terms. Series:- 3, 5, 9, 17, 33.<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>SeriesSum()</b> that takes the integer N as parameter. <b>Constraints:</b> 1 <= N <= 20Return the sum of N terms.Sample Input:- 3 Sample Output:- 17 Sample Input:- 2 Sample Output:- 8, I have written this Solution Code: int SeriesSum(int N){ int n=1; int ans=3; int res=3; for(int i=1;i<N;i++){ n*=2; res+=n; ans+=res; } return ans; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and an integer N, your task is to print the sum of it's first N terms. Series:- 3, 5, 9, 17, 33.<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>SeriesSum()</b> that takes the integer N as parameter. <b>Constraints:</b> 1 <= N <= 20Return the sum of N terms.Sample Input:- 3 Sample Output:- 17 Sample Input:- 2 Sample Output:- 8, I have written this Solution Code: static int SeriesSum(int N){ int n=1; int ans=3; int res=3; for(int i=1;i<N;i++){ n*=2; res+=n; ans+=res; } return ans; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and an integer N, your task is to print the sum of it's first N terms. Series:- 3, 5, 9, 17, 33.<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>SeriesSum()</b> that takes the integer N as parameter. <b>Constraints:</b> 1 <= N <= 20Return the sum of N terms.Sample Input:- 3 Sample Output:- 17 Sample Input:- 2 Sample Output:- 8, I have written this Solution Code: def SeriesSum(N): n=1 res=3 ans=3 for i in range (1,N): n=n*2 res=res+n ans=ans+res return ans , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b> Complete the function <b>LeapYear()</b> that takes integer n as a parameter. <b>Constraint:</b> 1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: n = int(input()) if (n%4==0 and n%100!=0 or n%400==0): print("YES") elif n==0: print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b> Complete the function <b>LeapYear()</b> that takes integer n as a parameter. <b>Constraint:</b> 1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int n = scanner.nextInt(); LeapYear(n); } static void LeapYear(int year){ if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");} else { System.out.println("NO");} } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<b>User Task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>quickSort()</b> which contains following arguments. <b>A[]:</b> input array <b>start:</b> starting index of array <b>end</b>: ending index of array Constraints 1 <= T <= 1000 1 <= N <= 10^4 1 <= A[i] <= 10^5 <b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.Sample Input: 2 3 3 1 2 3 4 5 6 Sample Output: 1 2 3 4 5 6, I have written this Solution Code: def partition(array, low, high): pivot = array[high] i = low - 1 for j in range(low, high): if array[j] <= pivot: i = i + 1 (array[i], array[j]) = (array[j], array[i]) (array[i + 1], array[high]) = (array[high], array[i + 1]) return i + 1 def quick_sort(array, low, high): if low < high: pi = partition(array, low, high) quick_sort(array, low, pi - 1) quick_sort(array, pi + 1, high) t=int(input()) for i in range(t): n=int(input()) a=input().strip().split() a=[int(i) for i in a] quick_sort(a, 0, n - 1) for i in a: print(i,end=" ") print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<b>User Task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>quickSort()</b> which contains following arguments. <b>A[]:</b> input array <b>start:</b> starting index of array <b>end</b>: ending index of array Constraints 1 <= T <= 1000 1 <= N <= 10^4 1 <= A[i] <= 10^5 <b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.Sample Input: 2 3 3 1 2 3 4 5 6 Sample Output: 1 2 3 4 5 6, I have written this Solution Code: public static int[] quickSort(int arr[], int low, int high) { if (low < high) { /* pi is partitioning index, arr[pi] is now at right place */ int pi = partition(arr, low, high); // Recursively sort elements before // partition and after partition quickSort(arr, low, pi-1); quickSort(arr, pi+1, high); } return arr; } public static int partition(int arr[], int low, int high) { int pivot = arr[high]; int i = (low-1); // index of smaller element for (int j=low; j<high; j++) { // If current element is smaller than the pivot if (arr[j] < pivot) { i++; // swap arr[i] and arr[j] int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } // swap arr[i+1] and arr[high] (or pivot) int temp = arr[i+1]; arr[i+1] = arr[high]; arr[high] = temp; return i+1; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable