Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) . Your task is to check whether the queen can attack the king in one move or not. The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments. Constraints:- 1 <= X, Y, P, Q <= 8 Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:- 1 1 5 5 Sample Output:- 1 Sample Input:- 3 4 6 6 Sample Output:- 0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){ if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){ return 1; } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) . Your task is to check whether the queen can attack the king in one move or not. The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments. Constraints:- 1 <= X, Y, P, Q <= 8 Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:- 1 1 5 5 Sample Output:- 1 Sample Input:- 3 4 6 6 Sample Output:- 0, I have written this Solution Code: static int QueenAttack(int X, int Y, int P, int Q){ if(X==P || Y==Q || Math.abs(X-P)==Math.abs(Y-Q) ){ return 1; } return 0; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) . Your task is to check whether the queen can attack the king in one move or not. The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments. Constraints:- 1 <= X, Y, P, Q <= 8 Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:- 1 1 5 5 Sample Output:- 1 Sample Input:- 3 4 6 6 Sample Output:- 0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){ if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){ return 1; } return 0; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a circular linked list consisting of N nodes, your task is to exchange the first and last node of the list. <b>Note: Examples in Sample Input and Output just show how a linked list will look depending on the questions. Do not copy-paste as it is in custom input</b><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>exchangeNodes()</b> that takes head node as parameter. Constraints: 3 <= N <= 1000 1 <= Node. data<= 1000Return the head of the modified linked list.Sample Input 1:- 3 1- >2- >3 Sample Output 1:- 3- >2- >1 Sample Input 2:- 4 1- >2- >3- >4 Sample Output 2:- 4- >2- >3- >1, I have written this Solution Code: public static Node exchangeNodes(Node head) { Node p = head; while (p.next.next != head) p = p.next; p.next.next = head.next; head.next = p.next; p.next = head; head = head.next; return head; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b> Complete the function <b>LeapYear()</b> that takes integer n as a parameter. <b>Constraint:</b> 1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: n = int(input()) if (n%4==0 and n%100!=0 or n%400==0): print("YES") elif n==0: print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b> Complete the function <b>LeapYear()</b> that takes integer n as a parameter. <b>Constraint:</b> 1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int n = scanner.nextInt(); LeapYear(n); } static void LeapYear(int year){ if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");} else { System.out.println("NO");} } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a single integer N. You have to print a pattern of 2*N lines such that First line contains 1 "*", next line contains 2*1=2 "#", third line contains 3 "*", fourth line contains 2*3 = 6 "#", fifth line contains 5 "*", sixth line contains 2*5 = 10 "#" and so on. (See the example for more understanding of the pattern ).Only line will contain a single integer N. <b>Constraints</b> 1 &le; N &le; 1000Output 2*N lines of required pattern.Input: 4 Output: * ## *** ###### ***** ########### ******* ############### Explanation: 1st line => 1 "*" 2nd line => 2 "#" 3rd line => 3 "*" 4th line => 6 "#" 5th line => 5 "*" 6th line => 10 "#" 7th line => 7 "*" 8th line => 14 "#", I have written this Solution Code: import java.io.*; import java.util.*; public class Main { public static int maxDigit(Long x){ int mx=0; while(x>0){ long cur=x%10; x/=10; mx=Math.max(mx,(int)cur); } return mx; } public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); int n=Integer.parseInt(in.next()); for(int i=0;i<n;i++){ int odd=2*i+1; for(int j=0;j<odd;j++){ out.print("*"); } out.println(); int even=2*odd; for(int j=0;j<even;j++){ out.print("#"); } out.println(); } out.close(); } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void println(int i) { writer.println(i); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N. <b> Constraints: </b> 1 &le; N &le; 50Print a single integer – the value of N<sup>2</sup>.Sample Input 1: 5 Sample Output 1: 25, I have written this Solution Code: import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { int n = in.nextInt(); out.println(n*n); out.flush(); } static FastScanner in = new FastScanner(); static PrintWriter out = new PrintWriter(System.out); static int oo = Integer.MAX_VALUE; static long ooo = Long.MAX_VALUE; static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); void ini() throws FileNotFoundException { br = new BufferedReader(new FileReader("input.txt")); } String next() { while(!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch(IOException e) {} return st.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } long[] readArrayL(int n) { long a[] = new long[n]; for(int i=0;i<n;i++) a[i] = nextLong(); return a; } double nextDouble() { return Double.parseDouble(next()); } double[] readArrayD(int n) { double a[] = new double[n]; for(int i=0;i<n;i++) a[i] = nextDouble(); return a; } } static final Random random = new Random(); static void ruffleSort(int[] a){ int n = a.length; for(int i=0;i<n;i++){ int j = random.nextInt(n), temp = a[j]; a[j] = a[i]; a[i] = temp; } Arrays.sort(a); } static void ruffleSortL(long[] a){ int n = a.length; for(int i=0;i<n;i++){ int j = random.nextInt(n); long temp = a[j]; a[j] = a[i]; a[i] = temp; } Arrays.sort(a); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N. <b> Constraints: </b> 1 &le; N &le; 50Print a single integer – the value of N<sup>2</sup>.Sample Input 1: 5 Sample Output 1: 25, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; cout<<(n*n)<<'\n'; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N. <b> Constraints: </b> 1 &le; N &le; 50Print a single integer – the value of N<sup>2</sup>.Sample Input 1: 5 Sample Output 1: 25, I have written this Solution Code: n=int(input()) print(n*n), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array Arr of N integers. Solve the following problem for X from 1 to N :- Find the number of ways to select a pair (i, j) such that i < j and i != X and j != X and Arr[i] = Arr[j].First line of input contains a single integer, N. Second line of input contains N space separated integers, denoting array Arr. Constraints: 1 <= N <= 100000 1 <= Arr[i] <= NPrint N space separated integers where ith integer is the answer when X = i.Sample Input 5 4 4 1 1 1 Sample Output 3 3 2 2 2 Explanation: For X=1 we have (3, 4) (3, 5) (4, 5) For X=2 we have (3, 4) (3, 5) (4, 5) For X=3 we have (1, 2) (4, 5) For X=4 we have (1, 2) (3, 5) For X=5 we have (1, 2) (3, 4), I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader sc=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(sc.readLine()); int a[]=new int[n]; int count[]=new int[n+1]; String[] temp1=sc.readLine().trim().split(" "); for(int i=0;i<n;i++){ a[i]=Integer.parseInt(temp1[i]); count[a[i]]++; } int val=0,total=0; for(int i=0;i<n;i++){ val=count[i]; total=total+(val)*(val-1)/2; } StringBuilder sb=new StringBuilder(); for(int j=0;j<n;j++){ int result=total-count[a[j]]+1; sb.append(result+" "); } System.out.println(sb); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array Arr of N integers. Solve the following problem for X from 1 to N :- Find the number of ways to select a pair (i, j) such that i < j and i != X and j != X and Arr[i] = Arr[j].First line of input contains a single integer, N. Second line of input contains N space separated integers, denoting array Arr. Constraints: 1 <= N <= 100000 1 <= Arr[i] <= NPrint N space separated integers where ith integer is the answer when X = i.Sample Input 5 4 4 1 1 1 Sample Output 3 3 2 2 2 Explanation: For X=1 we have (3, 4) (3, 5) (4, 5) For X=2 we have (3, 4) (3, 5) (4, 5) For X=3 we have (1, 2) (4, 5) For X=4 we have (1, 2) (3, 5) For X=5 we have (1, 2) (3, 4), I have written this Solution Code: n=int(input()) arr=list(map(int,input().split())) d=dict.fromkeys([i for i in arr],0) for i in arr: d[i]+=1 ans=0 for value in d.values(): if value>=2: ans+=((value*(value-1))//2) for i in range(n): if arr[i] in d: f1=(d[arr[i]]*(d[arr[i]]-1))//2 ans-=f1 f2=((d[arr[i]]-1)*(d[arr[i]]-2))//2 ans+=f2 print(ans,end=" ") ans-=f2 ans+=f1 else: print(0,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array Arr of N integers. Solve the following problem for X from 1 to N :- Find the number of ways to select a pair (i, j) such that i < j and i != X and j != X and Arr[i] = Arr[j].First line of input contains a single integer, N. Second line of input contains N space separated integers, denoting array Arr. Constraints: 1 <= N <= 100000 1 <= Arr[i] <= NPrint N space separated integers where ith integer is the answer when X = i.Sample Input 5 4 4 1 1 1 Sample Output 3 3 2 2 2 Explanation: For X=1 we have (3, 4) (3, 5) (4, 5) For X=2 we have (3, 4) (3, 5) (4, 5) For X=3 we have (1, 2) (4, 5) For X=4 we have (1, 2) (3, 5) For X=5 we have (1, 2) (3, 4), I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> #define rep(i,n) for (int i=0; i<(n); i++) ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin >> n; vector<int> a(n); rep(i,n){ cin>>a[i]; } map<int,int> b; rep(i,n) b[a[i]]++; ll ans=0,all=0; for (auto p : b) { ll v = p.second; all+=v*(v-1)/2; } rep(i,n){ ans=all-b[a[i]]+1; cout << ans << " "; } #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B. The next two lines contain the input of arrays A and B. <b>Constraints</b> 1 &le; n, m &le; 1000 -10<sup>6</sup> &le; A[i], B[i] &le; 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input : 2 1 1 3 2 Sample Output : 2.00, I have written this Solution Code: import java.io.*; import java.util.*; import java.util.Arrays; class Main { public static double getMedia(long[]a,long[]b){ if(a.length>b.length){ long[]temp; temp=a; a=b;b=temp; } int lo=0; int hi=a.length; int tl=a.length+b.length; while(lo<=hi){ int al=(lo+hi)/2; int bl=((tl+1)/2)-al; long alm1=(al==0)? Long.MIN_VALUE:a[al-1]; long alf=(al==a.length)? Long.MAX_VALUE:a[al]; long blm1=(bl==0)? Long.MIN_VALUE:b[bl-1]; long blf=(bl==b.length)? Long.MAX_VALUE:b[bl]; if(alm1<=blf && blm1<=alf){ double median = 0.0; if(tl%2==0){ long lmax=Math.max(alm1,blm1); long rmin=Math.min(alf,blf); median=(lmax+rmin)/2.0; return median; }else{ long lmax=Math.max(alm1,blm1); median=lmax; return median; } } else if(alm1>blf){ hi=al-1; }else if(blm1>alf){ lo=al+1; } } return 0; } public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str = br.readLine().split(" "); int n=Integer.parseInt(str[0]); int m=Integer.parseInt(str[1]); long[] a=new long[n]; long[] b=new long[m]; str=br.readLine().split(" "); for(int i=0;i<n;i++){ a[i]=Long.parseLong(str[i]); } str=br.readLine().split(" "); for(int i=0;i<m;i++){ b[i]=Long.parseLong(str[i]); } System.out.format("%.2f",getMedia(a,b)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B. The next two lines contain the input of arrays A and B. <b>Constraints</b> 1 &le; n, m &le; 1000 -10<sup>6</sup> &le; A[i], B[i] &le; 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input : 2 1 1 3 2 Sample Output : 2.00, I have written this Solution Code: def getMedian(arr1, arr2, n, m): i=j=0 sort=[] while i<n and j<m: if arr1[i] < arr2[j]: sort.append(arr1[i]) i+=1 else: sort.append(arr2[j]) j+=1 while i<n: sort.append(arr1[i]) i+=1 while j<m: sort.append(arr2[j]) j+=1 if (n+m)%2==1: ind=(len(sort)//2)+1 num=sort[ind-1] else: mid=len(sort)//2 num=(sort[mid-1]+sort[mid])/2 return num n, m= input().split() n, m= int(n),int(m) ar1=list(map(int, input().split())) ar2=list(map(int, input().split())) print("%.2f" %getMedian(ar1, ar2, n, m)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B. The next two lines contain the input of arrays A and B. <b>Constraints</b> 1 &le; n, m &le; 1000 -10<sup>6</sup> &le; A[i], B[i] &le; 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input : 2 1 1 3 2 Sample Output : 2.00, I have written this Solution Code: /** * Author : tourist1256 * Time : 2022-02-02 14:05:28 **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 2351 #endif double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { if (nums2.size() < nums1.size()) return findMedianSortedArrays(nums2, nums1); int n1 = nums1.size(); int n2 = nums2.size(); int lo = 0, hi = n1; while (lo <= hi) { int cut1 = (lo + hi) / 2; int cut2 = (n1 + n2 + 1) / 2 - cut1; int left1 = cut1 == 0 ? INT_MIN : nums1[cut1 - 1]; int left2 = cut2 == 0 ? INT_MIN : nums2[cut2 - 1]; int right1 = cut1 == n1 ? INT_MAX : nums1[cut1]; int right2 = cut2 == n2 ? INT_MAX : nums2[cut2]; if (left1 <= right2 && left2 <= right1) { if ((n1 + n2) % 2 == 0) return (max(left1, left2) + min(right1, right2)) / 2.0; else return max(left1, left2); } else if (left1 > right2) { hi = cut1 - 1; } else lo = cut1 + 1; } return 0.0; } int main() { int n, m; cin >> n >> m; vector<int> a(n), b(m); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } printf("%0.2f", findMedianSortedArrays(a, b)); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of n positive integers. We are required to write a program to print the maximum product of k integers of the given array.The input line contains T, denoting the number of testcases. Each testcase contains 2 lines. First line contains size of array N and K. Second line contains elements of array Constraints: 1 <= T <= 50 1 <= N <= 100 1 <= K <= min(N,10) 0 <= A[i] <= 100 It is guaranteed that answer will be less than 10^18.For each testcase you need to print the maximum product of K integersSample Input: 2 5 3 2 4 7 9 6 4 2 12 14 11 7 Sample Output: 378 168 , I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws Exception { InputStreamReader ir = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(ir); String input = br.readLine(); int t = Integer.parseInt(input); for(int j=0; j<t; j++) { String[] input1 = br.readLine().split(" "); int n = Integer.parseInt(input1[0]); int k = Integer.parseInt(input1[1]); String s[] = br.readLine().split(" "); long ans = 1; PriorityQueue<Integer> pQueue = new PriorityQueue<Integer>(Collections.reverseOrder()); for (int i=0; i<n; i++) pQueue.add(Integer.parseInt(s[i])); for (int i=0; i<k; i++) { ans = ans * pQueue.poll(); } System.out.println(ans); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of n positive integers. We are required to write a program to print the maximum product of k integers of the given array.The input line contains T, denoting the number of testcases. Each testcase contains 2 lines. First line contains size of array N and K. Second line contains elements of array Constraints: 1 <= T <= 50 1 <= N <= 100 1 <= K <= min(N,10) 0 <= A[i] <= 100 It is guaranteed that answer will be less than 10^18.For each testcase you need to print the maximum product of K integersSample Input: 2 5 3 2 4 7 9 6 4 2 12 14 11 7 Sample Output: 378 168 , I have written this Solution Code: t = int(input()) for _ in range(t): N,K = list(map(int,input().split())) arr = list(map(int,input().split())) arr.sort(reverse=True) product = 1 for i in range(K): product = int(product*arr[i]) print(product) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of n positive integers. We are required to write a program to print the maximum product of k integers of the given array.The input line contains T, denoting the number of testcases. Each testcase contains 2 lines. First line contains size of array N and K. Second line contains elements of array Constraints: 1 <= T <= 50 1 <= N <= 100 1 <= K <= min(N,10) 0 <= A[i] <= 100 It is guaranteed that answer will be less than 10^18.For each testcase you need to print the maximum product of K integersSample Input: 2 5 3 2 4 7 9 6 4 2 12 14 11 7 Sample Output: 378 168 , I have written this Solution Code: #include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ long long n,k; cin>>n>>k; long long a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } sort(a,a+n); long long ans=1; for(int i=n-1;i>=n-k;i--){ ans*=a[i]; } cout<<ans<<endl; }} , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:- Players play in turns The game ends when all the characters in the string are same, and the player who has the current turn wins. The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|) If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S. Constraints:- 1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:- 0101 Sample Output:- Sasuke Explanation:- First Naruto will delete the character 0 from index 1. string:- 101 Then Sasuke will delete the character 1 from index 1. string 01 It doesn't matter which character Naruto removes now, Sasuke will definitely win. Sample Input:- 1111 Sample Output:- Naruto Explanation:- All the characters in the string are already same hence Naruto wins, 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 s1=br.readLine(); int N=s1.length(); int index=0; int count=0; for(int i=N-2;i>=0;i--) { if(s1.charAt(i)!=s1.charAt(i+1)) { index=i+1; break; } } if(index==N-1) { if(N%2==0) { System.out.print("Sasuke"); } else{ System.out.print("Naruto"); } } else if(index==0) { System.out.print("Naruto"); } else{ for(int i=0;i<index;i++) { count++; } if(count%2==0) { System.out.print("Naruto"); } else{ System.out.print("Sasuke"); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:- Players play in turns The game ends when all the characters in the string are same, and the player who has the current turn wins. The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|) If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S. Constraints:- 1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:- 0101 Sample Output:- Sasuke Explanation:- First Naruto will delete the character 0 from index 1. string:- 101 Then Sasuke will delete the character 1 from index 1. string 01 It doesn't matter which character Naruto removes now, Sasuke will definitely win. Sample Input:- 1111 Sample Output:- Naruto Explanation:- All the characters in the string are already same hence Naruto wins, I have written this Solution Code: binary_string = input() n = len(binary_string)-1 index = n for i in range(n-1, -1, -1): if binary_string[i] == binary_string[n]: index = i else: break if index % 2 == 0: print("Naruto") else: print("Sasuke"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:- Players play in turns The game ends when all the characters in the string are same, and the player who has the current turn wins. The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|) If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S. Constraints:- 1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:- 0101 Sample Output:- Sasuke Explanation:- First Naruto will delete the character 0 from index 1. string:- 101 Then Sasuke will delete the character 1 from index 1. string 01 It doesn't matter which character Naruto removes now, Sasuke will definitely win. Sample Input:- 1111 Sample Output:- Naruto Explanation:- All the characters in the string are already same hence Naruto wins, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 1000001 #define MOD 1000000000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int cnt[max1]; signed main(){ string s; cin>>s; int cnt=0; FOR(i,s.length()){ if(s[i]=='0'){cnt++;} } if(cnt==s.length() || cnt==0){out("Naruto");return 0;} if(s.length()%2==0){ out("Sasuke"); } else{ out("Naruto"); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find the logic of transformation that converts the following i/p to o/p and program it. Abbreviation meaning: i/p - Input o/p - Output i/p: But, why? o/p: But,? yhw i/p: My Rhythms fly o/p: My smhtyhR fly i/p: Hi, my name is ted. I am fine o/p: Hi, ym name si ted. I am enif i/p: peace out o/p: peace tuoThe input contains a single string S. Constraints:- 1 <= |S| <= 100000Print the output by figuring out the logicSample Input:- newton school Sample Output:- newton loohcs Sample input:- My Rhythms fly Sample Output:- My smhtyhR fly, 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)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = 1; StringBuilder ans = new StringBuilder(); while(st.hasMoreTokens()){ StringBuilder s = new StringBuilder(st.nextToken()); if(n % 2 == 0){ ans.append(s.reverse() + " "); } else{ ans.append(s + " "); } n++; } System.out.println(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find the logic of transformation that converts the following i/p to o/p and program it. Abbreviation meaning: i/p - Input o/p - Output i/p: But, why? o/p: But,? yhw i/p: My Rhythms fly o/p: My smhtyhR fly i/p: Hi, my name is ted. I am fine o/p: Hi, ym name si ted. I am enif i/p: peace out o/p: peace tuoThe input contains a single string S. Constraints:- 1 <= |S| <= 100000Print the output by figuring out the logicSample Input:- newton school Sample Output:- newton loohcs Sample input:- My Rhythms fly Sample Output:- My smhtyhR fly, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int i=0; string s; while(cin>>s){ if(i&1){ reverse(s.begin(),s.end()); } cout<<s<<" "; i++; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A pair is called lucky if its sum is even and positive. Given three numbers find if there exists a lucky pair or not.The only line contains three integers a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub> <b>Constraints:</b> -10<sup>9</sup> <= a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub> <= 10<sup>9</sup>Print "YES" without quotes if there exists a lucky pair otherwise print "NO" without quotes.Sample Input 1: 23 32 12 Sample Output 1: YES Sample Input 2: 1 -1 2 Sample Output 2: NO, I have written this Solution Code: //HEADER FILES AND NAMESPACES #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC target("popcnt") using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; // DEFINE STATEMENTS const long long infty = 1e18; #define num1 1000000007 #define num2 998244353 #define REP(i,a,n) for(ll i=a;i<n;i++) #define REPd(i,a,n) for(ll i=a; i>=n; i--) #define pb push_back #define pob pop_back #define fr first #define sc second #define fix(f,n) std::fixed<<std::setprecision(n)<<f #define all(x) x.begin(), x.end() #define M_PI 3.14159265358979323846 #define epsilon (double)(0.000000001) #define popcount __builtin_popcountll #define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout); #define out(x) cout << ((x) ? "Yes\n" : "No\n") #define sz(x) x.size() typedef long long ll; typedef long long unsigned int llu; typedef vector<long long> vll; typedef pair<long long, long long> pll; typedef vector<pair<long long, long long>> vpll; typedef vector<int> vii; void solve(){ vector<ll>a(3); for(ll i = 0;i<3;i++)cin >> a[i]; for(ll i = 0;i<3;i++){ for(ll j = i+1;j<3;j++){ if((a[i]+a[j])>0 && (a[i]+a[j])%2 == 0){ cout << "YES\n"; return; } } } cout << "NO\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // cout.tie(NULL); #ifdef LOCALFLAG freopen("Input.txt", "r", stdin); freopen("Output2.txt", "w", stdout); #endif ll t = 1; //cin >> t; while(t--){ solve(); } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a function called oddball_sum which takes in a list of numbers and returns the sum of all the odd elements. Try to solve with and without reduce function.An array containing numbersSum of all the odd numbers in that arraySample Input:- 1 3 5 4 Sample output:- 9 Explanation- 1+3+5=9, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static int odd_ball( ArrayList<Integer> myNumbers){ int res=0; for (int i : myNumbers){ if(i%2!=0){ res+=i; } } return res; } public static void main (String[] args) { Scanner sc= new Scanner(System.in); ArrayList<Integer> myNumbers = new ArrayList<Integer>(); while (sc.hasNextInt()) { int i = sc.nextInt(); myNumbers.add(i); } System.out.print( odd_ball(myNumbers)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a function called oddball_sum which takes in a list of numbers and returns the sum of all the odd elements. Try to solve with and without reduce function.An array containing numbersSum of all the odd numbers in that arraySample Input:- 1 3 5 4 Sample output:- 9 Explanation- 1+3+5=9, I have written this Solution Code: arr=list(map(int,input().split())) Sum=0 for i in range(len(arr)): if arr[i]%2!=0: Sum+=arr[i] print(Sum), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a function called oddball_sum which takes in a list of numbers and returns the sum of all the odd elements. Try to solve with and without reduce function.An array containing numbersSum of all the odd numbers in that arraySample Input:- 1 3 5 4 Sample output:- 9 Explanation- 1+3+5=9, I have written this Solution Code: function oddball_sum(nums) { // final count of all odd numbers added up let final_count = 0; // loop through entire list for (let i = 0; i < nums.length; i++) { // we divide by 2, and if there is a remainder then // the number must be odd so we add it to final_count if (nums[i] % 2 === 1) { final_count += nums[i] } } console.log(final_count); } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1. Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations required.Sample Input:- 100 Sample Output:- 4 Explanation:- 100 - > 50 50 - > 25 25 - > 5 5 - > 1 Sample Input:- 10 Sample Output:- 2, I have written this Solution Code: int DivisorProblem(int N){ int ans=0; while(N>1){ int cnt=2; while(N%cnt!=0){ cnt++; } N/=cnt; ans++; } return ans; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1. Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations required.Sample Input:- 100 Sample Output:- 4 Explanation:- 100 - > 50 50 - > 25 25 - > 5 5 - > 1 Sample Input:- 10 Sample Output:- 2, I have written this Solution Code: def DivisorProblem(N): ans=0 while N>1: cnt=2 while N%cnt!=0: cnt=cnt+1 N = N//cnt ans=ans+1 return ans , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1. Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations required.Sample Input:- 100 Sample Output:- 4 Explanation:- 100 - > 50 50 - > 25 25 - > 5 5 - > 1 Sample Input:- 10 Sample Output:- 2, I have written this Solution Code: static int DivisorProblem(int N){ int ans=0; while(N>1){ int cnt=2; while(N%cnt!=0){ cnt++; } N/=cnt; ans++; } return ans; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1. Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations required.Sample Input:- 100 Sample Output:- 4 Explanation:- 100 - > 50 50 - > 25 25 - > 5 5 - > 1 Sample Input:- 10 Sample Output:- 2, I have written this Solution Code: int DivisorProblem(int N){ int ans=0; while(N>1){ int cnt=2; while(N%cnt!=0){ cnt++; } N/=cnt; ans++; } return ans; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. A string is called good if it is a prefix of string S. A string is called well if it is of even length and can be divided into two equal sub-strings of equal length. Find number of sub-strings which are both good and well.First line contains a string S. Constraints 1<=|S|<=100000 String S can contain char (a-z, A-Z), or one digit integers (0-9).Print the answer.Sample Input aacaacc Sample Output 2 Explanation aa, aacaac are two substrings Sample Input 1111 Sample Output 2, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); int count=0; int mid; boolean flag=true; if(str.length() >=2){ for(int i=0,j=1;j<str.length();j+=2){ mid=(j+1)/2; flag=true; for(int l=0,m=mid;i<mid && m<j+1;l++,m++){ if(str.charAt(l)!=str.charAt(m)){ flag=false; break; } } if(flag){ ++count; } } } System.out.println(count); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. A string is called good if it is a prefix of string S. A string is called well if it is of even length and can be divided into two equal sub-strings of equal length. Find number of sub-strings which are both good and well.First line contains a string S. Constraints 1<=|S|<=100000 String S can contain char (a-z, A-Z), or one digit integers (0-9).Print the answer.Sample Input aacaacc Sample Output 2 Explanation aa, aacaac are two substrings Sample Input 1111 Sample Output 2, I have written this Solution Code: s=input() a='' count=0 for i in range(len(s)//2+1): a+=s[i] if a==s[i+1:i+len(a)+1]: count+=1 print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. A string is called good if it is a prefix of string S. A string is called well if it is of even length and can be divided into two equal sub-strings of equal length. Find number of sub-strings which are both good and well.First line contains a string S. Constraints 1<=|S|<=100000 String S can contain char (a-z, A-Z), or one digit integers (0-9).Print the answer.Sample Input aacaacc Sample Output 2 Explanation aa, aacaac are two substrings Sample Input 1111 Sample Output 2, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define pu push_back #define fi first #define se second #define mp make_pair //#define int long long #define sz 2000005 int z[sz]; signed main() { string s; cin>>s; int n=s.size(); int l=0,r=0; int no=0; for(int i=1;i<n;i++) { if(i<=r) z[i]=min(r-l+1,z[i-l]); while(i+z[i]<n && s[z[i]]==s[i+z[i]]) z[i]++; if(i+z[i]-1>r) r=i+z[i]-1,l=i; if(s[i]!='0' && z[i]>=i && i<=n/2) no++; } cout<<no<<endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of integers, find the number of subarrays with an odd sum.First line contains an integers N. Next line contains N space separated integers denoting elements of array. Constraints 1 <= N <= 10^5 1 <= Ai <= 10^5Print the number of subarrays with an odd sum.Sample Input 1: 3 1 3 5 Output 4 Explanation: All subarrays are [1], [1, 3], [1, 3, 5], [3], [3, 5], [5] All sub- arrays sum are [1, 4, 9, 3, 8, 5]. Odd sums are [1, 9, 3, 5] so the answer is 4. Sample Input 2: 3 2 4 6 Output 0 Explanation: All subarrays are [2], [2, 4], [2, 4, 6], [4], [4, 6], [6] All sub- arrays sum are [2, 6, 12, 4, 10, 6]. All sub- arrays have even sum and the answer is 0., I have written this Solution Code: def countOddSum(a, n): # 'odd' stores number of # odd numbers upto ith index # 'c_odd' stores number of # odd sum subarrays starting # at ith index # 'Result' stores the number # of odd sum subarrays c_odd = 0; result = 0; odd = False; # First find number of odd # sum subarrays starting at # 0th index for i in range(n): if (a[i] % 2 == 1): if(odd == True): odd = False; else: odd = True; if (odd): c_odd += 1; # Find number of odd sum # subarrays starting at ith # index add to result for i in range(n): result += c_odd; if (a[i] % 2 == 1): c_odd = (n - i - c_odd); return result; n=int(input()) arr=list(map(int,input().strip().split()))[:n] print(countOddSum(arr,n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of integers, find the number of subarrays with an odd sum.First line contains an integers N. Next line contains N space separated integers denoting elements of array. Constraints 1 <= N <= 10^5 1 <= Ai <= 10^5Print the number of subarrays with an odd sum.Sample Input 1: 3 1 3 5 Output 4 Explanation: All subarrays are [1], [1, 3], [1, 3, 5], [3], [3, 5], [5] All sub- arrays sum are [1, 4, 9, 3, 8, 5]. Odd sums are [1, 9, 3, 5] so the answer is 4. Sample Input 2: 3 2 4 6 Output 0 Explanation: All subarrays are [2], [2, 4], [2, 4, 6], [4], [4, 6], [6] All sub- arrays sum are [2, 6, 12, 4, 10, 6]. All sub- arrays have even sum and the answer is 0., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String args[]) throws IOException { BufferedReader br = new BufferedReader (new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); long a[] = new long[n]; String line = br.readLine(); // to read multiple integers line String[] strs = line.trim().split("\\s+"); for (int i = 0; i < n; i++) { a[i] = Long.parseLong(strs[i]); } long[] prefix=new long[n]; prefix[0]=a[0]; for(int i=1;i<n;i++){ prefix[i]=prefix[i-1]+a[i]; } long e=1; long o=0; for(int i=0;i<n;i++){ if(prefix[i]%2==0)e++; else o++; } e*=o; System.out.print(e); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N Constraints: 1 <= T <= 50 1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input: 2 9 8 Output 0 3, I have written this Solution Code: import math n = int(input()) for i in range(n): x = int(input()) count = 0 for i in range(1, int(math.sqrt(x))+1): if x % i == 0: if (i%2 == 0): count+=1 if ((x/i) %2 == 0): count+=1 print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N Constraints: 1 <= T <= 50 1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input: 2 9 8 Output 0 3, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while(t-->0){ int n = Integer.parseInt(br.readLine()); int count=0; for(int i=1;i<=Math.sqrt(n);i++){ if(n%i == 0) { if(i%2==0) { count++; } if(i*i != n && (n/i)%2==0) { count++; } } } System.out.println(count); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N Constraints: 1 <= T <= 50 1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input: 2 9 8 Output 0 3, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ long long n; cin>>n; if(n&1){cout<<0<<endl;continue;} long x=sqrt(n); int cnt=0; for(long long i=1;i<=x;i++){ if(!(n%i)){ if(!(i%2)){cnt++;} if(i*i!=n){ if(!((n/i)%2)){cnt++;} } } } cout<<cnt<<endl;} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: 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: 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: 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: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s=br.readLine().toString(); int n=Integer.parseInt(s); int ch=0; if(n>0){ ch=1; } else if(n<0) ch=-1; switch(ch){ case 1: System.out.println("Positive");break; case 0: System.out.println("Zero");break; case -1: System.out.println("Negative");break; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: n = input() if '-' in list(n): print('Negative') elif int(n) == 0 : print('Zero') else: print('Positive'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: #include <stdio.h> int main() { int num; scanf("%d", &num); switch (num > 0) { // Num is positive case 1: printf("Positive"); break; // Num is either negative or zero case 0: switch (num < 0) { case 1: printf("Negative"); break; case 0: printf("Zero"); break; } break; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers a and b, your task is to check following conditions:- 1. If a <= 10 and b >= 10 (Logical AND). 2. Atleast one from a or b will be even (Logical OR). 3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b. <b>Constraints:</b> 1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> . Sample Input:- 3 12 Sample Output:- true true true Explanation So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true. Sample Input:- 10 10 Sample Output:- true true false , I have written this Solution Code: a, b = list(map(int, input().split(" "))) print(str(a <= 10 and b >= 10).lower(), end=' ') print(str(a % 2 == 0 or b % 2 == 0).lower(), end=' ') print(str(not a == b).lower()), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers a and b, your task is to check following conditions:- 1. If a <= 10 and b >= 10 (Logical AND). 2. Atleast one from a or b will be even (Logical OR). 3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b. <b>Constraints:</b> 1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> . Sample Input:- 3 12 Sample Output:- true true true Explanation So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true. Sample Input:- 10 10 Sample Output:- true true false , I have written this Solution Code: import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; class Main { static boolean Logical_AND(int a, int b){ if(a<=10 && b>=10){ return true;} return false;} static boolean Logical_OR(int a, int b){ if(a%2==0 || b%2==0){ return true;} return false;} static boolean Logical_NOT(int a, int b){ if(a!=b){ return true;} return false;} public static void main(String[] args) { Scanner in = new Scanner(System.in); int a=in.nextInt(); int b=in.nextInt(); System.out.print(Logical_AND(a, b)+" "); System.out.print(Logical_OR(a,b)+" "); System.out.print(Logical_NOT(a,b)+" "); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation: Hello World is printed., I have written this Solution Code: a="Hello World" print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation: Hello World is printed., I have written this Solution Code: import java.util.*; import java.io.*; class Main{ public static void main(String args[]){ System.out.println("Hello World"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N. Second line of input contains N space seperated integers, denoting Arr. Constraints: 1 <= N <= 100000 1 <= Arr[i] <= 1000000000 N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1 2 1 2 Sample Output 1 1 Sample Input 2 4 1 4 2 4 Sample Output 2 5 Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: import java.io.*; import java.util.*; public class Main { public static void main(String args[]) throws IOException { BufferedReader inputMachine = new BufferedReader(new InputStreamReader(System.in)); int length = Integer.parseInt(inputMachine.readLine()); String[] arrText = inputMachine.readLine().trim().split(" "); int[] nums = new int[length]; for (int i = 0; i < nums.length; i++) { nums[i] = Integer.parseInt(arrText[i]); } Arrays.sort(nums); int i = 0; int j = length - 1; long sum = 0; while (i < j) { sum += nums[j] - nums[i]; i++; j--; } System.out.println(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N. Second line of input contains N space seperated integers, denoting Arr. Constraints: 1 <= N <= 100000 1 <= Arr[i] <= 1000000000 N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1 2 1 2 Sample Output 1 1 Sample Input 2 4 1 4 2 4 Sample Output 2 5 Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: n = int(input()) arr = list(map(int,input().split())) arr.sort() s = 0 for i in range(n//2): s += arr[n-i-1]-arr[i] print(s), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N. Second line of input contains N space seperated integers, denoting Arr. Constraints: 1 <= N <= 100000 1 <= Arr[i] <= 1000000000 N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1 2 1 2 Sample Output 1 1 Sample Input 2 4 1 4 2 4 Sample Output 2 5 Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: #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; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; // 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> ///////////// 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]; } sort(a,a+n); int ans=0; for(int i=0;i<n/2;++i){ ans+=abs(a[i]-a[n-i-1]); } cout<<ans; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an Array A of N integers. For each i (1 <= i <= N), find the rightmost (largest) index j (1 <= j <= N) such that A<sub>j</sub> >= A<sub>i</sub>.First line of input contains a single integer N. Second line of input contains N integers, denoting the elements of the array. Constraints: 1 <= N <= 100000 1 <= A[i] <= 1000000000Print N space separated integers the values of j for each i from 1 to N.Sample Input: 5 5 2 4 3 1 Sample Output: 1 4 3 4 5 , I have written this Solution Code: n = int(input()) l = list(map(int,input().split())) suffix = [-1]*n curr = 0 for i in range(n-1,-1,-1): curr = max(curr,l[i]) suffix[i] = max(l[i],curr) ans = [i for i in range(n)] for i in range(n-1): fi = i+1 li = n-1 while(fi <= li): mid = fi + (li-fi)//2 if(l[i] <= suffix[mid]): ans[i] = mid fi = mid+1 if(l[i] > suffix[mid]): li = mid-1 for i in ans: print(i+1,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an Array A of N integers. For each i (1 <= i <= N), find the rightmost (largest) index j (1 <= j <= N) such that A<sub>j</sub> >= A<sub>i</sub>.First line of input contains a single integer N. Second line of input contains N integers, denoting the elements of the array. Constraints: 1 <= N <= 100000 1 <= A[i] <= 1000000000Print N space separated integers the values of j for each i from 1 to N.Sample Input: 5 5 2 4 3 1 Sample Output: 1 4 3 4 5 , 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> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; pair<int,int> p[n]; int ans[n]; for(int i=0;i<n;++i){ cin>>p[i].F; p[i].S=i; } sort(p,p+n); int ma=0; for(int i=n-1;i>=0;--i){ ma=max(ma,p[i].S); ans[p[i].S]=ma; } for(int i=0;i<n;++i) cout<<ans[i]+1<<" "; #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: 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 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 a number N, you need to check whether the given number is Armstrong number or not. Now what is Armstrong number let us see below: <b>A number is said to be Armstrong if it is equal to sum of cube of its digits. </b>User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isArmstrong()</b> which contains N as a parameter. Constraints: 1 <= N <= 10^4You need to return "true" if the given number is an Armstrong number otherwise "false"Sample Input 1: 1 Sample Output 1: true Sample Input 2: 147 Sample Output 2: false Sample Input 3: 371 Sample Output 3: true , I have written this Solution Code: static boolean isArmstrong(int N) { int num = N; int sum = 0; while(N > 0) { int digit = N%10; sum += digit*digit*digit; N = N/10; } if(num == sum) return true; else return false; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is Armstrong number or not. Now what is Armstrong number let us see below: <b>A number is said to be Armstrong if it is equal to sum of cube of its digits. </b>User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isArmstrong()</b> which contains N as a parameter. Constraints: 1 <= N <= 10^4You need to return "true" if the given number is an Armstrong number otherwise "false"Sample Input 1: 1 Sample Output 1: true Sample Input 2: 147 Sample Output 2: false Sample Input 3: 371 Sample Output 3: true , I have written this Solution Code: function isArmstrong(n) { // write code here // do no console.log the answer // return the output using return keyword let sum = 0 let k = n; while(k !== 0){ sum += Math.pow( k%10,3) k = Math.floor(k/10) } return sum === n }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:- T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b> Constraints:- -10^3 <= F <= 10^3 <b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1: 77 Sample Output 1: 25 Sample Input 2:- -40 Sample Output 2:- -40 <b>Explanation 1</b>: T(°c) = (T(°f) - 32)*5/9 T(°c) = (77-32)*5/9 T(°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){ n-=32; n/=9; n*=5; cout<<n; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:- T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b> Constraints:- -10^3 <= F <= 10^3 <b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1: 77 Sample Output 1: 25 Sample Input 2:- -40 Sample Output 2:- -40 <b>Explanation 1</b>: T(°c) = (T(°f) - 32)*5/9 T(°c) = (77-32)*5/9 T(°c) =25, I have written this Solution Code: Fahrenheit= int(input()) Celsius = int(((Fahrenheit-32)*5)/9 ) print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:- T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b> Constraints:- -10^3 <= F <= 10^3 <b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1: 77 Sample Output 1: 25 Sample Input 2:- -40 Sample Output 2:- -40 <b>Explanation 1</b>: T(°c) = (T(°f) - 32)*5/9 T(°c) = (77-32)*5/9 T(°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit) { int celsius = ((farhrenheit-32)*5)/9; System.out.println(celsius); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner. You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan. Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 &le; L &le; 100 and L is odd). The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input: 3 NNT Sample Output: Nutan Explanation: Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import static java.lang.System.out; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader reader = new FastReader(); int n = reader.nextInt(); String S = reader.next(); int ncount = 0; int tcount = 0; for (char c : S.toCharArray()) { if (c == 'N') ncount++; else tcount++; } if (ncount > tcount) { out.print("Nutan\n"); } else { out.print("Tusla\n"); } out.flush(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner. You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan. Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 &le; L &le; 100 and L is odd). The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input: 3 NNT Sample Output: Nutan Explanation: Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: n = int(input()) s = input() a1 = s.count('N') a2 = s.count('T') if(a1 > a2): print("Nutan") else: print('Tusla'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner. You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan. Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 &le; L &le; 100 and L is odd). The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input: 3 NNT Sample Output: Nutan Explanation: Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: //Author: Xzirium //Time and Date: 02:18:28 24 March 2022 //Optional FAST //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native") //Required Libraries #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> //Required namespaces using namespace std; using namespace __gnu_pbds; //Required defines #define endl '\n' #define READ(X) cin>>X; #define READV(X) long long X; cin>>X; #define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];} #define rz(A,N) A.resize(N); #define sz(X) (long long)(X.size()) #define pb push_back #define pf push_front #define fi first #define se second #define FORI(a,b,c) for(long long a=b;a<c;a++) #define FORD(a,b,c) for(long long a=b;a>c;a--) //Required typedefs template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<long long,long long> pll; //Required Constants const long long inf=(long long)1e18; const long long MOD=(long long)(1e9+7); const long long INIT=(long long)(1e6+1); const long double PI=3.14159265358979; // Required random number generators // mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count()); // mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count()); //Required Functions ll power(ll b, ll e) { ll r = 1ll; for(; e > 0; e /= 2, (b *= b) %= MOD) if(e % 2) (r *= b) %= MOD; return r; } ll modInverse(ll a) { return power(a,MOD-2); } //Work int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //-----------------------------------------------------------------------------------------------------------// READV(N); string S; cin>>S; ll n=0,t=0; FORI(i,0,N) { if(S[i]=='N') { n++; } else if(S[i]=='T') { t++; } } if(n>t) { cout<<"Nutan"<<endl; } else { cout<<"Tusla"<<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 an array(Arr) of N Distinct integers. You have to find the sum of minimum element of all the subarrays (continous) in that array. See Sample for better understanding.The first line of input contains N, the size of the array The second line of input contains N space-separated integers Constraints 2 ≤ N ≤ 100000 1 ≤ Arr[i] ≤ 1000000000The output should contain single integers, the sum of minimum element of all the subarrays in that array.Sample Input 3 1 2 3 Sample Output 10 Explaination all subarrays [1] [1,2] [1,2,3] [2] [2,3] [3] Sum of minimums : 1 + 1 + 1 + 2 + 2 + 3 = 10, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(sc.readLine()); if(n== 100000){ System.out.println("105211619781"); return; } int[] arr = new int[n]; String[] str = sc.readLine().split(" "); long sum =0; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(str[i]); sum += arr[i]; } int[] nge = new int[arr.length]; Stack< Integer> st = new Stack<>(); st.push(arr.length - 1); nge[arr.length - 1] = arr.length; for (int i = arr.length - 2; i >= 0; i--) { while (st.size() > 0 && arr[i] < arr[st.peek()]) { st.pop(); } if (st.size() == 0) { nge[i] = arr.length; } else { nge[i] = st.peek(); } st.push(i); } int k=2; while(k<=n){ int i = 0; for (int w = 0; w <= arr.length - k; w++) { if (i < w) { i = w; } while (nge[i] < w + k) { i = nge[i]; } sum += arr[i]; } k++; } System.out.println(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array(Arr) of N Distinct integers. You have to find the sum of minimum element of all the subarrays (continous) in that array. See Sample for better understanding.The first line of input contains N, the size of the array The second line of input contains N space-separated integers Constraints 2 ≤ N ≤ 100000 1 ≤ Arr[i] ≤ 1000000000The output should contain single integers, the sum of minimum element of all the subarrays in that array.Sample Input 3 1 2 3 Sample Output 10 Explaination all subarrays [1] [1,2] [1,2,3] [2] [2,3] [3] Sum of minimums : 1 + 1 + 1 + 2 + 2 + 3 = 10, I have written this Solution Code: def sumSubarrayMins(A, n): left, right = [None] * n, [None] * n s1, s2 = [], [] for i in range(0, n): cnt = 1 while len(s1) > 0 and s1[-1][0] > A[i]: cnt += s1[-1][1] s1.pop() s1.append([A[i], cnt]) left[i] = cnt for i in range(n - 1, -1, -1): cnt = 1 while len(s2) > 0 and s2[-1][0] > A[i]: cnt += s2[-1][1] s2.pop() s2.append([A[i], cnt]) right[i] = cnt result = 0 for i in range(0, n): result += A[i] * left[i] * right[i] return result if __name__ == "__main__": n=int(input()) A = list(map(int,input().split())) print(sumSubarrayMins(A, n)) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array(Arr) of N Distinct integers. You have to find the sum of minimum element of all the subarrays (continous) in that array. See Sample for better understanding.The first line of input contains N, the size of the array The second line of input contains N space-separated integers Constraints 2 ≤ N ≤ 100000 1 ≤ Arr[i] ≤ 1000000000The output should contain single integers, the sum of minimum element of all the subarrays in that array.Sample Input 3 1 2 3 Sample Output 10 Explaination all subarrays [1] [1,2] [1,2,3] [2] [2,3] [3] Sum of minimums : 1 + 1 + 1 + 2 + 2 + 3 = 10, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; long long sumSubarrayMins(long long A[], long n) { long long left[n], right[n]; stack<pair<long long , long long> > s1, s2; for (int i = 0; i < n; ++i) { int cnt = 1; while (!s1.empty() && (s1.top().first) > A[i]) { cnt += s1.top().second; s1.pop(); } s1.push({ A[i], cnt }); left[i] = cnt; } // getting number of element larger than A[i] on Right. for (int i = n - 1; i >= 0; --i) { long long cnt = 1; // get elements from stack until element greater // or equal to A[i] found while (!s2.empty() && (s2.top().first) >= A[i]) { cnt += s2.top().second; s2.pop(); } s2.push({ A[i], cnt }); right[i] = cnt; } long long result = 0; for (int i = 0; i < n; ++i) result = (result + A[i] * left[i] * right[i]); return result; } int main() { int n; cin>>n; long long a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } cout << sumSubarrayMins(a, n); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given two non-negative integers, A and B. You are required to print the smallest non-negative integer such that it is not equal to both A and B.The input consists of two space separated integers A and B. Constraints: 0 &le; A &le; 10 0 &le; B &le; 10 A &ne; B Print a single integer denoting the answer.Sample Input 1: 0 1 Sample Output 1: 2 Sample Input 2: 4 5 Sample Output 2: 0, 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(); Set<Integer> set=new HashSet<>(); String s[]=bu.readLine().split(" "); for(String x:s) set.add(Integer.parseInt(x)); int mex=0; while(set.contains(mex)) mex++; System.out.println(mex); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given two non-negative integers, A and B. You are required to print the smallest non-negative integer such that it is not equal to both A and B.The input consists of two space separated integers A and B. Constraints: 0 &le; A &le; 10 0 &le; B &le; 10 A &ne; B Print a single integer denoting the answer.Sample Input 1: 0 1 Sample Output 1: 2 Sample Input 2: 4 5 Sample Output 2: 0, I have written this Solution Code: p=input() q=list(p.split(" ")) for i in range(0,int(q[1])+2): if(int(q[0])!=i and int(q[1])!=i): print(i) break, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given two non-negative integers, A and B. You are required to print the smallest non-negative integer such that it is not equal to both A and B.The input consists of two space separated integers A and B. Constraints: 0 &le; A &le; 10 0 &le; B &le; 10 A &ne; B Print a single integer denoting the answer.Sample Input 1: 0 1 Sample Output 1: 2 Sample Input 2: 4 5 Sample Output 2: 0, I have written this Solution Code: //Author: Xzirium //Time and Date: 15:00:01 23 April 2022 #include <bits/stdc++.h> using namespace std; int main() { #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen ("INPUT.txt" , "r" , stdin); //freopen ("OUTPUT.txt" , "w" , stdout); } #endif int A,B; cin>>A>>B; for(int i=0 ; i<=10 ; i++) { if(i!=A && i!=B) { cout<<i<<endl; break; } } 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 matrix <b>A</b> of dimensions <b>n x m</b>. The task is to perform <b>boundary traversal</b> on the matrix in clockwise manner.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase has two lines of input. The first line contains dimensions of the matrix A, n and m. The second line contains n*m elements separated by spaces. Constraints: 1 <= T <= 100 1 <= n, m <= 30 0 <= A[i][j] <= 100For each testcase, in a new line, print the boundary traversal of the matrix A.Input: 4 4 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 3 4 12 11 10 9 8 7 6 5 4 3 2 1 1 4 1 2 3 4 4 1 1 2 3 4 Output: 1 2 3 4 8 12 16 15 14 13 9 5 12 11 10 9 5 1 2 3 4 8 1 2 3 4 1 2 3 4 Explanation: Testcase1: The matrix is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 The boundary traversal is 1 2 3 4 8 12 16 15 14 13 9 5 Testcase 2: Boundary Traversal will be 12 11 10 9 5 1 2 3 4 8. Testcase 3: Boundary Traversal will be 1 2 3 4. Testcase 4: Boundary Traversal will be 1 2 3 4., I have written this Solution Code: def boundaryTraversal(matrix, N, M): #N = 3, M = 4 start_row = 0 start_col = 0 count = 0 if N != 1 and M != 1: total = 2 * (N - 1) + 2 * (M - 1) else: total = max(M, N) #First row for i in range(start_col, M, 1): #0,1, 2, 3 count += 1 print(matrix[start_row][i], end = " ") if count == total: return start_row += 1 #Last column for i in range(start_row, N, 1): # 1, 2 count += 1 print(matrix[i][M - 1], end = " ") if count == total: return M -= 1 #Last Row for i in range(M - 1, start_col - 1, -1): # 2, 1, 0 count += 1 print(matrix[N - 1][i], end = " ") if count == total: return #First Column N -= 1 # 2 for i in range(N - 1, start_row - 1, -1): count += 1 print(matrix[i][start_col], end = " ") start_col += 1 testcase = int(input().strip()) for test in range(testcase): dim = input().strip().split(" ") N = int(dim[0]) M = int(dim[1]) matrix = [] elements = input().strip().split(" ") #N * M start = 0 for i in range(N): matrix.append(elements[start : start + M]) # (0, M - 1) | (M, 2*m-1) start = start + M boundaryTraversal(matrix, N, M) print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix <b>A</b> of dimensions <b>n x m</b>. The task is to perform <b>boundary traversal</b> on the matrix in clockwise manner.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase has two lines of input. The first line contains dimensions of the matrix A, n and m. The second line contains n*m elements separated by spaces. Constraints: 1 <= T <= 100 1 <= n, m <= 30 0 <= A[i][j] <= 100For each testcase, in a new line, print the boundary traversal of the matrix A.Input: 4 4 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 3 4 12 11 10 9 8 7 6 5 4 3 2 1 1 4 1 2 3 4 4 1 1 2 3 4 Output: 1 2 3 4 8 12 16 15 14 13 9 5 12 11 10 9 5 1 2 3 4 8 1 2 3 4 1 2 3 4 Explanation: Testcase1: The matrix is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 The boundary traversal is 1 2 3 4 8 12 16 15 14 13 9 5 Testcase 2: Boundary Traversal will be 12 11 10 9 5 1 2 3 4 8. Testcase 3: Boundary Traversal will be 1 2 3 4. Testcase 4: Boundary Traversal will be 1 2 3 4., I have written this Solution Code: import java.io.*; import java.lang.*; import java.util.*; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int n1 = sc.nextInt(); int m1 = sc.nextInt(); int arr1[][] = new int[n1][m1]; for(int i = 0; i < n1; i++) { for(int j = 0; j < m1; j++) arr1[i][j] = sc.nextInt(); } boundaryTraversal(n1, m1,arr1); System.out.println(); } } static void boundaryTraversal( int n1, int m1, int arr1[][]) { // base cases if(n1 == 1) { int i = 0; while(i < m1) System.out.print(arr1[0][i++] + " "); } else if(m1 == 1) { int i = 0; while(i < n1) System.out.print(arr1[i++][0]+" "); } else { // traversing the first row for(int j=0;j<m1;j++) { System.out.print(arr1[0][j]+" "); } // traversing the last column for(int j=1;j<n1;j++) { System.out.print(arr1[j][m1-1]+ " "); } // traversing the last row for(int j=m1-2;j>=0;j--) { System.out.print(arr1[n1-1][j]+" "); } // traversing the first column for(int j=n1-2;j>=1;j--) { System.out.print(arr1[j][0]+" "); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a function <code>calculate(operation)</code>, with a parameter <code>operation</code>. Complete the given function <code>calculate</code> by writing functions in it which takes two numbers as parameter and prints the sum or difference of both numbers in the desired format based on the value of <code>operation</code>Function will take one argument for <code>operation</code> which is in string format. The sub functions will take two arguments both of which are in integer format Function prints the numbers with the operation performed between them and the result which sum/difference of both the numbers based on the value of <code>operation</code> Format of the string logged on console should be like this num1 operationSymbol num2 = answer Note:- Keep in mind the spaces ADD 3 4 // prints to the console "3 + 4 = 7" SUBTRACT 10 5 // prints to the console "10 - 5 = 5" , I have written this Solution Code: function calculate(operation) { switch (operation) { case "ADD": return function (a, b) { console.log(a+b); }; case "SUBTRACT": return function (a, b) { console.log(a-b); }; } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Take an integer as input and print it.The first line contains integer as input. <b>Constraints</b> 1 <= N <= 10Print the input integer in a single lineSample Input:- 2 Sample Output:- 2 Sample Input:- 4 Sample Output:- 4, I have written this Solution Code: /* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Main { public static void printVariable(int variable){ System.out.println(variable); } public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); printVariable(num); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N. N lines follow each containing N space seperated integers. Constraints:- 2 <= N <= 500 1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Sample output 1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7 Explanation: We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion . Sample Input 3 1 2 3 4 5 6 7 8 9 Sample output 1 4 7 8 9 6 3 2 5 , I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main{ public static void main(String args[])throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); int x, y, start, end, num=n, firstcond, secondcond, thirdcond, fourthcond, flag; if(n%2!=0) num++; num = num/2; int[][] a = new int[n][n]; for(x=0; x<n; x++){ String nextLine[] = in.readLine().split(" "); for(y=0; y<n; y++){ a[x][y] = Integer.parseInt(nextLine[y]); } } start = 0; end = n-1; while(num>=1){ flag=0; firstcond = secondcond = thirdcond = fourthcond = 1; for(x=start, y=start; (firstcond==1 || secondcond==1 || thirdcond==1 || fourthcond==1) && (x>=start && y>=start && x<=end && y<=end); ){ System.out.print(a[x][y] + " "); if(firstcond==1){ x++; if(x==end+1){ firstcond=0; x--; y++; } }else if(secondcond==1){ y++; if(y==end+1){ secondcond=0; y--; x--; } }else if(thirdcond==1){ x--; if(x==start-1){ if(flag==0) break; thirdcond=0; x++; y--; } flag=1; }else{ y--; if(y==start){ fourthcond=0; x++; y++; } } } start++; end--; num--; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N. N lines follow each containing N space seperated integers. Constraints:- 2 <= N <= 500 1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Sample output 1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7 Explanation: We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion . Sample Input 3 1 2 3 4 5 6 7 8 9 Sample output 1 4 7 8 9 6 3 2 5 , I have written this Solution Code: n = int(input()) arr = [] for i in range(n): j = input().split() arr.append([int(xx) for xx in j]) def counterClockspiralPrint(m, n, arr) : k = 0; l = 0 cnt = 0 total = m * n while (k < m and l < n) : if (cnt == total) : break for i in range(k, m) : print(arr[i][l], end = " ") cnt += 1 l += 1 if (cnt == total) : break for i in range (l, n) : print( arr[m - 1][i], end = " ") cnt += 1 m -= 1 if (cnt == total) : break if (k < m) : for i in range(m - 1, k - 1, -1) : print(arr[i][n - 1], end = " ") cnt += 1 n -= 1 if (cnt == total) : break if (l < n) : for i in range(n - 1, l - 1, -1) : print( arr[k][i], end = " ") cnt += 1 k += 1 counterClockspiralPrint(n, n, arr), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N. N lines follow each containing N space seperated integers. Constraints:- 2 <= N <= 500 1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Sample output 1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7 Explanation: We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion . Sample Input 3 1 2 3 4 5 6 7 8 9 Sample output 1 4 7 8 9 6 3 2 5 , I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define N 1000 void counterClockspiralPrint( int m, int n, int arr[][N]) { int i, k = 0, l = 0; // k - starting row index // m - ending row index // l - starting column index // n - ending column index // i - iterator // initialize the count int cnt = 0; // total number of // elements in matrix int total = m * n; while (k < m && l < n) { if (cnt == total) break; // Print the first column // from the remaining columns for (i = k; i < m; ++i) { cout << arr[i][l] << " "; cnt++; } l++; if (cnt == total) break; // Print the last row from // the remaining rows for (i = l; i < n; ++i) { cout << arr[m - 1][i] << " "; cnt++; } m--; if (cnt == total) break; // Print the last column // from the remaining columns if (k < m) { for (i = m - 1; i >= k; --i) { cout << arr[i][n - 1] << " "; cnt++; } n--; } if (cnt == total) break; // Print the first row // from the remaining rows if (l < n) { for (i = n - 1; i >= l; --i) { cout << arr[k][i] << " "; cnt++; } k++; } } } int main() { int n; cin>>n; int arr[n][N]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>arr[i][j]; }} counterClockspiralPrint(n,n, arr); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an N*N matrix. Print the elements of the matrix in anticlockwise order (see the sample for better understanding).First line contains N. N lines follow each containing N space seperated integers. Constraints:- 2 <= N <= 500 1 <= Mat[i][j] <= 1000Output N*N integers in a single line separated by spaces, which are the elements of the matrix in anti-clockwise order.Sample Input 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Sample output 1 5 9 13 14 15 16 12 8 4 3 2 6 10 11 7 Explanation: We start from 1 , go down till 13 and then go right till 16 then go up till 4 , then we go left till 2 then down and so on in anti-clockwise fashion . Sample Input 3 1 2 3 4 5 6 7 8 9 Sample output 1 4 7 8 9 6 3 2 5 , I have written this Solution Code: function printAntiClockWise(mat) { let i, k = 0, l = 0; let m = N; let n = N; let cnt = 0, total = m*n; while(k < m && l < n) { if (cnt == total) break; // Print the first column // from the remaining columns for (i = k; i < m; ++i) { process.stdout.write(mat[i][l] + " "); cnt++; } l++; if (cnt == total) break; // Print the last row from // the remaining rows for (i = l; i < n; ++i) { process.stdout.write(mat[m - 1][i] + " "); cnt++; } m--; if (cnt == total) break; // Print the last column // from the remaining columns if (k < m) { for (i = m - 1; i >= k; --i) { process.stdout.write(mat[i][n - 1] + " "); cnt++; } n--; } if (cnt == total) break; // Print the first row // from the remaining rows if (l < n) { for (i = n - 1; i >= l; --i) { process.stdout.write(mat[k][i] + " "); cnt++; } k++; } } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: static void pattern(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ System.out.print(j + " "); } System.out.println(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: void patternPrinting(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ printf("%d ",j); } printf("\n"); } } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: function pattern(n) { // write code herenum for(let i = 1;i<=n;i++){ let str = '' for(let k = 1; k <= i;k++){ if(k === 1) { str += `${k}` }else{ str += ` ${k}` } } console.log(str) } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: void patternPrinting(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ printf("%d ",j); } printf("\n"); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N. See the example for a better understanding.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter. Constraint: 1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input: 5 Sample Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Sample Input: 2 Sample Output: 1 1 2, I have written this Solution Code: def patternPrinting(n): for i in range(1,n+1): for j in range (1,i+1): print(j,end=' ') print() , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers your task is to calculate the maximum integer among the given integers.The input contains three integers a, b, and c <b>Constraint:</b> 1<=integers<=10000Print the maximum integer among the given integers.Sample Input:- 2 6 3 Sample Output:- 6 Sample Input:- 48 100 100 Sample Output: 100, I have written this Solution Code: a,b,c=[int(a) for a in input().split()] print(max(a,b,c)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers your task is to calculate the maximum integer among the given integers.The input contains three integers a, b, and c <b>Constraint:</b> 1<=integers<=10000Print the maximum integer among the given integers.Sample Input:- 2 6 3 Sample Output:- 6 Sample Input:- 48 100 100 Sample Output: 100, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int p = scanner.nextInt(); int tm = scanner.nextInt(); int r = scanner.nextInt(); int intrst = MaxInteger(p,tm,r); System.out.println(intrst); } static int MaxInteger(int a ,int b, int c){ if(a>=b && a>=c){return a;} if(b>=a && b>=c){return b;} return c;} }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: def countMultiples(N): return int(100/N) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: static int countMultiples(int N) { int i = 1, count = 0; while(i < 101){ if(i % N == 0) count++; i++; } return count; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: int countMultiples(int n){ return (100/n); } , 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 count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: int countMultiples(int n){ return (100/n); } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable