Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem. Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d. <b>Constraints</b> 1<= a, b, c, d <= 100 Print single line containing the percentage.Sample Input 1: 25 25 25 25 Sample Output 1: 25 Sample Input 2: 75 25 75 25 Sample Output 2: 50, 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)); String str[]=br.readLine().split(" "); int a[]=new int[str.length]; int sum=0; for(int i=0;i<str.length;i++) { a[i]=Integer.parseInt(str[i]); sum=sum+a[i]; } System.out.println(sum/4); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem. Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d. <b>Constraints</b> 1<= a, b, c, d <= 100 Print single line containing the percentage.Sample Input 1: 25 25 25 25 Sample Output 1: 25 Sample Input 2: 75 25 75 25 Sample Output 2: 50, I have written this Solution Code: a,b,c,d = map(int,input().split()) print((a+b+c+d)*100//400), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s=br.readLine().toString(); int n=Integer.parseInt(s); int ch=0; if(n>0){ ch=1; } else if(n<0) ch=-1; switch(ch){ case 1: System.out.println("Positive");break; case 0: System.out.println("Zero");break; case -1: System.out.println("Negative");break; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: n = input() if '-' in list(n): print('Negative') elif int(n) == 0 : print('Zero') else: print('Positive'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: #include <stdio.h> int main() { int num; scanf("%d", &num); switch (num > 0) { // Num is positive case 1: printf("Positive"); break; // Num is either negative or zero case 0: switch (num < 0) { case 1: printf("Negative"); break; case 0: printf("Zero"); break; } break; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies. In the first move Joey has to give Chandler 1 candy. In the second move Chandler has to give Joey 2 candies. In the third move Joey has to give Chandler 3 candies. In the fourth move Chandler has to give Joey 4 candies. In the fifth move Joey has to give Chandler 5 candy. ... and so on. The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B. Constraints: 0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input 2 1 Sample Output Chandler Explanation: In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0. In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2. In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); String s[]=bu.readLine().split(" "); long a=Long.parseLong(s[0]),b=Long.parseLong(s[1]); if(a>=b) sb.append("Chandler"); else sb.append("Joey"); System.out.print(sb); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies. In the first move Joey has to give Chandler 1 candy. In the second move Chandler has to give Joey 2 candies. In the third move Joey has to give Chandler 3 candies. In the fourth move Chandler has to give Joey 4 candies. In the fifth move Joey has to give Chandler 5 candy. ... and so on. The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B. Constraints: 0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input 2 1 Sample Output Chandler Explanation: In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0. In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2. In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// template<class C> void mini(C&a4, C b4){a4=min(a4,b4);} typedef unsigned long long ull; auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define mod 1000000007ll #define pii pair<int,int> ///////////// signed main(){ #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int a,b; cin>>a>>b; if(a>=b) cout<<"Chandler"; else cout<<"Joey"; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies. In the first move Joey has to give Chandler 1 candy. In the second move Chandler has to give Joey 2 candies. In the third move Joey has to give Chandler 3 candies. In the fourth move Chandler has to give Joey 4 candies. In the fifth move Joey has to give Chandler 5 candy. ... and so on. The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B. Constraints: 0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input 2 1 Sample Output Chandler Explanation: In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0. In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2. In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: ch,jo=map(int,input().split()) if ch>=jo: print('Chandler') else: print('Joey'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: function LeapYear(year){ // write code here // return the output using return keyword // do not use console.log here if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) { return 0; } else { return 1 } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: year = int(input()) if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0: print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int side = scanner.nextInt(); int area = LeapYear(side); if(area==1){ System.out.println("YES");} else{ System.out.println("NO");} } static int LeapYear(int year){ if(year%400==0){return 1;} if(year%100 != 0 && year%4==0){return 1;} else { return 0;} } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.Each test case have one line string S of character '(' and ')' of length N. Constraints: 1 <= N <= 10^5Print the length of the longest valid parenthesis substring.Input ((() Output 2 Input )()()) Output 4, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int n = s.length(); int left = 0, right = 0; int maxlength = 0; for(int i = 0; i < n; i++) { if (s.charAt(i) == '(') left++; else right++; if (left == right) maxlength = Math.max(maxlength, 2 * right); else if (right > left) left = right = 0; } left = right = 0; for(int i = n - 1; i >= 0; i--) { if (s.charAt(i) == '(') left++; else right++; if (left == right) maxlength = Math.max(maxlength, 2 * left); else if (left > right) left = right = 0; } System.out.println(maxlength); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.Each test case have one line string S of character '(' and ')' of length N. Constraints: 1 <= N <= 10^5Print the length of the longest valid parenthesis substring.Input ((() Output 2 Input )()()) Output 4, I have written this Solution Code: def longestValidParentheses( S): stack, ans = [-1], 0 for i in range(len(S)): if S[i] == '(': stack.append(i) elif len(stack) == 1: stack[0] = i else: stack.pop() ans = max(ans, i - stack[-1]) return ans n=input() print(longestValidParentheses(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.Each test case have one line string S of character '(' and ')' of length N. Constraints: 1 <= N <= 10^5Print the length of the longest valid parenthesis substring.Input ((() Output 2 Input )()()) Output 4, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; string s; cin >> s; int n = s.length(); s = "#" + s; stack<int> st; st.push(0); int ans = 0; for(int i = 1; i <= n; i++){ if(s[i] == '(') st.push(i); else{ if(s[st.top()] == '('){ int x = st.top(); a[i] = i-x+1 + a[x-1]; ans = max(ans, a[i]); st.pop(); } else st.push(i); } } cout << ans; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a String <b>S</b>, you need to typecast this String to Long. If the typecasting is done successfully then we will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>checkConvertion()</b>, which contains S as a parameter. <b>Constraints:-</b> 1 <= |S| <= 15 The string will contain only numeric digits(1-9)You need to return the typecasted Long value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>". <b>Note:-</b> We are not converting this string to int here because the size of the number exceeds the int limits.Sample Input 1:- 43 Sample Output 1:- Nice Job Sample Input 2:- 2584563259874 Sample Output 2:- Nice Job, I have written this Solution Code: def checkConevrtion(a): return int(a) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a String <b>S</b>, you need to typecast this String to Long. If the typecasting is done successfully then we will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>checkConvertion()</b>, which contains S as a parameter. <b>Constraints:-</b> 1 <= |S| <= 15 The string will contain only numeric digits(1-9)You need to return the typecasted Long value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>". <b>Note:-</b> We are not converting this string to int here because the size of the number exceeds the int limits.Sample Input 1:- 43 Sample Output 1:- Nice Job Sample Input 2:- 2584563259874 Sample Output 2:- Nice Job, I have written this Solution Code: static long checkConevrtion(String S) { return Long.parseLong(S); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of integers, find the number of subarrays with an odd sum.First line contains an integers N. Next line contains N space separated integers denoting elements of array. Constraints 1 <= N <= 10^5 1 <= Ai <= 10^5Print the number of subarrays with an odd sum.Sample Input 1: 3 1 3 5 Output 4 Explanation: All subarrays are [1], [1, 3], [1, 3, 5], [3], [3, 5], [5] All sub- arrays sum are [1, 4, 9, 3, 8, 5]. Odd sums are [1, 9, 3, 5] so the answer is 4. Sample Input 2: 3 2 4 6 Output 0 Explanation: All subarrays are [2], [2, 4], [2, 4, 6], [4], [4, 6], [6] All sub- arrays sum are [2, 6, 12, 4, 10, 6]. All sub- arrays have even sum and the answer is 0., I have written this Solution Code: def countOddSum(a, n): # 'odd' stores number of # odd numbers upto ith index # 'c_odd' stores number of # odd sum subarrays starting # at ith index # 'Result' stores the number # of odd sum subarrays c_odd = 0; result = 0; odd = False; # First find number of odd # sum subarrays starting at # 0th index for i in range(n): if (a[i] % 2 == 1): if(odd == True): odd = False; else: odd = True; if (odd): c_odd += 1; # Find number of odd sum # subarrays starting at ith # index add to result for i in range(n): result += c_odd; if (a[i] % 2 == 1): c_odd = (n - i - c_odd); return result; n=int(input()) arr=list(map(int,input().strip().split()))[:n] print(countOddSum(arr,n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of integers, find the number of subarrays with an odd sum.First line contains an integers N. Next line contains N space separated integers denoting elements of array. Constraints 1 <= N <= 10^5 1 <= Ai <= 10^5Print the number of subarrays with an odd sum.Sample Input 1: 3 1 3 5 Output 4 Explanation: All subarrays are [1], [1, 3], [1, 3, 5], [3], [3, 5], [5] All sub- arrays sum are [1, 4, 9, 3, 8, 5]. Odd sums are [1, 9, 3, 5] so the answer is 4. Sample Input 2: 3 2 4 6 Output 0 Explanation: All subarrays are [2], [2, 4], [2, 4, 6], [4], [4, 6], [6] All sub- arrays sum are [2, 6, 12, 4, 10, 6]. All sub- arrays have even sum and the answer is 0., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String args[]) throws IOException { BufferedReader br = new BufferedReader (new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); long a[] = new long[n]; String line = br.readLine(); // to read multiple integers line String[] strs = line.trim().split("\\s+"); for (int i = 0; i < n; i++) { a[i] = Long.parseLong(strs[i]); } long[] prefix=new long[n]; prefix[0]=a[0]; for(int i=1;i<n;i++){ prefix[i]=prefix[i-1]+a[i]; } long e=1; long o=0; for(int i=0;i<n;i++){ if(prefix[i]%2==0)e++; else o++; } e*=o; System.out.print(e); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: 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 a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: static void pattern(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ System.out.print(j + " "); } System.out.println(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: void patternPrinting(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ printf("%d ",j); } printf("\n"); } } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: function pattern(n) { // write code herenum for(let i = 1;i<=n;i++){ let str = '' for(let k = 1; k <= i;k++){ if(k === 1) { str += `${k}` }else{ str += ` ${k}` } } console.log(str) } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: void patternPrinting(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ printf("%d ",j); } printf("\n"); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: def patternPrinting(n): for i in range(1,n+1): for j in range (1,i+1): print(j,end=' ') print() , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: int RotationPolicy(int A, int B){ int cnt=0; for(int i=A;i<=B;i++){ if((i-1)%2!=0 && (i-1)%3!=0){cnt++;} } return cnt; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: int RotationPolicy(int A, int B){ int cnt=0; for(int i=A;i<=B;i++){ if((i-1)%2!=0 && (i-1)%3!=0){cnt++;} } return cnt; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: static int RotationPolicy(int A, int B){ int cnt=0; for(int i=A;i<=B;i++){ if((i-1)%2!=0 && (i-1)%3!=0){cnt++;} } return cnt; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: def RotationPolicy(A, B): cnt=0 for i in range (A,B+1): if(i-1)%2!=0 and (i-1)%3!=0: cnt=cnt+1 return cnt , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: function RotationPolicy(a, b) { // write code here // do no console.log the answer // return the output using return keyword let count = 0 for (let i = a; i <= b; i++) { if((i-1)%2 !== 0 && (i-1)%3 !==0){ count++ } } return count } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Calculate inversion count of array of integers. Inversion count of an array is quantisation of how much unsorted an array is. A sorted array has inversion count 0, while an unsorted array has maximum inversion count. Formally speaking inversion count = number of pairs i, j such that i < j and a[i] > a[j].The first line contain integers N. The second line of the input contains N singly spaces integers. 1 <= N <= 100000 1 <= A[i] <= 1000000000Output one integer the inversion count.Sample Input 5 1 1 3 2 2 Sample Output 2 Sample Input 5 5 4 3 2 1 Sample Output 10, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static long count(int[] arr, int l, int h, int[] aux) { if (l >= h) return 0; int mid = (l +h) / 2; long count = 0; count += count(aux, l, mid, arr); count += count(aux, mid + 1, h, arr); count += merge(arr, l, mid, h, aux); return count; } static long merge(int[] arr, int l, int mid, int h, int[] aux) { long count = 0; int i = l, j = mid + 1, k = l; while (i <= mid || j <= h) { if (i > mid) { arr[k++] = aux[j++]; } else if (j > h) { arr[k++] = aux[i++]; } else if (aux[i] <= aux[j]) { arr[k++] = aux[i++]; } else { arr[k++] = aux[j++]; count += mid + 1 - i; } } return count; } public static void main (String[] args)throws IOException { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); String str[]; str = br.readLine().split(" "); int n = Integer.parseInt(str[0]); str = br.readLine().split(" "); int arr[] =new int[n]; for (int j = 0; j < n; j++) { arr[j] = Integer.parseInt(str[j]); } int[] aux = arr.clone(); System.out.print(count(arr, 0, n - 1, aux)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Calculate inversion count of array of integers. Inversion count of an array is quantisation of how much unsorted an array is. A sorted array has inversion count 0, while an unsorted array has maximum inversion count. Formally speaking inversion count = number of pairs i, j such that i < j and a[i] > a[j].The first line contain integers N. The second line of the input contains N singly spaces integers. 1 <= N <= 100000 1 <= A[i] <= 1000000000Output one integer the inversion count.Sample Input 5 1 1 3 2 2 Sample Output 2 Sample Input 5 5 4 3 2 1 Sample Output 10, I have written this Solution Code: count=0 def implementMergeSort(arr,s,e): global count if e-s==1: return mid=(s+e)//2 implementMergeSort(arr,s,mid) implementMergeSort(arr,mid,e) count+=merge_sort_place(arr,s,mid,e) return count def merge_sort_place(arr,s,mid,e): arr3=[] i=s j=mid count=0 while i<mid and j<e: if arr[i]>arr[j]: arr3.append(arr[j]) j+=1 count+=(mid-i) else: arr3.append(arr[i]) i+=1 while (i<mid): arr3.append(arr[i]) i+=1 while (j<e): arr3.append(arr[j]) j+=1 for x in range(len(arr3)): arr[s+x]=arr3[x] return count n=int(input()) arr=list(map(int,input().split()[:n])) c=implementMergeSort(arr,0,len(arr)) print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Calculate inversion count of array of integers. Inversion count of an array is quantisation of how much unsorted an array is. A sorted array has inversion count 0, while an unsorted array has maximum inversion count. Formally speaking inversion count = number of pairs i, j such that i < j and a[i] > a[j].The first line contain integers N. The second line of the input contains N singly spaces integers. 1 <= N <= 100000 1 <= A[i] <= 1000000000Output one integer the inversion count.Sample Input 5 1 1 3 2 2 Sample Output 2 Sample Input 5 5 4 3 2 1 Sample Output 10, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; long long _mergeSort(long long arr[], int temp[], int left, int right); long long merge(long long arr[], int temp[], int left, int mid, int right); /* This function sorts the input array and returns the number of inversions in the array */ long long mergeSort(long long arr[], int array_size) { int temp[array_size]; return _mergeSort(arr, temp, 0, array_size - 1); } /* An auxiliary recursive function that sorts the input array and returns the number of inversions in the array. */ long long _mergeSort(long long arr[], int temp[], int left, int right) { long long mid, inv_count = 0; if (right > left) { /* Divide the array into two parts and call _mergeSortAndCountInv() for each of the parts */ mid = (right + left) / 2; /* Inversion count will be sum of inversions in left-part, right-part and number of inversions in merging */ inv_count += _mergeSort(arr, temp, left, mid); inv_count += _mergeSort(arr, temp, mid + 1, right); /*Merge the two parts*/ inv_count += merge(arr, temp, left, mid + 1, right); } return inv_count; } /* This funt merges two sorted arrays and returns inversion count in the arrays.*/ long long merge(long long arr[], int temp[], int left, int mid, int right) { int i, j, k; long long inv_count = 0; i = left; /* i is index for left subarray*/ j = mid; /* j is index for right subarray*/ k = left; /* k is index for resultant merged subarray*/ while ((i <= mid - 1) && (j <= right)) { if (arr[i] <= arr[j]) { temp[k++] = arr[i++]; } else { temp[k++] = arr[j++]; /* this is tricky -- see above explanation/diagram for merge()*/ inv_count = inv_count + (mid - i); } } /* Copy the remaining elements of left subarray (if there are any) to temp*/ while (i <= mid - 1) temp[k++] = arr[i++]; /* Copy the remaining elements of right subarray (if there are any) to temp*/ while (j <= right) temp[k++] = arr[j++]; /*Copy back the merged elements to original array*/ for (i = left; i <= right; i++) arr[i] = temp[i]; return inv_count;} int main(){ int n; cin>>n; long long a[n]; for(int i=0;i<n;i++){ cin>>a[i];} long long ans = mergeSort(a, n); cout << ans; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a 2D matrix of size [M, N], Q number of queries. In each query, you will be given a number X to check whether it is present in the matrix or not.The first line contains three integers M(number of rows), N(Number of columns), and Q(number of queries) Next M lines contain N integers which are the elements of the matrix. Next, Q lines will contain a single integer X. Constraints:- 1<=M,N<=1000 1<=Q<=10000 1<=X, Arr[i]<=1000000000For each query, in a new line print "Yes" if the element is present in matrix or print "No" if the element is absent.Input:- 3 3 2 1 2 3 5 6 7 8 9 10 7 11 Output:- Yes No Input:- 3 4 4 4 8 11 14 15 54 45 47 1 2 3 4 5 15 45 26 Output:- No Yes Yes No, I have written this Solution Code: import java.io.*; // for handling input/output import java.util.*; // contains Collections framework // don't change the name of this class // you can add inner classes if needed class Main { public static void main (String[] args) { // Your code here Scanner sc = new Scanner(System.in); int m = sc.nextInt(); int n = sc.nextInt(); int q = sc.nextInt(); int mat[] = new int[m*n]; int matSize = m*n; for(int i = 0; i < m*n; i++) { int ele = sc.nextInt(); mat[i] = ele; } Arrays.sort(mat); for(int i = 1; i <= q; i++) { int qs = sc.nextInt(); System.out.println(isPresent(mat, matSize, qs)); } } static String isPresent(int mat[], int size, int ele) { int l = 0, h = size-1; while(l <= h) { int mid = l + (h-l)/2; if(mat[mid] == ele) return "Yes"; else if(mat[mid] > ele) h = mid - 1; else l = mid+1; } return "No"; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a 2D matrix of size [M, N], Q number of queries. In each query, you will be given a number X to check whether it is present in the matrix or not.The first line contains three integers M(number of rows), N(Number of columns), and Q(number of queries) Next M lines contain N integers which are the elements of the matrix. Next, Q lines will contain a single integer X. Constraints:- 1<=M,N<=1000 1<=Q<=10000 1<=X, Arr[i]<=1000000000For each query, in a new line print "Yes" if the element is present in matrix or print "No" if the element is absent.Input:- 3 3 2 1 2 3 5 6 7 8 9 10 7 11 Output:- Yes No Input:- 3 4 4 4 8 11 14 15 54 45 47 1 2 3 4 5 15 45 26 Output:- No Yes Yes No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define N 1000000 long a[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,q; cin>>n>>m>>q; n=n*m; long long sum=0,sum1=0; for(int i=0;i<n;i++){ cin>>a[i]; } sort(a,a+n); while(q--){ long x; cin>>x; int l=0; int r=n-1; while (r >= l) { int mid = l + (r - l) / 2; if (a[mid] == x) { cout<<"Yes"<<endl;goto f;} if (a[mid] > x) { r=mid-1; } else {l=mid+1; } } cout<<"No"<<endl; f:; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a cubic dice with 6 faces. All the individual faces have a numbers printed on them. The numbers are in the range of 1 to 6, like any ordinary dice. Given a number on one face of the dice , you need to print the number on the opposite face . NOTE : In a normal dice sum of numbers on opposite faces is 7 .The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each test case contains a single line of the input containing a positive integer N. Constraints: 1 <= T <= 100 1 <= N <= 6For each testcase, print the number that is on the opposite side of the given face.Input: 2 6 2 Output: 1 5 Explanation: Testcase 1: For dice facing number 6 opposite face will have the number 1., I have written this Solution Code: def get_opposite_face(n): return 7-n t = int(input()) for n in range(t): print(get_opposite_face(int(input()))), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a cubic dice with 6 faces. All the individual faces have a numbers printed on them. The numbers are in the range of 1 to 6, like any ordinary dice. Given a number on one face of the dice , you need to print the number on the opposite face . NOTE : In a normal dice sum of numbers on opposite faces is 7 .The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each test case contains a single line of the input containing a positive integer N. Constraints: 1 <= T <= 100 1 <= N <= 6For each testcase, print the number that is on the opposite side of the given face.Input: 2 6 2 Output: 1 5 Explanation: Testcase 1: For dice facing number 6 opposite face will have the number 1., I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; signed main() { IOS; int t; cin >> t; while(t--){ int n; cin >> n; cout << 7-n << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a cubic dice with 6 faces. All the individual faces have a numbers printed on them. The numbers are in the range of 1 to 6, like any ordinary dice. Given a number on one face of the dice , you need to print the number on the opposite face . NOTE : In a normal dice sum of numbers on opposite faces is 7 .The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each test case contains a single line of the input containing a positive integer N. Constraints: 1 <= T <= 100 1 <= N <= 6For each testcase, print the number that is on the opposite side of the given face.Input: 2 6 2 Output: 1 5 Explanation: Testcase 1: For dice facing number 6 opposite face will have the number 1., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t-->0){ int n=Integer.parseInt(br.readLine()); System.out.println(6-n+1); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N Books B[], where B[i] denotes the number of pages P in i'th book. Now you need to find the maximum number of distinct books (having a different number of pages) after removing K books from the array.The input line contains T, denoting the number of testcases. Each testcase contains two lines. First line contains N, number of books and K, number of books you need to remove. Second line contains N positive integers denoting the number of pages in ith book. Constraints: 1 <= T <= 100 1 <= N <= 10^4 1 <= K <= N 1 <= B[i] <= 10^4You need to print the maximum number of distinct books.Sample Input: 2 7 3 5 7 5 5 1 2 2 6 4 1 2 3 4 5 6 Sample Output: 4 2 Explanation: Testcase 1: Remove 2 occurrences of books having 5 pages and 1 occurrence of book having 2 pages., I have written this Solution Code: import java.util.*; import java.io.*; class Main{ static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static void main(String[] args) throws IOException { Reader sc = new Reader(); int t = sc.nextInt(); while (t-->0) { HashMap<Integer,Integer> map = new HashMap<>(); int n = sc.nextInt(); int k = sc.nextInt(); for (int i = 0; i < n; i++) { int v = sc.nextInt(); map.put(v, map.getOrDefault(v, 0)+1); } int maxRemove = 0; for (Integer integer : map.keySet()) { maxRemove += map.get(integer) -1; } if (k<=maxRemove) { System.out.println(map.size()); }else{ System.out.println(map.size() - (k-maxRemove)); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N Books B[], where B[i] denotes the number of pages P in i'th book. Now you need to find the maximum number of distinct books (having a different number of pages) after removing K books from the array.The input line contains T, denoting the number of testcases. Each testcase contains two lines. First line contains N, number of books and K, number of books you need to remove. Second line contains N positive integers denoting the number of pages in ith book. Constraints: 1 <= T <= 100 1 <= N <= 10^4 1 <= K <= N 1 <= B[i] <= 10^4You need to print the maximum number of distinct books.Sample Input: 2 7 3 5 7 5 5 1 2 2 6 4 1 2 3 4 5 6 Sample Output: 4 2 Explanation: Testcase 1: Remove 2 occurrences of books having 5 pages and 1 occurrence of book having 2 pages., I have written this Solution Code: t=int(input()) for m in range(0,t): n,k=input().split() n=int(n) k=int(k) arr=input().split() hm={} temp=k dictinct=0 for i in range(0,n): arr[i]=int(arr[i]) if(arr[i] not in hm): hm[arr[i]]=1 else: k-=1 dictinct+=1 if(k>0): print (len(hm)-k) else: print (len(hm)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N Books B[], where B[i] denotes the number of pages P in i'th book. Now you need to find the maximum number of distinct books (having a different number of pages) after removing K books from the array.The input line contains T, denoting the number of testcases. Each testcase contains two lines. First line contains N, number of books and K, number of books you need to remove. Second line contains N positive integers denoting the number of pages in ith book. Constraints: 1 <= T <= 100 1 <= N <= 10^4 1 <= K <= N 1 <= B[i] <= 10^4You need to print the maximum number of distinct books.Sample Input: 2 7 3 5 7 5 5 1 2 2 6 4 1 2 3 4 5 6 Sample Output: 4 2 Explanation: Testcase 1: Remove 2 occurrences of books having 5 pages and 1 occurrence of book having 2 pages., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define max1 1000001 int a[max1]; int main(){ int t; cin>>t; while(t--){ int n,k; cin>>n>>k; int arr; map<int,int> m; int cnt=0; for(int i=0;i<n;i++){ cin>>arr; if(m.find(arr)!=m.end()){cnt++;} m[arr]++; } if(k<=cnt){cout<<m.size()<<endl;} else{cout<<m.size()-(k-cnt)<<endl;} } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is Armstrong number or not. <b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isArmstrong()</b> which contains N as a parameter. Constraints: 1 <= N <= 10^4You need to return "True" if the given number is an Armstrong number otherwise "False"Sample Input: 1 Sample Output: true Explanation: 1<sup>3</sup> = 1 Sample Input: 147 Sample Output: false Explanation: 1<sup>3</sup> + 4<sup>3</sup> + 7<sup>3</sup> != 147, I have written this Solution Code: def isArmstrong(N): w=N ans=0 while w>0: x=w%10 ans=ans+x**3 w=int(w//10) res=ans==N return res , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:- For each multiple of 3, print "Fizz" instead of the number. For each multiple of 5, print "Buzz" instead of the number. For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N. <b>Constraints:-</b> 1 &le; N &le; 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:- 3 Sample Output:- 1 2 Fizz Sample Input:- 5 Sample Output:- 1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){ for(int i=1;i<=n;i++){ if(i%3==0 && i%5==0){cout<<"FizzBuzz"<<" ";} else if(i%5==0){cout<<"Buzz ";} else if(i%3==0){cout<<"Fizz ";} else{cout<<i<<" ";} } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:- For each multiple of 3, print "Fizz" instead of the number. For each multiple of 5, print "Buzz" instead of the number. For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N. <b>Constraints:-</b> 1 &le; N &le; 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:- 3 Sample Output:- 1 2 Fizz Sample Input:- 5 Sample Output:- 1 2 Fizz 4 Buzz, 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 x= sc.nextInt(); fizzbuzz(x); } static void fizzbuzz(int n){ for(int i=1;i<=n;i++){ if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");} else if(i%5==0){System.out.print("Buzz ");} else if(i%3==0){System.out.print("Fizz ");} else{System.out.print(i+" ");} } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:- For each multiple of 3, print "Fizz" instead of the number. For each multiple of 5, print "Buzz" instead of the number. For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N. <b>Constraints:-</b> 1 &le; N &le; 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:- 3 Sample Output:- 1 2 Fizz Sample Input:- 5 Sample Output:- 1 2 Fizz 4 Buzz, I have written this Solution Code: def fizzbuzz(n): for i in range (1,n+1): if (i%3==0 and i%5==0): print("FizzBuzz",end=' ') elif i%3==0: print("Fizz",end=' ') elif i%5==0: print("Buzz",end=' ') else: print(i,end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:- For each multiple of 3, print "Fizz" instead of the number. For each multiple of 5, print "Buzz" instead of the number. For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N. <b>Constraints:-</b> 1 &le; N &le; 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:- 3 Sample Output:- 1 2 Fizz Sample Input:- 5 Sample Output:- 1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){ for(int i=1;i<=n;i++){ if(i%3==0 && i%5==0){printf("FizzBuzz ");} else if(i%5==0){printf("Buzz ");} else if(i%3==0){printf("Fizz ");} else{printf("%d ",i);} } }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Print_Digit()</b> that takes integer N as a parameter. <b>Constraints:-</b> 1 &le; N &le; 10<sup>7</sup>Print the digits of the number as shown in the example. <b>Note:-</b> Print all digits in lowercase English lettersSample Input:- 1024 Sample Output:- one zero two four Sample Input:- 2 Sample Output:- two, I have written this Solution Code: def Print_Digit(n): dc = {1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 0: "zero"} final_list = [] while (n > 0): final_list.append(dc[int(n%10)]) n = int(n / 10) for val in final_list[::-1]: print(val, end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Print_Digit()</b> that takes integer N as a parameter. <b>Constraints:-</b> 1 &le; N &le; 10<sup>7</sup>Print the digits of the number as shown in the example. <b>Note:-</b> Print all digits in lowercase English lettersSample Input:- 1024 Sample Output:- one zero two four Sample Input:- 2 Sample Output:- two, I have written this Solution Code: class Solution { public static void Print_Digits(int N){ if(N==0){return;} Print_Digits(N/10); int x=N%10; if(x==1){System.out.print("one ");} else if(x==2){System.out.print("two ");} else if(x==3){System.out.print("three ");} else if(x==4){System.out.print("four ");} else if(x==5){System.out.print("five ");} else if(x==6){System.out.print("six ");} else if(x==7){System.out.print("seven ");} else if(x==8){System.out.print("eight ");} else if(x==9){System.out.print("nine ");} else if(x==0){System.out.print("zero ");} } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N. Print the value of PI with precision upto N decimal places.The only input line contains an integer N. Constraints: 1 <= N <= 10Print the value of PI.Sample Input 1: 4 Output: 3.1416 Sample Input 2: 10 Output: 3.1415926536, I have written this Solution Code: import java.io.*; import java.util.Scanner; class Main { public static void main (String[] args) { int n; Scanner s = new Scanner(System.in); n = s.nextInt(); if(n==1)System.out.printf("%.1f",Math.PI); else if(n==2)System.out.printf("%.2f",Math.PI); else if(n==3)System.out.printf("%.3f",Math.PI); else if(n==4)System.out.printf("%.4f",Math.PI); else if(n==5)System.out.printf("%.5f",Math.PI); else if(n==6)System.out.printf("%.6f",Math.PI); else if(n==7)System.out.printf("%.7f",Math.PI); else if(n==8)System.out.printf("%.8f",Math.PI); else if(n==9)System.out.printf("%.9f",Math.PI); else System.out.printf("%.10f",Math.PI); } }, 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 value of PI with precision upto N decimal places.The only input line contains an integer N. Constraints: 1 <= N <= 10Print the value of PI.Sample Input 1: 4 Output: 3.1416 Sample Input 2: 10 Output: 3.1415926536, I have written this Solution Code: n = int(input()) pi = 3.1415926536 print(round(pi, n)), 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: There are n rectangles of the same size: w in width and h in length. It is required to find a square of the smallest size into which these rectangles can be packed. Rectangles cannot be rotated.The first line of the input contains three space-separated integers w, h and n. <b>Constraints</b> 1 ≤ w, h, n ≤ 10<sup>9</sup>Output the minimum length of a side of a square, into which the given rectangles can be packed.Sample Input : 2 3 10 Sample Output: 9 <b>Explanation:</b> 9 is the minimum size of the square in which all these rectangles can fit. <img src = "https://d3dyfaf3iutrxo.cloudfront.net/general/upload/7aef090772524a368cf0cbe754a484a9.png"></img>, I have written this Solution Code: #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <class key, class value, class cmp = std::less<key>> using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; // find_by_order(k) returns iterator to kth element starting from 0; // order_of_key(k) returns count of elements strictly smaller than k; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 2351 #endif #define int long long mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int64_t random_long(int l = LLONG_MIN, int r = LLONG_MAX) { uniform_int_distribution<int64_t> generator(l, r); return generator(rng); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); auto start = std::chrono::high_resolution_clock::now(); int w, h, n; cin >> w >> h >> n; int l = 1, r = (int)1e18; while (l <= r) { int mid = l + (r - l) / 2; int x = mid / w; int y = mid / h; if ((y > 0 && x >= ((n - 1) / y + 1)) || (x > 0 && y >= ((n - 1) / x + 1))) { r = mid - 1; } else { l = mid + 1; } } cout << l << "\n"; auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); // cerr << "Time taken : " << ((long double)duration.count()) / ((long double)1e9) << "s " << endl; return 0; }; , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Tono is on her mission to spread happiness everywhere. She has N close friends. She wants to make them stand in a line. She knows the happiness of the i<sup>th</sup> friend will be A[i] if the friend is standing among the first C[i] people in the line, else it would be B[i]. Find the maximum happiness that Tono can have in the line if she can arrange her friends in any order.The first line of the input contains an integer N. The next N lines of the input contain three integers C[i], A[i], and B[i] denoting the parameters for the i<sup>th</sup> friend. Constraints 1 <= N <= 100000 1 <= C[i] <= N 1 <= L[i], R[i] <= 10<sup>9</sup>Output the maximum happiness that Tono can achieve in the line.Sample Input 3 2 93 78 1 71 59 3 57 96 Sample Output 221 Explanation The optimal order is [2, 1, 3]. The happiness of friend 1 = 93 (among the first 2 people), friend 2 = 71 (among the first 1 people), and friend 3 = 57 (among the first 3 people). Sample Input 2 1 5 10 2 15 5 Sample Output 25, I have written this Solution Code: import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int n = sc.nextInt(); Map<Integer, ArrayList<Camel>> map = new HashMap<>(); for (int i = 0; i < n; i++) map.put(i, new ArrayList<>()); Camel[] c = new Camel[n]; long base = 0; for (int i = 0; i < n; i++) { int split = sc.nextInt(); long l = sc.nextInt(); long r = sc.nextInt(); c[i] = new Camel(l - r, split - 1); map.get(c[i].split).add(c[i]); base += Math.min(l, r); } Arrays.sort(c, Comparator.comparingInt(a -> a.split)); PriorityQueue<Long> pq = new PriorityQueue<>(); for (int i = 0; i < n; i++) { for (Camel camel : map.get(i)) { if (camel.dif < 0) continue; pq.add(camel.dif); base += camel.dif; } while (pq.size() > i + 1) { long bestRemove = pq.poll(); base -= bestRemove; } } pq = new PriorityQueue<>(); for (int i = n - 1; i >= 0; i--) { for (Camel camel : map.get(i)) { if (camel.dif >= 0) continue; pq.add(-camel.dif); base += -camel.dif; } while (pq.size() > n - i - 1) { long bestRemove = pq.poll(); base -= bestRemove; } } out.println(base); out.close(); } static class Camel { long dif; int split; Camel(long dif, int split) { this.dif = dif; this.split =split; } } public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Tono is on her mission to spread happiness everywhere. She has N close friends. She wants to make them stand in a line. She knows the happiness of the i<sup>th</sup> friend will be A[i] if the friend is standing among the first C[i] people in the line, else it would be B[i]. Find the maximum happiness that Tono can have in the line if she can arrange her friends in any order.The first line of the input contains an integer N. The next N lines of the input contain three integers C[i], A[i], and B[i] denoting the parameters for the i<sup>th</sup> friend. Constraints 1 <= N <= 100000 1 <= C[i] <= N 1 <= L[i], R[i] <= 10<sup>9</sup>Output the maximum happiness that Tono can achieve in the line.Sample Input 3 2 93 78 1 71 59 3 57 96 Sample Output 221 Explanation The optimal order is [2, 1, 3]. The happiness of friend 1 = 93 (among the first 2 people), friend 2 = 71 (among the first 1 people), and friend 3 = 57 (among the first 3 people). Sample Input 2 1 5 10 2 15 5 Sample Output 25, 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<pii> f; vector<pii> b; int ans = 0; For(i, 0, n){ int l, r, k; cin>>k>>l>>r; ans += min(l, r); if(l > r){ f.pb({l-r, k}); } else if(r > l){ b.pb({r-l, k}); } } sort(all(f)); reverse(all(f)); sort(all(b)); reverse(all(b)); set<int> s; For(i, 1, sz(f)+1){ s.insert(i); } for(pii p: f){ int ex = p.F; int pos = p.S; auto it = s.upper_bound(pos); if(it == s.begin()) continue; it--; ans += ex; s.erase(it); } while(s.size()){ s.erase(s.begin()); } For(i, sz(f)+1, n+1){ s.insert(i); } for(pii p: b){ int ex = p.F; int pos = p.S; auto it = s.upper_bound(pos); if(it == s.end()) continue; ans += ex; s.erase(it); } cout<<ans; } signed main() { fast #ifdef SWAPNIL07 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t=1; while(t--){ solve(); cout<<"\n"; } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<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>MakeTheNumber()</b> that takes the integer X as parameter. <b>Constraints:</b> 1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:- 3 Sample Output:- 4 Sample Input:- 5 Sample Output:- 16, I have written this Solution Code: def MakeTheNumber(N) : for i in range (1,10000): cnt=0 for x in range (1,i+1): if(i%x==0): cnt=cnt+1 if(cnt==N): return i return -1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<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>MakeTheNumber()</b> that takes the integer X as parameter. <b>Constraints:</b> 1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:- 3 Sample Output:- 4 Sample Input:- 5 Sample Output:- 16, I have written this Solution Code: int MakeTheNumber(int n){ for(int x=1;x<=10000;x++){ int cnt=0; for(int i=1;i<=x;i++){ if(x%i==0){cnt++;} } if(cnt==n){ return x;} } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<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>MakeTheNumber()</b> that takes the integer X as parameter. <b>Constraints:</b> 1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:- 3 Sample Output:- 4 Sample Input:- 5 Sample Output:- 16, I have written this Solution Code: public static int MakeTheNumber(int n){ for(int x=1;x<=10000;x++){ int cnt=0; for(int i=1;i<=x;i++){ if(x%i==0){cnt++;} } if(cnt==n){ return x;} } return -1; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<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>MakeTheNumber()</b> that takes the integer X as parameter. <b>Constraints:</b> 1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:- 3 Sample Output:- 4 Sample Input:- 5 Sample Output:- 16, I have written this Solution Code: int MakeTheNumber(int n){ for(int x=1;x<=10000;x++){ int cnt=0; for(int i=1;i<=x;i++){ if(x%i==0){cnt++;} } if(cnt==n){ return x;} } } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Complete the function <code>promiseMe</code> Such that it takes a number as the first argument (time) and a string as the second argument(data). It returns a promise which resolves after time milliseconds and data is returned. Note:- You only have to implement the function, in the example it shows your implemented question will be run.Function should take number as first argument and data to be returned as second.Resolves to the data given as inputpromiseMe(200, 'hi').then(data=>{ console.log(data) // prints hi }), I have written this Solution Code: function promiseMe(number, dat) { return new Promise((res,rej)=>{ setTimeout(()=>{ res(dat) },number) }) // 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 an N-size array of unique integers, your task is to print the array in a waveform, i. e a1 >= a2 <= a3 >= a4 <= a5.. . print the lexicographically smallest array possible.The first line of input contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 &le; N &le; 10<sup>5</sup> 1 &le; Arr[i] &le; 10<sup>9</sup>Print the array in wave form as mentioned.Sample Input :- 5 2 1 3 5 4 Sample Output:- 2 1 4 3 5 Sample Input:- 3 1 2 3 Sample Output:- 2 1 3, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(read.readLine()); StringTokenizer st = new StringTokenizer(read.readLine()); int[] arr = new int[N]; for(int i=0; i<N; i++) { arr[i] = Integer.parseInt(st.nextToken()); } Arrays.sort(arr); StringBuilder res = new StringBuilder(); for(int i=0; i<N-1; i+=2) { int temp = arr[i]; arr[i] = arr[i+1]; arr[i+1] = temp; res.append(arr[i] + " "); res.append(arr[i+1] + " "); } if(N % 2 != 0) { res.append(arr[N-1]); } System.out.print(res); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an N-size array of unique integers, your task is to print the array in a waveform, i. e a1 >= a2 <= a3 >= a4 <= a5.. . print the lexicographically smallest array possible.The first line of input contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 &le; N &le; 10<sup>5</sup> 1 &le; Arr[i] &le; 10<sup>9</sup>Print the array in wave form as mentioned.Sample Input :- 5 2 1 3 5 4 Sample Output:- 2 1 4 3 5 Sample Input:- 3 1 2 3 Sample Output:- 2 1 3, I have written this Solution Code: n = int(input()) a = list(map(int,input().strip().split())) a.sort() for i in range(0,n-1,2): print("{} ".format(a[i+1]),end="") print("{} ".format(a[i]),end="") if n&1: print("{} ".format(a[n-1])), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an N-size array of unique integers, your task is to print the array in a waveform, i. e a1 >= a2 <= a3 >= a4 <= a5.. . print the lexicographically smallest array possible.The first line of input contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 &le; N &le; 10<sup>5</sup> 1 &le; Arr[i] &le; 10<sup>9</sup>Print the array in wave form as mentioned.Sample Input :- 5 2 1 3 5 4 Sample Output:- 2 1 4 3 5 Sample Input:- 3 1 2 3 Sample Output:- 2 1 3, I have written this Solution Code: #include<bits/stdc++.h> #define int long long using namespace std; signed main() { int n,m; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } sort(a,a+n); for(int i=0;i<n-1;i+=2){ cout<<a[i+1]<<" "; cout<<a[i]<<" "; } if(n&1){ cout<<a[n-1]<<" "; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement the function <code>correctMistake</code>, which should take a string which will be the string we want to change the mistake in, and another string which is the wrong word or character, and third string which is the correct version and return its result as a string with mistakes (Use JS In built functions)Function will take 3 args, 1) line arg which is the string with mistakes 2) incorrectWord(or char) which is the char/word which needs to be replaced 3) toBeReplacedWithChar which is a stringFunction will return string with corrected mistakesconsole. log(correctMistake("Hi World world", "world", "of coding")) // prints "Hi World of coding" since world is replaced by empty char console. log(correctMistake("hi hi hi", "hi", "hello")) // prints "hello hello hello", I have written this Solution Code: function correctMistake(line, charToBeReplaced, what) { // write code here // return the output , do not use console.log here return line.replace(new RegExp(charToBeReplaced,'g'), what) }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N. The second line of input contains N integers, denoting the array height. <b>Constraints:</b> 1 <= N <= 10<sup>5</sup> 1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:- 5 5 4 1 2 1 Sample Output:- 2 <b>Explanation:</b> We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> #define rep(i,n) for (int i=0; i<(n); i++) ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; int a[n]; for(int i=0;i<n;++i){ cin>>a[i]; } int ans=0; int v=0; for(int i=1;i<n;++i){ if(a[i]>a[i-1]) v=0; else ++v; ans=max(ans,v); } cout<<ans; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N. The second line of input contains N integers, denoting the array height. <b>Constraints:</b> 1 <= N <= 10<sup>5</sup> 1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:- 5 5 4 1 2 1 Sample Output:- 2 <b>Explanation:</b> We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., 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 num = Integer.parseInt(br.readLine()); String s= br.readLine(); int[] arr= new int[num]; String[] s1 = s.split(" "); int ccount = 0, pcount = 0; for(int i=0;i<(num);i++) { arr[i]=Integer.parseInt(s1[i]); if(i+1 < num){ arr[i+1] = Integer.parseInt(s1[i+1]);} if(((i+1)< num) && (arr[i]>=arr[i+1]) ){ ccount++; }else{ if(ccount > pcount){ pcount = ccount; } ccount = 0; } } System.out.print(pcount); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N. The second line of input contains N integers, denoting the array height. <b>Constraints:</b> 1 <= N <= 10<sup>5</sup> 1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:- 5 5 4 1 2 1 Sample Output:- 2 <b>Explanation:</b> We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., I have written this Solution Code: N = int(input()) arr = iter(map(int,input().strip().split())) jumps = [] jump = 0 temp = next(arr) for i in arr: if i<=temp: jump += 1 temp = i continue temp = i jumps.append(jump) jump = 0 jumps.append(jump) print(max(jumps)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: static void simpleSum(int a, int b, int c){ System.out.println(a+b+c); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: void simpleSum(int a, int b, int c){ cout<<a+b+c; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: x = input() a, b, c = x.split() a = int(a) b = int(b) c = int(c) print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Your task is to implement a stack using a linked list and perform given queries Note:-if stack is already empty than pop operation will do nothing and 0 will be printed as a top element of stack if it is empty.User task: Since this will be a functional problem, you don't have to take input. You just have to complete the functions: <b>push()</b>:- that takes the integer to be added as a parameter. <b>pop()</b>:- that takes no parameter. <b>top()</b> :- that takes no parameter. Constraints: 1 <= N(number of queries) <= 10<sup>3</sup>You don't need to print anything else other than in top function in which you require to print the top most element of your stack in a new line, if the stack is empty you just need to print 0.Input: 7 push 1 push 2 top pop top pop top Output: 2 1 0 , I have written this Solution Code: Node top = null; public void push(int x) { Node temp = new Node(x); temp.next = top; top = temp; } public void pop() { if (top == null) { } else { top = (top).next;} } public void top() { // check for stack underflow if (top == null) { System.out.println("0"); } else { Node temp = top; System.out.println(temp.val); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones. Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy. The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items <b>Constraints:</b> 1 <= N <= 100000 1 <= K <= N - 2 1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input: 5 2 4 1 2 3 5 Sample Output: 7 Explanation: Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3. Sample Input: 10 8 99 56 50 93 47 36 65 25 87 16 Sample Output: 533, I have written this Solution Code: function supermarket(prices, n, k) { // write code here // do not console.log the answer // return sorted array const newPrices = prices.sort((a, b) => a - b).slice(2) let kk = k let price = 0; let i = 0 while (kk-- && i < newPrices.length) { price += newPrices[i] i += 1 } return price }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones. Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy. The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items <b>Constraints:</b> 1 <= N <= 100000 1 <= K <= N - 2 1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input: 5 2 4 1 2 3 5 Sample Output: 7 Explanation: Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3. Sample Input: 10 8 99 56 50 93 47 36 65 25 87 16 Sample Output: 533, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str[]= br.readLine().trim().split(" "); int n=Integer.parseInt(str[0]); int k=Integer.parseInt(str[1]); str= br.readLine().trim().split(" "); int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=Integer.parseInt(str[i]); Arrays.sort(arr); long sum=0; for(int i=2;i<k+2;i++) sum+=arr[i]; System.out.print(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones. Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy. The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items <b>Constraints:</b> 1 <= N <= 100000 1 <= K <= N - 2 1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input: 5 2 4 1 2 3 5 Sample Output: 7 Explanation: Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3. Sample Input: 10 8 99 56 50 93 47 36 65 25 87 16 Sample Output: 533, I have written this Solution Code: a=input().split() for i in range(len(a)): a[i]=int(a[i]) b=input().split() for i in range(len(b)): b[i]=int(b[i]) b.sort() b.reverse() b.pop() b.pop() s=0 while a[1]>0: s+=b.pop() a[1]-=1 print(s), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones. Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy. The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items <b>Constraints:</b> 1 <= N <= 100000 1 <= K <= N - 2 1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input: 5 2 4 1 2 3 5 Sample Output: 7 Explanation: Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3. Sample Input: 10 8 99 56 50 93 47 36 65 25 87 16 Sample Output: 533, I have written this Solution Code: #include<bits/stdc++.h> #define int long long #define ll long long #define pb push_back #define endl '\n' #define pii pair<int,int> #define vi vector<int> #define all(a) (a).begin(),(a).end() #define F first #define S second #define sz(x) (int)x.size() #define hell 1000000007 #define rep(i,a,b) for(int i=a;i<b;i++) #define dep(i,a,b) for(int i=a;i>=b;i--) #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define mp make_pair using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; void solve(){ int n, k; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); int ans = 0; for(int i = 3; i <= 2 + k; i++) ans += a[i]; cout << ans << endl; } void testcases(){ int tt = 1; //cin >> tt; while(tt--){ solve(); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t start = clock(); testcases(); cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: "; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static boolean isArrangementPossible(long arr[],int n,long sum){ if(n==1){ if(arr[0]==sum) return true; else return false; } return(isArrangementPossible(arr,n-1,sum-arr[n-1]) || isArrangementPossible(arr,n-1,sum+arr[n-1])); } public static void main (String[] args) throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String str1[]=br.readLine().trim().split(" "); int n=Integer.parseInt(str1[0]); long sum=Long.parseLong(str1[1]); String str[]=br.readLine().trim().split(" "); long arr[]=new long[n]; for(int i=0;i<n;i++){ arr[i]=Long.parseLong(str[i]); } if(isArrangementPossible(arr,n,sum)){ System.out.println("YES"); }else{ System.out.println("NO"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: def checkIfGivenTargetIsPossible(nums,currSum,i,targetSum): if i == len(nums): if currSum == targetSum: return 1 return 0 if(checkIfGivenTargetIsPossible(nums,currSum + nums[i],i+1,targetSum)): return 1 return checkIfGivenTargetIsPossible(nums,currSum - nums[i], i+1,targetSum) n,k = map(int,input().split()) nums = list(map(int,input().split())) if(checkIfGivenTargetIsPossible(nums,0,0,k)): print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #define int long long int k; using namespace std; int solve(int n, int a[], int i, int curr ){ if(i==n){ if(curr==k){return 1;} return 0; } if(solve(n,a,i+1,curr+a[i])==1){return 1;} return solve(n,a,i+1,curr-a[i]); } signed main() { int n; cin>>n>>k; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } if(solve(n,a,1,a[0])){ cout<<"YES";} else{ cout<<"NO";} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: function LeapYear(year){ // write code here // return the output using return keyword // do not use console.log here if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) { return 0; } else { return 1 } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: year = int(input()) if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0: print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int side = scanner.nextInt(); int area = LeapYear(side); if(area==1){ System.out.println("YES");} else{ System.out.println("NO");} } static int LeapYear(int year){ if(year%400==0){return 1;} if(year%100 != 0 && year%4==0){return 1;} else { return 0;} } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists. NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture. If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N. Constraints: 1 ≤ T ≤ 100 2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input: 2 8 3 Sample Output: 3 5 -1, I have written this Solution Code: // author-Shivam gupta #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1073741824 #define read(type) readInt<type>() #define max1 1000001 #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' const double pi=acos(-1.0); typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<string> VS; typedef vector<PII> VII; typedef vector<VI> VVI; typedef map<int,int> MPII; typedef set<int> SETI; typedef multiset<int> MSETI; typedef long int li; typedef unsigned long int uli; typedef long long int ll; typedef unsigned long long int ull; bool isPowerOfTwo (int x) { /* First x in the below expression is for the case when x is 0 */ return x && (!(x&(x-1))); } void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } ll power(ll x, ll y, ll p) { ll res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) % p; // y must be even now y = y>>1; // y = y/2 x = (x*x) % p; } return res; } // Returns n^(-1) mod p ll modInverse(ll n, ll p) { return power(n, p-2, p); } // Returns nCr % p using Fermat's little // theorem. ll ncr(ll n, ll r,ll p) { // Base case if (r==0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r ll fac[n+1]; fac[0] = 1; for (ll i=1 ; i<=n; i++) fac[i] = fac[i-1]*i%p; return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p; } ll fastexp (ll a, ll b, ll n) { ll res = 1; while (b) { if (b & 1) res = res*a%n; a = a*a%n; b >>= 1; } return res; } bool a[max1]; int main() { FOR(i,max1){ a[i]=false;} for(int i=2;i<max1;i++){ if(a[i]==false){ for(int j=i+i;j<max1;j+=i){ a[j]=true; } }} vector<int> v; map<int,int> m; for(int i=2;i<max1;i++){ if(a[i]==false){ v.EB(i); m[i]++; } } int t; cin>>t; while(t--){ int n; cin>>n; bool win=false; for(int i=0;i<v.size();i++){ if(m.find(n-v[i])!=m.end()){ if(v[i]>n){break;} cout<<v[i]<<" "<<n-v[i]<<endl;win=true;break; } } if(win==false){out(-1);} } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists. NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture. If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N. Constraints: 1 ≤ T ≤ 100 2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input: 2 8 3 Sample Output: 3 5 -1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static boolean isPrime(int n) { boolean ans=true; if(n<=1) { ans=false; } else if(n==2 || n==3) { ans=true; } else if(n%2==0 || n%3==0) { ans=false; } else { for(int i=5;i*i<=n;i+=6) { if(n%i==0 || n%(i+2)==0) { ans=false; break; } } } return ans; } public static void main (String[] args) throws IOException { BufferedReader scan=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(scan.readLine()); while(t-->0) { int n=Integer.parseInt(scan.readLine()); int a=0,b=0; if(n%2==1) { if(isPrime(n-2)) { a=2;b=n-2; } } else { for(int i=2;i<=n/2;i++) { if(isPrime(i)) { if(isPrime(n-i)) { a=i;b=n-i; break; } } } } if(a!=0 && b!=0) { System.out.println(a+" "+b); } else { System.out.println(-1); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists. NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture. If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N. Constraints: 1 ≤ T ≤ 100 2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input: 2 8 3 Sample Output: 3 5 -1, I have written this Solution Code: def isprime(num): if(num==1 or num==0): return False for i in range(2,int(num**0.5)+1): if(num%i==0): return False return True T = int(input()) for test in range(T): N = int(input()) value = -1 if(N%2==0): for i in range(2,int(N/2)+1): if(isprime(i)): if(isprime(N-i)): value = i break else: if(isprime(N-2)): value = 2 if(value==-1): print(value) else: print(str(value)+" "+str(N-value)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>. One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength. <b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases. Each test case consists of one line containing three space-separated integers x, y and z. <b> Constraints: </b> 1 ≤ t ≤ 10<sup>4</sup> 1 ≤ x, y ≤ 10<sup>15</sup> max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input 2 2 3 4 1 1 5 Sample Output 2 4, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { long z=0,x=0,y=0; int choice; Scanner in = new Scanner(System.in); choice = in.nextInt(); String s=""; int f = 1; while(f<=choice){ x = in.nextLong(); y = in.nextLong(); z = in.nextLong(); System.out.println((long)(Math.max((z-x),(z-y)))); f++; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>. One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength. <b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases. Each test case consists of one line containing three space-separated integers x, y and z. <b> Constraints: </b> 1 ≤ t ≤ 10<sup>4</sup> 1 ≤ x, y ≤ 10<sup>15</sup> max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input 2 2 3 4 1 1 5 Sample Output 2 4, I have written this Solution Code: n = int(input()) for i in range(n): l = list(map(int,input().split())) print(l[2]-min(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>. One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength. <b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases. Each test case consists of one line containing three space-separated integers x, y and z. <b> Constraints: </b> 1 ≤ t ≤ 10<sup>4</sup> 1 ≤ x, y ≤ 10<sup>15</sup> max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input 2 2 3 4 1 1 5 Sample Output 2 4, I have written this Solution Code: #include <bits/stdc++.h> #define int long long #define endl '\n' using namespace std; typedef long long ll; typedef long double ld; #define db(x) cerr << #x << ": " << x << '\n'; #define read(a) int a; cin >> a; #define reads(s) string s; cin >> s; #define readb(a, b) int a, b; cin >> a >> b; #define readc(a, b, c) int a, b, c; cin >> a >> b >> c; #define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];} #define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];} #define print(a) cout << a << endl; #define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl; #define printv(v) for (int i: v) cout << i << " "; cout << endl; #define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} #define all(v) v.begin(), v.end() #define sz(v) (int)(v.size()) #define rz(v, n) v.resize((n) + 1); #define pb push_back #define fi first #define se second #define vi vector <int> #define pi pair <int, int> #define vpi vector <pi> #define vvi vector <vi> #define setprec cout << fixed << showpoint << setprecision(20); #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const ll inf = 1e18; const ll mod = 1e9 + 7; const ll mod2 = 998244353; const ll N = 2e5 + 1; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int power (int a, int b = mod - 2) { int res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } signed main() { read(t); assert(1 <= t && t <= ll(1e4)); while (t--) { readc(x, y, z); assert(1 <= x && x <= ll(1e15)); assert(1 <= y && y <= ll(1e15)); assert(max(x, y) < z && z <= ll(1e15)); int r = 2*z - x - y - 1; int l = z - max(x, y); print(r - l + 1); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>. One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength. <b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases. Each test case consists of one line containing three space-separated integers x, y and z. <b> Constraints: </b> 1 ≤ t ≤ 10<sup>4</sup> 1 ≤ x, y ≤ 10<sup>15</sup> max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input 2 2 3 4 1 1 5 Sample Output 2 4, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define int long long void solve() { int t; cin>>t; while(t--) { int x, y, z; cin>>x>>y>>z; cout<<max(z - y, z- x)<<endl; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL); #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen("INPUT.txt", "r", stdin); freopen("OUTPUT.txt", "w", stdout); } #endif solve(); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows: If the percentage is >= 80 then print Grade ‘A’ If the percentage is <80 and >=60 then print Grade ‘B’ If the percentage is <60 and >=40 then print Grade ‘C’ else print Grade ‘D’The input contains 5 integers separated by spaces. <b>Constraints:</b> 1 &le; marks &le; 100You need to print the grade obtained by a student.Sample Input: 75 70 80 90 100 Sample Output: A <b>Explanation</b> ((75+70+80+90+100)/5)*100=83% A grade. , I have written this Solution Code: import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.io.*; public class Main { static final int MOD = 1000000007; public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str[] = br.readLine().trim().split(" "); int a = Integer.parseInt(str[0]); int b = Integer.parseInt(str[1]); int c = Integer.parseInt(str[2]); int d = Integer.parseInt(str[3]); int e = Integer.parseInt(str[4]); System.out.println(grades(a, b, c, d, e)); } static char grades(int a, int b, int c, int d, int e) { int sum = a+b+c+d+e; int per = sum/5; if(per >= 80) return 'A'; else if(per >= 60) return 'B'; else if(per >= 40) return 'C'; else return 'D'; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows: If the percentage is >= 80 then print Grade ‘A’ If the percentage is <80 and >=60 then print Grade ‘B’ If the percentage is <60 and >=40 then print Grade ‘C’ else print Grade ‘D’The input contains 5 integers separated by spaces. <b>Constraints:</b> 1 &le; marks &le; 100You need to print the grade obtained by a student.Sample Input: 75 70 80 90 100 Sample Output: A <b>Explanation</b> ((75+70+80+90+100)/5)*100=83% A grade. , I have written this Solution Code: li = list(map(int,input().strip().split())) avg=0 for i in li: avg+=i avg=avg/5 if(avg>=80): print("A") elif(avg>=60 and avg<80): print("B") elif(avg>=40 and avg<60): print("C") else: print("D"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones. Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy. The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items <b>Constraints:</b> 1 <= N <= 100000 1 <= K <= N - 2 1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input: 5 2 4 1 2 3 5 Sample Output: 7 Explanation: Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3. Sample Input: 10 8 99 56 50 93 47 36 65 25 87 16 Sample Output: 533, I have written this Solution Code: function supermarket(prices, n, k) { // write code here // do not console.log the answer // return sorted array const newPrices = prices.sort((a, b) => a - b).slice(2) let kk = k let price = 0; let i = 0 while (kk-- && i < newPrices.length) { price += newPrices[i] i += 1 } return price }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones. Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy. The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items <b>Constraints:</b> 1 <= N <= 100000 1 <= K <= N - 2 1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input: 5 2 4 1 2 3 5 Sample Output: 7 Explanation: Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3. Sample Input: 10 8 99 56 50 93 47 36 65 25 87 16 Sample Output: 533, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str[]= br.readLine().trim().split(" "); int n=Integer.parseInt(str[0]); int k=Integer.parseInt(str[1]); str= br.readLine().trim().split(" "); int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=Integer.parseInt(str[i]); Arrays.sort(arr); long sum=0; for(int i=2;i<k+2;i++) sum+=arr[i]; System.out.print(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones. Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy. The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items <b>Constraints:</b> 1 <= N <= 100000 1 <= K <= N - 2 1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input: 5 2 4 1 2 3 5 Sample Output: 7 Explanation: Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3. Sample Input: 10 8 99 56 50 93 47 36 65 25 87 16 Sample Output: 533, I have written this Solution Code: a=input().split() for i in range(len(a)): a[i]=int(a[i]) b=input().split() for i in range(len(b)): b[i]=int(b[i]) b.sort() b.reverse() b.pop() b.pop() s=0 while a[1]>0: s+=b.pop() a[1]-=1 print(s), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price P<sub>i</sub>. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones. Find the total cost of all items that he would buy.The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy. The second line contains N distinct integers P<sub>i</sub> , denoting the prices of the items <b>Constraints:</b> 1 <= N <= 100000 1 <= K <= N - 2 1 <= P<sub>i</sub> <= 1000000Print a single integer denoting the total cost of items Toros would buy.Sample Input: 5 2 4 1 2 3 5 Sample Output: 7 Explanation: Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3. Sample Input: 10 8 99 56 50 93 47 36 65 25 87 16 Sample Output: 533, I have written this Solution Code: #include<bits/stdc++.h> #define int long long #define ll long long #define pb push_back #define endl '\n' #define pii pair<int,int> #define vi vector<int> #define all(a) (a).begin(),(a).end() #define F first #define S second #define sz(x) (int)x.size() #define hell 1000000007 #define rep(i,a,b) for(int i=a;i<b;i++) #define dep(i,a,b) for(int i=a;i>=b;i--) #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define mp make_pair using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; void solve(){ int n, k; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); int ans = 0; for(int i = 3; i <= 2 + k; i++) ans += a[i]; cout << ans << endl; } void testcases(){ int tt = 1; //cin >> tt; while(tt--){ solve(); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t start = clock(); testcases(); cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: "; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Your task is to implement a stack using an array and perform given queries <b>Note</b>: Description of each query is given in the <b>input and output format</b>User task: Since this will be a functional problem, you don't have to take input. You just have to complete the functions: <b>push()</b>:- that takes the integer to be added and the maximum size of the array as a parameter. <b>pop()</b>:- that takes no parameter. <b>top()</b> :- that takes no parameter. Constraints: 1 <= N(number of queries) <= 10<sup>3</sup>During a <b>pop</b> operation if the stack is empty you need to print "<b>Stack underflow</b>", during <b>push</b> operation, if the maximum size of the array is reached you need to print "<b>Stack overflow</b>", <br> during <b>top</b> operation, you need to print the element which is at the top if the stack is empty you need to print "<b>Empty stack</b>". <b>Note</b>:- Each message or element is to be printed on a new line Sample Input:- 6 3 pop push 3 push 2 push 4 push 6 top Sample Output:- Stack underflow Stack overflow 4 Explanation:- Here maximum size of the array is 3, so element 6 can not be added to stack Sample input:- 8 4 push 2 top push 4 top push 6 top push 8 top Sample Output:- 2 4 6 8 , I have written this Solution Code: void push(int x,int k) { if (top >= k-1) { System.out.println("Stack overflow"); } else { a[++top] = x; } } void pop() { if (top < 0) { System.out.println("Stack underflow"); } else { int x = a[top--]; } } void top() { if (top < 0) { System.out.println("Empty stack"); } else { int x = a[top]; System.out.println(x); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print the pattern of "*" in the form of the Right Angle Triangle. See the below example for clarity.Since this is a functional problem, you don't have to worry about the input. It will be handled by driver code. You just have to complete <b>printTriangle()</b>. In the custom input area, you can provide any positive integer and check whether your code is working or not.Print the right angle triangle of height 5 as shown.Sample Input: No Input Sample Output:- * * * * * * * * * * * * * * *, I have written this Solution Code: class Solution { public static void printTriangle(){ System.out.println("*"); System.out.println("* *"); System.out.println("* * *"); System.out.println("* * * *"); System.out.println("* * * * *"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print the pattern of "*" in the form of the Right Angle Triangle. See the below example for clarity.Since this is a functional problem, you don't have to worry about the input. It will be handled by driver code. You just have to complete <b>printTriangle()</b>. In the custom input area, you can provide any positive integer and check whether your code is working or not.Print the right angle triangle of height 5 as shown.Sample Input: No Input Sample Output:- * * * * * * * * * * * * * * *, I have written this Solution Code: j=1 for i in range(0,5): for k in range(0,j): print("*",end=" ") if(j<=4): print() j=j+1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid. <b>Constraints:-</b> 1 <= n <= 100000 0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:- 10 1 2 3 2 4 3 6 6 7 6 Sample Output 1:- 0 0 0 1 0 1 0 0 0 1 43 Sample Input 2:- 7 10 20 30 40 30 20 10 Sample Output 2:- 0 0 0 0 10 20 30 220, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { InputStreamReader read = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); int n = Integer.parseInt(in.readLine()); int []donationList = new int[n]; int[] defaulterList = new int[n]; long totalDonations = 0L; StringTokenizer st = new StringTokenizer(in.readLine()); for(int i=0 ; i<n ; i++){ donationList[i] = Integer.parseInt(st.nextToken()); } int max = Integer.MIN_VALUE; for(int i=0; i<n; i++){ totalDonations += donationList[i]; max = Math.max(max,donationList[i]); if(i>0){ if(donationList[i] >= max) defaulterList[i] = 0; else defaulterList[i] = max - donationList[i]; } totalDonations += defaulterList[i]; } for(int i=0; i<n ;i++){ System.out.print(defaulterList[i]+" "); } System.out.println(); System.out.print(totalDonations); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable