Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given an array A of size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array.
Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow.
Each testcases contains two lines of input. The first line denotes the size of the array N.
The second lines contains the elements of the array A separated by spaces.
Constraints:
1 <= T <= 100
1 <= N <= 100000
0 <= Ai <= 2
Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input :
2
5
0 2 1 2 0
3
0 1 0
Output:
0 0 1 2 2
0 0 1
Explanation:
Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output.
Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: function zeroOneTwoSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A positive integer num is given to you. Any two digits of num with the same parity can be swapped (i. e. both odd digits or both even digits).
After any number of swaps, output the largest attainable value of num.The first line contains the integer num.
Constraints:
1<= num <= 1e9After any number of digit swaps, output the largest number possible.Sample Input 1:
1234
Sample Output 1:
3412
Explanation 1:
When the digit 3 is swapped with the digit 1, the result is 3214.
The number 3412 is obtained by swapping the digit 2 with the numeral 4.
It's worth noting that there might be alternative swap sequences, but 3412 is the maximum feasible number.
Also, because the parities of the digits 4 and 1 are different, we cannot swap them.
Sample Input 2:
65875
Sample Output 2:
87655
Explanation 2:
The number 85675 is obtained by replacing the digit 8 with the digit 6.
If you swap the initial digit 5 with the seventh digit, you'll get the number 87655.
There may be alternative swap sequences, but it can be demonstrated that 87655 is the maximum conceivable number., I have written this Solution Code: import java.util.*;
import java.lang.*;
class Main {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
String numStr = Integer.toString(num);
PriorityQueue<Integer> oddPQ = new PriorityQueue<>(Collections.reverseOrder());
PriorityQueue<Integer> evenPQ = new PriorityQueue<>(Collections.reverseOrder());
for(char digit: numStr.toCharArray()) {
int value = digit - '0';
if(value % 2 == 0) {
evenPQ.offer(value);
} else {
oddPQ.offer(value);
}
}
int answer = 0;
for(char digit: numStr.toCharArray()) {
answer *= 10;
if((digit - '0') % 2 == 0) {
answer += evenPQ.poll();
} else {
answer += oddPQ.poll();
}
}
System.out.println(answer);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 ≤ A, B ≤ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
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();
String s[]=bu.readLine().split(" ");
int a=Integer.parseInt(s[0]),b=Integer.parseInt(s[1]);
int ans=2;
if(a==b) ans=0;
else if(a%b==0 || b%a==0 || a+1==b || b+1==a) ans=1;
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 ≤ A, B ≤ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: l=list(map(int, input().split()))
A=l[0]
B=l[1]
if A==B:
print(0)
elif A%B==0 or B%A==0 or abs(A-B)==1:
print(1)
else:
print(2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 ≤ A, B ≤ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a == b) cout << 0;
else if (abs(a - b) == 1) cout << 1;
else if (a % b == 0 || b % a == 0) cout << 1;
else cout << 2;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code:
import java.io.*;
import java.util.*;
class Main {
public static boolean isArrangementPossible(long arr[],int n,long sum){
if(n==1){
if(arr[0]==sum)
return true;
else
return false;
}
return(isArrangementPossible(arr,n-1,sum-arr[n-1]) || isArrangementPossible(arr,n-1,sum+arr[n-1]));
}
public static void main (String[] args) throws IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String str1[]=br.readLine().trim().split(" ");
int n=Integer.parseInt(str1[0]);
long sum=Long.parseLong(str1[1]);
String str[]=br.readLine().trim().split(" ");
long arr[]=new long[n];
for(int i=0;i<n;i++){
arr[i]=Long.parseLong(str[i]);
}
if(isArrangementPossible(arr,n,sum)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code: def checkIfGivenTargetIsPossible(nums,currSum,i,targetSum):
if i == len(nums):
if currSum == targetSum:
return 1
return 0
if(checkIfGivenTargetIsPossible(nums,currSum + nums[i],i+1,targetSum)):
return 1
return checkIfGivenTargetIsPossible(nums,currSum - nums[i], i+1,targetSum)
n,k = map(int,input().split())
nums = list(map(int,input().split()))
if(checkIfGivenTargetIsPossible(nums,0,0,k)):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code: #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define int long long
int k;
using namespace std;
int solve(int n, int a[], int i, int curr ){
if(i==n){
if(curr==k){return 1;}
return 0;
}
if(solve(n,a,i+1,curr+a[i])==1){return 1;}
return solve(n,a,i+1,curr-a[i]);
}
signed main() {
int n;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
if(solve(n,a,1,a[0])){
cout<<"YES";}
else{
cout<<"NO";}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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 an array containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array.
Constraints:-
1<=T<=500
1<=N,K<=10^5
-10^5<=A[i]<=10^5
Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input:
3
6 15
10 5 2 7 1 9
6 -5
-5 8 -14 2 4 12
3 6
-1 2 3
Sample Output:
4
5
0, I have written this Solution Code: def lenOfLongSubarr(arr, N, K):
mydict = dict()
sum = 0
maxLen = 0
for i in range(N):
sum += arr[i]
if (sum == K):
maxLen = i + 1
elif (sum - K) in mydict:
maxLen = max(maxLen, i - mydict[sum - K])
if sum not in mydict:
mydict[sum] = i
return maxLen
if __name__ == '__main__':
T = int(input())
#N,K=list(map(int,input().split()))
for i in range(T):
N,k= [int(N)for N in input("").split()]
arr=list(map(int,input().split()))
N = len(arr)
print(lenOfLongSubarr(arr, N, k)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array.
Constraints:-
1<=T<=500
1<=N,K<=10^5
-10^5<=A[i]<=10^5
Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input:
3
6 15
10 5 2 7 1 9
6 -5
-5 8 -14 2 4 12
3 6
-1 2 3
Sample Output:
4
5
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
unordered_map<long long,int> um;
int n,k;
cin>>n>>k;
long arr[n];
int maxLen=0;
for(int i=0;i<n;i++){cin>>arr[i];}
long long sum=0;
for(int i=0;i<n;i++){
sum += arr[i];
// when subarray starts from index '0'
if (sum == k)
maxLen = i + 1;
// make an entry for 'sum' if it is
// not present in 'um'
if (um.find(sum) == um.end())
um[sum] = i;
// check if 'sum-k' is present in 'um'
// or not
if (um.find(sum - k) != um.end()) {
// update maxLength
if (maxLen < (i - um[sum - k]))
maxLen = i - um[sum - k];
}
}
cout<<maxLen<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array.
Constraints:-
1<=T<=500
1<=N,K<=10^5
-10^5<=A[i]<=10^5
Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input:
3
6 15
10 5 2 7 1 9
6 -5
-5 8 -14 2 4 12
3 6
-1 2 3
Sample Output:
4
5
0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
if(t%10==0){
System.gc();
}
int arrsize=sc.nextInt();
int k=sc.nextInt();
int[] arr=new int[arrsize];
for(int i=0;i<arrsize;i++){
arr[i]=sc.nextInt();
}
int subsize=0;
int sum=0;
HashMap<Integer, Integer> hash=new HashMap<>();
for(int i=0;i<arrsize;i++){
sum+=arr[i];
if(sum==k){
subsize=i+1;
}
if(!hash.containsKey(sum)){
hash.put(sum,i);
}
if(hash.containsKey(sum-k)){
if(subsize<(i-hash.get(sum-k))){
subsize=i-hash.get(sum-k);
}
}
}
System.out.println(subsize);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc =new Scanner(System.in);
int T= sc.nextInt();
for(int i=0;i<T;i++){
int arrsize=sc.nextInt();
int max=0,secmax=0,thirdmax=0,j;
for(int k=0;k<arrsize;k++){
j=sc.nextInt();
if(j>max){
thirdmax=secmax;
secmax=max;
max=j;
}
else if(j>secmax){
thirdmax=secmax;
secmax=j;
}
else if(j>thirdmax){
thirdmax=j;
}
if(k%10000==0){
System.gc();
}
}
System.out.println(max+" "+secmax+" "+thirdmax+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: t=int(input())
while t>0:
t-=1
n=int(input())
l=list(map(int,input().strip().split()))
li=[0,0,0]
for i in l:
x=i
for j in range(0,3):
y=min(x,li[j])
li[j]=max(x,li[j])
x=y
print(li[0],end=" ")
print(li[1],end=" ")
print(li[2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
vector<long> a(n);
long ans[3]={0};
long x,y;
for(int i=0;i<n;i++){
cin>>a[i];
x=a[i];
for(int j=0;j<3;j++){
y=min(x,ans[j]);
ans[j]=max(x,ans[j]);
// cout<<ans[j]<<" ";
x=y;
}
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
if(ans[2]<ans[1]){
swap(ans[1],ans[2]);
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: function maxNumbers(arr,n) {
// write code here
// do not console.log the answer
// return the answer as an array of 3 numbers
return arr.sort((a,b)=>b-a).slice(0,3)
};
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10, 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());
int n;
while(t>0) {
n = Integer.parseInt(br.readLine());
int a[] = new int[n];
String s = br.readLine();
String arr[] = s.split(" ");
for(int i=0;i<n;i++) {
a[i] = Integer.parseInt(arr[i]);
}
int b[] = sort(a);
for(int i=0;i<n;i++) {
System.out.print(b[i] + " ");
}
System.out.println();
t--;
}
}
static int[] sort(int[] a) {
int temp, index;
for(int i=0;i<a.length-1;i++) {
index = i;
for(int j=i+1;j<a.length;j++) {
if(a[j]<a[index]) {
index = j;
}
}
temp = a[i];
a[i] = a[index];
a[index] = temp;
}
return a;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: for _ in range(int(input())):
n = input()
res = map(str, sorted(list( map(int,input().split()))))
print(' '.join(res)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code: static int focal_length(int R, char Mirror)
{
int f=R/2;
if((R%2==1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code:
int focal_length(int R, char Mirror)
{
int f=R/2;
if((R&1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code:
int focal_length(int R, char Mirror)
{
int f=R/2;
if((R&1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code: def focal_length(R,Mirror):
f=R/2;
if(Mirror == ')'):
f=-f
if R%2==1:
f=f-1
return int(f)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a doubly linked list consisting of N nodes and two integers <b>P</b> and <b>K</b>. Your task is to add an element K at the Pth position from the start of the linked list<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>insertnew()</b>. The description of parameters are mentioned below:
<b>head</b>: head node of the double linked list
<b>K</b>: the element which you have to insert
<b>P</b>: the position at which you have insert
Constraints:
1 <= P <=N <= 1000
1 <=K, Node.data<= 1000
In the sample Input N, P and K are in the order as mentioned below:
<b>N P K</b>Return the head of the modified linked list.Sample Input:-
5 3 2
1 3 2 4 5
Sample Output:-
1 3 2 2 4 5, I have written this Solution Code: public static Node insertnew(Node head, int k,int pos) {
int cnt=1;
if(pos==1){Node temp=new Node(k);
temp.next=head;
head.prev=temp;
return temp;}
Node temp=head;
while(cnt!=pos-1){
temp=temp.next;
cnt++;
}
Node x= new Node(k);
x.next=temp.next;
temp.next.prev=x;
temp.next=x;
x.prev=temp;
return head;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string your task is to reverse the given string.The first line of the input contains a string.
Constraints:-
1 <= string length <= 100
String contains only lowercase english lettersThe output should contain reverse of the input string.Sample Input
abc
Sample Output
cba, I have written this Solution Code: s = input("")
print (s[::-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string your task is to reverse the given string.The first line of the input contains a string.
Constraints:-
1 <= string length <= 100
String contains only lowercase english lettersThe output should contain reverse of the input string.Sample Input
abc
Sample Output
cba, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
reverse(s.begin(),s.end());
cout<<s;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string your task is to reverse the given string.The first line of the input contains a string.
Constraints:-
1 <= string length <= 100
String contains only lowercase english lettersThe output should contain reverse of the input string.Sample Input
abc
Sample Output
cba, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String s = sc.next();
for(int i = s.length()-1;i>=0;i--){
System.out.print(s.charAt(i));
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code:
int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code: static int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code: int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code:
def DragonSlayer(A,B,C,D):
x = C//B
if(C%B!=0):
x=x+1
y = A//D
if(A%D!=0):
y=y+1
if(x<y):
return 0
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number <b>N</b>, find the count of pairs(x, y) such that the absolute value of sum of x<sup>3</sup> and y<sup>3</sup> is equal to N, i. e |x<sup>3</sup> + y<sup>3</sup>|=N<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pairs()</b> that takes the integer N as parameter
<b>Constraints</b>
1 <= N <= 10<sup>8</sup>Return the <b>count of pairs</b> which satisfies the given condition.Sample Input:-
8
Sample Output:-
2
Explanation:-
The required pairs are (0, -2), (0, 2)
Sample Input:-
3
Sample Output:-
0, I have written this Solution Code: def Pairs(N):
cnt=0
for i in range(-1000, 1001):
for j in range (i,1001):
a=i*i*i
b=j*j*j
if abs(a+b)==N:
cnt=cnt+1
return cnt, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number <b>N</b>, find the count of pairs(x, y) such that the absolute value of sum of x<sup>3</sup> and y<sup>3</sup> is equal to N, i. e |x<sup>3</sup> + y<sup>3</sup>|=N<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pairs()</b> that takes the integer N as parameter
<b>Constraints</b>
1 <= N <= 10<sup>8</sup>Return the <b>count of pairs</b> which satisfies the given condition.Sample Input:-
8
Sample Output:-
2
Explanation:-
The required pairs are (0, -2), (0, 2)
Sample Input:-
3
Sample Output:-
0, I have written this Solution Code: int Pairs(long N){
int cnt=0;
long int sum=0,a,b,i,j;
for(i=-6000 ;i<=6000;i++){
for(j=i; j<=6000;j++){
a=i*i*i;
b=j*j*j;
if((a+b)>0 && (a+b)==N){
cnt++;}
else if((a+b)<0 && (a+b) ==(-N)){cnt++;}
}}
return cnt;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number <b>N</b>, find the count of pairs(x, y) such that the absolute value of sum of x<sup>3</sup> and y<sup>3</sup> is equal to N, i. e |x<sup>3</sup> + y<sup>3</sup>|=N<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pairs()</b> that takes the integer N as parameter
<b>Constraints</b>
1 <= N <= 10<sup>8</sup>Return the <b>count of pairs</b> which satisfies the given condition.Sample Input:-
8
Sample Output:-
2
Explanation:-
The required pairs are (0, -2), (0, 2)
Sample Input:-
3
Sample Output:-
0, I have written this Solution Code: public static int Pairs(int N){
int cnt=0;
long sum=0,a,b,i;
for(i=-6000 ;i<=6000;i++){
for(long j=i; j<=6000;j++){
a=i*i*i;
b=j*j*j;
if(Math.abs(a+b)==N){
cnt++;}
}
}
return cnt;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number <b>N</b>, find the count of pairs(x, y) such that the absolute value of sum of x<sup>3</sup> and y<sup>3</sup> is equal to N, i. e |x<sup>3</sup> + y<sup>3</sup>|=N<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pairs()</b> that takes the integer N as parameter
<b>Constraints</b>
1 <= N <= 10<sup>8</sup>Return the <b>count of pairs</b> which satisfies the given condition.Sample Input:-
8
Sample Output:-
2
Explanation:-
The required pairs are (0, -2), (0, 2)
Sample Input:-
3
Sample Output:-
0, I have written this Solution Code:
int Pairs(long N){
int cnt=0;
long int sum=0,a,b,i,j;
for(i=-6000 ;i<=6000;i++){
for(j=i; j<=6000;j++){
a=i*i*i;
b=j*j*j;
if(abs(a+b)==N){
cnt++;}
}
}
return cnt;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array.
The second line of each test case contains N space separated integers denoting array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^6
<b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input:
3
10
2 3 4 5 6 7 8 9 10 1
5
3 4 5 1 2
8
10 20 30 45 50 60 4 6
Output:
1
1
4
Explanation:
Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1.
Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1.
Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: def findMin(arr, low, high):
if high < low:
return arr[0]
if high == low:
return arr[low]
mid = int((low + high)/2)
if mid < high and arr[mid+1] < arr[mid]:
return arr[mid+1]
if mid > low and arr[mid] < arr[mid - 1]:
return arr[mid]
if arr[high] > arr[mid]:
return findMin(arr, low, mid-1)
return findMin(arr, mid+1, high)
T =int(input())
for i in range(T):
N = int(input())
arr = list(input().split())
for k in range(len(arr)):
arr[k] = int(arr[k])
print(findMin(arr,0,N-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array.
The second line of each test case contains N space separated integers denoting array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^6
<b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input:
3
10
2 3 4 5 6 7 8 9 10 1
5
3 4 5 1 2
8
10 20 30 45 50 60 4 6
Output:
1
1
4
Explanation:
Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1.
Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1.
Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
int l = 0, h = n+1;
if(a[1] < a[n]){
cout << a[1] << endl;
continue;
}
while(l+1 < h){
int m = (l + h) >> 1;
if(a[m] >= a[1])
l = m;
else
h = m;
}
cout << a[h] << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array.
The second line of each test case contains N space separated integers denoting array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^6
<b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input:
3
10
2 3 4 5 6 7 8 9 10 1
5
3 4 5 1 2
8
10 20 30 45 50 60 4 6
Output:
1
1
4
Explanation:
Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1.
Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1.
Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
public static void main (String[] args) {
//code
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for(int j=0;j<t;j++){
int al = s.nextInt();
int a[] = new int[al];
for(int i=0;i<al;i++){
a[i] = s.nextInt();
}
binSearchSmallest(a);
}
}
public static void binSearchSmallest(int a[]) {
int s=0;
int e = a.length - 1;
int mid = 0;
while(s<=e){
mid = (s+e)/2;
if(a[s]<a[e]){
System.out.println(a[s]);
return;
}
if(a[mid]>=a[s]){
s=mid+1;
}
else{
e=mid;
}
if(s == e){
System.out.println(a[s]);
return;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array.
The second line of each test case contains N space separated integers denoting array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^6
<b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input:
3
10
2 3 4 5 6 7 8 9 10 1
5
3 4 5 1 2
8
10 20 30 45 50 60 4 6
Output:
1
1
4
Explanation:
Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1.
Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1.
Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: // arr is the input array
function findMin(arr,n) {
// write code here
// do not console.log
// return the number
let min = arr[0]
for(let i=1;i<arr.length;i++){
if(min > arr[i]){
min = arr[i]
}
}
return min
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N-size array of unique integers, your task is to print the array in a waveform, i. e a1 >= a2 <= a3 >= a4 <= a5.. . print the lexicographically smallest array possible.The first line of input contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ Arr[i] ≤ 10<sup>9</sup>Print the array in wave form as mentioned.Sample Input :-
5
2 1 3 5 4
Sample Output:-
2 1 4 3 5
Sample Input:-
3
1 2 3
Sample Output:-
2 1 3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(read.readLine());
StringTokenizer st = new StringTokenizer(read.readLine());
int[] arr = new int[N];
for(int i=0; i<N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr);
StringBuilder res = new StringBuilder();
for(int i=0; i<N-1; i+=2) {
int temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;
res.append(arr[i] + " ");
res.append(arr[i+1] + " ");
}
if(N % 2 != 0) {
res.append(arr[N-1]);
}
System.out.print(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N-size array of unique integers, your task is to print the array in a waveform, i. e a1 >= a2 <= a3 >= a4 <= a5.. . print the lexicographically smallest array possible.The first line of input contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ Arr[i] ≤ 10<sup>9</sup>Print the array in wave form as mentioned.Sample Input :-
5
2 1 3 5 4
Sample Output:-
2 1 4 3 5
Sample Input:-
3
1 2 3
Sample Output:-
2 1 3, I have written this Solution Code: n = int(input())
a = list(map(int,input().strip().split()))
a.sort()
for i in range(0,n-1,2):
print("{} ".format(a[i+1]),end="")
print("{} ".format(a[i]),end="")
if n&1:
print("{} ".format(a[n-1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N-size array of unique integers, your task is to print the array in a waveform, i. e a1 >= a2 <= a3 >= a4 <= a5.. . print the lexicographically smallest array possible.The first line of input contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ Arr[i] ≤ 10<sup>9</sup>Print the array in wave form as mentioned.Sample Input :-
5
2 1 3 5 4
Sample Output:-
2 1 4 3 5
Sample Input:-
3
1 2 3
Sample Output:-
2 1 3, I have written this Solution Code: #include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int n,m;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n-1;i+=2){
cout<<a[i+1]<<" ";
cout<<a[i]<<" ";
}
if(n&1){
cout<<a[n-1]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You went to shopping. You bought an item worth N rupees. What is the minimum change that you can get from the shopkeeper if you possess only 200 and 500 rupees notes.
Eg: If N = 678, the minimum change you can receive is 22, if you pay the shopkeeper a 500 and a 200 rupee note. You can show that no other combination can lead to a change lesser than this like (200, 200, 200, 200) or (500, 500).
Note: You have infinite number of 200 and 500 rupees notes. Enjoy, XD.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000000000Output a single integer, the minimum amount of change that you will receive.Sample Input
678
Sample Output
22
Sample Input
900
Sample Output
0, I have written this Solution Code: def sample(n):
if n<200:
print(200-n)
elif n<400:
print(400-n)
elif n<500:
print(500-n)
else:
div=n//100
if div*100==n:
print(0)
else:
print((div+1)*100-n)
n=int(input())
sample(n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You went to shopping. You bought an item worth N rupees. What is the minimum change that you can get from the shopkeeper if you possess only 200 and 500 rupees notes.
Eg: If N = 678, the minimum change you can receive is 22, if you pay the shopkeeper a 500 and a 200 rupee note. You can show that no other combination can lead to a change lesser than this like (200, 200, 200, 200) or (500, 500).
Note: You have infinite number of 200 and 500 rupees notes. Enjoy, XD.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000000000Output a single integer, the minimum amount of change that you will receive.Sample Input
678
Sample Output
22
Sample Input
900
Sample Output
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
if(n <= 200){
cout<<200-n;
return;
}
if(n <= 400){
cout<<400-n;
return;
}
int ans = (100-n%100)%100;
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You went to shopping. You bought an item worth N rupees. What is the minimum change that you can get from the shopkeeper if you possess only 200 and 500 rupees notes.
Eg: If N = 678, the minimum change you can receive is 22, if you pay the shopkeeper a 500 and a 200 rupee note. You can show that no other combination can lead to a change lesser than this like (200, 200, 200, 200) or (500, 500).
Note: You have infinite number of 200 and 500 rupees notes. Enjoy, XD.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000000000Output a single integer, the minimum amount of change that you will receive.Sample Input
678
Sample Output
22
Sample Input
900
Sample Output
0, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int ans=0;
if(n <= 200){
ans = 200-n;
}
else if(n <= 400){
ans=400-n;
}
else{
ans = (100-n%100)%100;
}
System.out.print(ans);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Phoebe is a big GCD fan. Being bored, she starts counting number of pairs of integers (A, B) such that following conditions are satisfied:
<li> GCD(A, B) = X (As X is Phoebe's favourite integer)
<li> A <= B <= L
As Phoebe's performance is coming up, she needs your help to find the number of such pairs possible.
Note: GCD refers to the <a href="https://en.wikipedia.org/wiki/Greatest_common_divisor">Greatest common divisor</a>.Input contains two integers L and X.
Constraints:
1 <= L, X <= 1000000000Print a single integer denoting number of pairs possible.Sample Input
5 2
Sample Output
2
Explanation: Pairs satisfying all conditions are: (2, 2), (2, 4)
Sample Input
5 3
Sample Output
1
Explanation: Pairs satisfying all conditions are: (3, 3), I have written this Solution Code: import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
out.println(sumTotient(ni()/ni()));
}
public static int[] enumTotientByLpf(int n, int[] lpf)
{
int[] ret = new int[n+1];
ret[1] = 1;
for(int i = 2;i <= n;i++){
int j = i/lpf[i];
if(lpf[j] != lpf[i]){
ret[i] = ret[j] * (lpf[i]-1);
}else{
ret[i] = ret[j] * lpf[i];
}
}
return ret;
}
public static int[] enumLowestPrimeFactors(int n)
{
int tot = 0;
int[] lpf = new int[n+1];
int u = n+32;
double lu = Math.log(u);
int[] primes = new int[(int)(u/lu+u/lu/lu*1.5)];
for(int i = 2;i <= n;i++)lpf[i] = i;
for(int p = 2;p <= n;p++){
if(lpf[p] == p)primes[tot++] = p;
int tmp;
for(int i = 0;i < tot && primes[i] <= lpf[p] && (tmp = primes[i]*p) <= n;i++){
lpf[tmp] = primes[i];
}
}
return lpf;
}
public static long sumTotient(int n)
{
if(n == 0)return 0L;
if(n == 1)return 1L;
int s = (int)Math.sqrt(n);
long[] cacheu = new long[n/s];
long[] cachel = new long[s+1];
int X = (int)Math.pow(n, 0.66);
int[] lpf = enumLowestPrimeFactors(X);
int[] tot = enumTotientByLpf(X, lpf);
long sum = 0;
int p = cacheu.length-1;
for(int i = 1;i <= X;i++){
sum += tot[i];
if(i <= s){
cachel[i] = sum;
}else if(p > 0 && i == n/p){
cacheu[p] = sum;
p--;
}
}
for(int i = p;i >= 1;i--){
int x = n/i;
long all = (long)x*(x+1)/2;
int ls = (int)Math.sqrt(x);
for(int j = 2;x/j > ls;j++){
long lval = i*j < cacheu.length ? cacheu[i*j] : cachel[x/j];
all -= lval;
}
for(int v = ls;v >= 1;v--){
long w = x/v-x/(v+1);
all -= cachel[v]*w;
}
cacheu[(int)i] = all;
}
return cacheu[1];
}
void run() throws Exception
{
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new Main().run(); }
private byte[] inbuf = new byte[1024];
private int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Phoebe is a big GCD fan. Being bored, she starts counting number of pairs of integers (A, B) such that following conditions are satisfied:
<li> GCD(A, B) = X (As X is Phoebe's favourite integer)
<li> A <= B <= L
As Phoebe's performance is coming up, she needs your help to find the number of such pairs possible.
Note: GCD refers to the <a href="https://en.wikipedia.org/wiki/Greatest_common_divisor">Greatest common divisor</a>.Input contains two integers L and X.
Constraints:
1 <= L, X <= 1000000000Print a single integer denoting number of pairs possible.Sample Input
5 2
Sample Output
2
Explanation: Pairs satisfying all conditions are: (2, 2), (2, 4)
Sample Input
5 3
Sample Output
1
Explanation: Pairs satisfying all conditions are: (3, 3), I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
template<class C> void mini(C&a4, C b4){a4=min(a4,b4);}
typedef unsigned long long ull;
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define mod 1000000007ll
#define pii pair<int,int>
/////////////
ull X[20000001];
ull cmp(ull N){
return N*(N+1)/2;
}
ull solve(ull N){
if(N==1)
return 1;
if(N < 20000001 && X[N] != 0)
return X[N];
ull res = 0;
ull q = floor(sqrt(N));
for(int k=2;k<N/q+1;++k){
res += solve(N/k);
}
for(int m=1;m<q;++m){
res += (N/m - N/(m+1)) * solve(m);
}
res = cmp(N) - res;
if(N < 20000001)
X[N] = res;
return res;
}
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int l,x;
cin>>l>>x;
if(l<x)
cout<<0;
else
cout<<solve(l/x);
#ifdef ANIKET_GOYAL
cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code: function numberOfDays(n)
{
let ans;
switch(n)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
ans = Number(31);
break;
case 2:
ans = Number(28);
break;
default:
ans = Number(30);
break;
}
return ans;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code:
static void numberofdays(int M){
if(M==4 || M ==6 || M==9 || M==11){System.out.print(30);}
else if(M==2){System.out.print(28);}
else{
System.out.print(31);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Print_Digit()</b> that takes integer N as a parameter.
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>7</sup>Print the digits of the number as shown in the example.
<b>Note:-</b>
Print all digits in lowercase English lettersSample Input:-
1024
Sample Output:-
one zero two four
Sample Input:-
2
Sample Output:-
two, I have written this Solution Code: def Print_Digit(n):
dc = {1: "one", 2: "two", 3: "three", 4: "four",
5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 0: "zero"}
final_list = []
while (n > 0):
final_list.append(dc[int(n%10)])
n = int(n / 10)
for val in final_list[::-1]:
print(val, end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Print_Digit()</b> that takes integer N as a parameter.
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>7</sup>Print the digits of the number as shown in the example.
<b>Note:-</b>
Print all digits in lowercase English lettersSample Input:-
1024
Sample Output:-
one zero two four
Sample Input:-
2
Sample Output:-
two, I have written this Solution Code: class Solution {
public static void Print_Digits(int N){
if(N==0){return;}
Print_Digits(N/10);
int x=N%10;
if(x==1){System.out.print("one ");}
else if(x==2){System.out.print("two ");}
else if(x==3){System.out.print("three ");}
else if(x==4){System.out.print("four ");}
else if(x==5){System.out.print("five ");}
else if(x==6){System.out.print("six ");}
else if(x==7){System.out.print("seven ");}
else if(x==8){System.out.print("eight ");}
else if(x==9){System.out.print("nine ");}
else if(x==0){System.out.print("zero ");}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string, reverse each word in the sentenceA string containing multiple words
ex:- "Welcome to this Javascript Guide!"A string with all words reversed
ex:- "emocleW ot siht tpircsavaJ !ediuG"Sample input:-
"Welcome to this Javascript Guide!"
Sample output:-
"emocleW ot siht tpircsavaJ !ediuG"
Explanation:-
The first word is reversed from "Welcome" to "emocleW"
and similarly all other wrods are reversed but the order of the words is same, I have written this Solution Code: function reverseBySeparator(string, separator) {
return string.split(separator).reverse().join(separator);
}
function reverseWords (str){
const step1 = reverseBySeparator(str,"")
const step2 = reverseBySeparator(step1," ")
console.log(step2)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string, reverse each word in the sentenceA string containing multiple words
ex:- "Welcome to this Javascript Guide!"A string with all words reversed
ex:- "emocleW ot siht tpircsavaJ !ediuG"Sample input:-
"Welcome to this Javascript Guide!"
Sample output:-
"emocleW ot siht tpircsavaJ !ediuG"
Explanation:-
The first word is reversed from "Welcome" to "emocleW"
and similarly all other wrods are reversed but the order of the words is same, I have written this Solution Code: import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Stack;
import static java.lang.Math.pow;
class InputReader {
private boolean finished = false;
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public static InputReader getInputReader(boolean readFromTextFile) throws FileNotFoundException {
return ((readFromTextFile) ? new InputReader(new FileInputStream("src/input.txt"))
: new InputReader(System.in));
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int peek() {
if (numChars == -1) {
return -1;
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String nextString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c)) {
res.appendCodePoint(c);
}
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private String readLine0() {
StringBuilder buf = new StringBuilder();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r') {
buf.appendCodePoint(c);
}
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0) {
s = readLine0();
}
return s;
}
public String readLine(boolean ignoreEmptyLines) {
if (ignoreEmptyLines) {
return readLine();
} else {
return readLine0();
}
}
public BigInteger readBigInteger() {
try {
return new BigInteger(nextString());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
public char nextCharacter() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
return (char) c;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E') {
return res * pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E') {
return res * pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public boolean isExhausted() {
int value;
while (isSpaceChar(value = peek()) && value != -1) {
read();
}
return value == -1;
}
public String next() {
return nextString();
}
public SpaceCharFilter getFilter() {
return filter;
}
public void setFilter(SpaceCharFilter filter) {
this.filter = filter;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
public int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; ++i) array[i] = nextInt();
return array;
}
public int[] nextSortedIntArray(int n) {
int array[] = nextIntArray(n);
Arrays.sort(array);
return array;
}
public int[] nextSumIntArray(int n) {
int[] array = new int[n];
array[0] = nextInt();
for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
return array;
}
public long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; ++i) array[i] = nextLong();
return array;
}
public long[] nextSumLongArray(int n) {
long[] array = new long[n];
array[0] = nextInt();
for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
return array;
}
public long[] nextSortedLongArray(int n) {
long array[] = nextLongArray(n);
Arrays.sort(array);
return array;
}
}
class Main {
public static void main(String[] args) throws FileNotFoundException {
InputReader sc = InputReader.getInputReader(false);
String str = sc.readLine();
char[] charArray = str.toCharArray();
Stack<Character> st = new Stack<>();
for (int i = 0; i < charArray.length; i++) {
while (i < charArray.length && charArray[i] != ' ') {
st.push(charArray[i]);
i++;
}
while (!st.isEmpty()) {
System.out.print(st.pop());
}
System.out.print(" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException
{
InputStreamReader pk = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(pk);
String[] strNums;
int num[] = new int[4];
strNums = in.readLine().split(" ");
for (int i = 0; i < strNums.length; i++) {
num[i] = Integer.parseInt(strNums[i]);
}
if((num[0]<(num[1]+num[2])) || (num[0]<(num[1]*num[3])))
System.out.println("1");
else
System.out.println("0");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: a = []
a = list(map(int, input().split()))
if a[1]+a[2] > a[0] or a[1]*a[3] > a[0]:
defeat = 1
else:
defeat = 0
print(defeat), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., 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>
// #include <sys/resource.h>
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 f first
#define s 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()
#define start_clock() auto start_time = std::chrono::high_resolution_clock::now();
#define measure() auto end_time = std::chrono::high_resolution_clock::now(); cerr << (end_time - start_time)/std::chrono::milliseconds(1) << "ms" << endl;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifdef LOCALY
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
// DEBUG FUNCTIONS END
// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // FOR RANDOM NUMBER GENERATION
ll mod_exp(ll a, ll b, ll c)
{
ll res=1; a=a%c;
while(b>0)
{
if(b%2==1)
res=(res*a)%c;
b/=2;
a=(a*a)%c;
}
return res;
}
ll mymod(ll a,ll b)
{
return (((a = a%b) < 0) ? a + b : a);
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
g++; //this line was added just to remove compiler warning
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct Graph
{
vector<vector<int>> adj;
Graph(int n)
{
adj.resize(n+1);
}
void add_edge(int a, int b, bool directed = false)
{
adj[a].pb(b);
if(!directed) adj[b].pb(a);
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll M, Y, R, G;
cin >> M >> Y >> R >> G;
ll maxm = Y;
maxm = max(maxm, Y+R);
maxm = max(maxm, Y*G);
cout << (M < maxm) << "\n";
return 0;
}
/*
1. Check borderline constraints. Can a variable you are dividing by be 0?
2. Use ll while using bitshifts
3. Do not erase from set while iterating it
4. Initialise everything
5. Read the task carefully, is something unique, sorted, adjacent, guaranteed??
6. DO NOT use if(!mp[x]) if you want to iterate the map later
7. Are you using i in all loops? Are the i's conflicting?
*/
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation.
<b>Note:-</b>
The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array.
<b>Constraints:</b>
1 <= T <= 50
3 <= N <= 10^3
1 <= A[i] <= 10^4
Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input:
2
4
3 4 1 2
3
1 3 2
Sample Output:
Yes
Yes
<b>Explanation:</b>
Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2).
Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
bool check_increasing(int n){
int id = 0;
for(int i = 2; i <= n; i++){
if(a[i] < a[i-1]){
id = i;
break;
}
}
if(id == 0) return 0;
int cur = id+1;
while(cur != id+n){
if(a[cur] <= a[cur-1])
return 0;
cur++;
}
return 1;
}
bool check_decreasing(int n){
int id = 0;
for(int i = 2; i <= n; i++){
if(a[i] > a[i-1]){
id = i;
break;
}
}
if(id == 0) return 0;
int cur = id+1;
while(cur != id+n){
if(a[cur] >= a[cur-1])
return 0;
cur++;
}
return 1;
}
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i], a[i+n] = a[i];
if(check_increasing(n))
cout << "Yes" << endl;
else if(check_decreasing(n))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation.
<b>Note:-</b>
The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array.
<b>Constraints:</b>
1 <= T <= 50
3 <= N <= 10^3
1 <= A[i] <= 10^4
Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input:
2
4
3 4 1 2
3
1 3 2
Sample Output:
Yes
Yes
<b>Explanation:</b>
Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2).
Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., I have written this Solution Code:
cases = int(input())
for _ in range(cases):
size = int(input())
orig = list(map(int,input().split()))
givenList = orig.copy()
givenList.sort()
flag = False
for _ in range(size-1):
ele = givenList.pop()
givenList.insert(0,ele)
if givenList == orig:
print("Yes")
flag = True
break
if not flag:
givenList.sort()
givenList.reverse()
for _ in range(size-1):
ele = givenList.pop()
givenList.insert(0,ele)
if givenList == orig:
print("Yes")
flag = True
break
if not flag:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation.
<b>Note:-</b>
The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array.
<b>Constraints:</b>
1 <= T <= 50
3 <= N <= 10^3
1 <= A[i] <= 10^4
Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input:
2
4
3 4 1 2
3
1 3 2
Sample Output:
Yes
Yes
<b>Explanation:</b>
Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2).
Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine().trim()); //Inputting the testcases
while(t-->0){
long n = Long.parseLong(br.readLine());
int arr[] = new int[(int)n];
String inputLine[] = br.readLine().trim().split("\\s+");
for(long i=0; i<n; i++){
arr[(int)i] = Integer.parseInt(inputLine[(int)i]);
}
long mini = Integer.MAX_VALUE, maxi = Integer.MIN_VALUE;
long max_index = 0, min_index = 0;
for(long i=0; i<n; i++){
if(maxi < arr[(int)i]){
maxi = arr[(int)i];
max_index = i;
}
if(mini > arr[(int)i]){
mini = arr[(int)i];
min_index = i;
}
}
int flag = 0;
if(max_index == min_index -1)
flag = 1;
else if(min_index == max_index - 1)
flag = -1;
if(flag == 1){
for(long i = 1; flag==1 && i<=max_index; ++i){
if(arr[(int)i-1] >= arr[(int)i])
flag = 0;
}
for(long i = min_index+1; flag==1 && i<n; ++i){
if(arr[(int)i-1] >= arr[(int)i])
flag = 0;
}
if(arr[0]<=arr[(int)n-1])
flag = 0;
} else if(flag == -1){
for(long i = 1; flag ==-1 && i<=min_index; ++i){
if(arr[(int)i-1] <= arr[(int)i])
flag = 0;
}
for(long i = max_index+1; flag==-1 && i<n; ++i){
if(arr[(int)i-1] <= arr[(int)i])
flag = 0;
}
if(arr[0]>=arr[(int)n-1])
flag = 0;
}
if(flag == 0)
System.out.println("No");
else
System.out.println("Yes");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square.
<b>Constraints:</b>
1 <= side <=100You just have to print the area of a squareSample Input:-
3
Sample Output:-
9
Sample Input:-
6
Sample Output:-
36, I have written this Solution Code: def area(side_of_square):
print(side_of_square*side_of_square)
def main():
N = int(input())
area(N)
if __name__ == '__main__':
main(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square.
<b>Constraints:</b>
1 <= side <=100You just have to print the area of a squareSample Input:-
3
Sample Output:-
9
Sample Input:-
6
Sample Output:-
36, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int side = Integer.parseInt(br.readLine());
System.out.print(side*side);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the marks of N students, your task is to calculate the average of the marks obtained.First line of input contains a single integer N. The next line contains N space separated integers containing the marks of the students.
Constraints:-
1 <= N <= 1000
1 <= marks <= 1000Print the floor of the average of marks obtained.Sample Input:-
4
1 2 3 4
Sample Output:-
2
Sample Input:-
3
5 5 5
Sample Output:-
5, I have written this Solution Code: n=int(input())
a=list(map(int,input().split()))
print(sum(a)//n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the marks of N students, your task is to calculate the average of the marks obtained.First line of input contains a single integer N. The next line contains N space separated integers containing the marks of the students.
Constraints:-
1 <= N <= 1000
1 <= marks <= 1000Print the floor of the average of marks obtained.Sample Input:-
4
1 2 3 4
Sample Output:-
2
Sample Input:-
3
5 5 5
Sample Output:-
5, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.*;
class Main {
public static void main (String[] args)throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
System.out.print(Average_Marks(a,n));
}
static int Average_Marks(int marks[],int N){
int sum=0;
for(int i=0;i<N;i++){
sum+=marks[i];
}
return sum/N;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Hi, it's Monica!
Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle.
Constraints
1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input
3
Sample Output
Yes
Sample Input
10
Sample Output
No, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Cf cf = new Cf();
cf.solve();
}
static class Cf {
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
int mod = (int)1e9+7;
public void solve() {
int t = in.readInt();
if(t>=6) {
out.printLine("No");
}else {
out.printLine("Yes");
}
}
public long findPower(long x,long n) {
long ans = 1;
long nn = n;
while(nn>0) {
if(nn%2==1) {
ans = (ans*x) % mod;
nn-=1;
}else {
x = (x*x)%mod;
nn/=2;
}
}
return ans%mod;
}
public static int log2(int x) {
return (int) (Math.log(x) / Math.log(2));
}
private static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public double readDouble() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, readInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, readInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
private 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]);
}
writer.flush();
}
public void printLine(Object... objects) {
print(objects);
writer.println();
writer.flush();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Hi, it's Monica!
Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle.
Constraints
1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input
3
Sample Output
Yes
Sample Input
10
Sample Output
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
template<class C> void mini(C&a4, C b4){a4=min(a4,b4);}
typedef unsigned long long ull;
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define mod 1000000007ll
#define pii pair<int,int>
/////////////
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
if(n<6)
cout<<"Yes";
else
cout<<"No";
#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: Hi, it's Monica!
Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle.
Constraints
1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input
3
Sample Output
Yes
Sample Input
10
Sample Output
No, I have written this Solution Code: n=int(input())
if(n>=6):
print("No")
else:
print("Yes"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: import java.io.*;
import java.util.*;
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 sc= new FastReader();
String str= sc.nextLine();
String a="Apple";
if(a.equals(str)){
System.out.println("Gravity");
}
else{
System.out.println("Space");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
//-----------------------------------------------------------------------------------------------------------//
string S;
cin>>S;
if(S=="Apple")
{
cout<<"Gravity"<<endl;
}
else
{
cout<<"Space"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: n=input()
if n=='Apple':print('Gravity')
else:print('Space'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are Q queries and for each query you are given a positive integer N. Find whether N is a perfect square or not.
Expected Space Complexity: O(1)First line contains an integer Q - the number of queries.
Q lines follow, each line containing a single integer N.
Constraints
1 <= Q <= 10^5
1 <= Ai <= 10^9Print Q lines. Each line should contain either "YES" or "NO".Sample Input 1:
3
1
2
4
Output
YES
NO
YES
Explanation:
1 and 4 are perfect squares.
Sample Input 2:
2
144
63
Output
YES
NO
Explanation:
12 * 12 = 144, I have written this Solution Code: import math
def checkperfectsquare(x):
if (math.ceil(math.sqrt(n)) ==
math.floor(math.sqrt(n))):
print("YES")
else:
print("NO")
t=int(input())
for _ in range(t):
n=int(input())
checkperfectsquare(n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are Q queries and for each query you are given a positive integer N. Find whether N is a perfect square or not.
Expected Space Complexity: O(1)First line contains an integer Q - the number of queries.
Q lines follow, each line containing a single integer N.
Constraints
1 <= Q <= 10^5
1 <= Ai <= 10^9Print Q lines. Each line should contain either "YES" or "NO".Sample Input 1:
3
1
2
4
Output
YES
NO
YES
Explanation:
1 and 4 are perfect squares.
Sample Input 2:
2
144
63
Output
YES
NO
Explanation:
12 * 12 = 144, 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) {
Scanner sc = new Scanner(System.in);
long Q = sc.nextLong();
while(Q-- > 0){
long n = sc.nextLong();
long sqrt = (long)Math.sqrt(n);
if(sqrt*sqrt == n){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are Q queries and for each query you are given a positive integer N. Find whether N is a perfect square or not.
Expected Space Complexity: O(1)First line contains an integer Q - the number of queries.
Q lines follow, each line containing a single integer N.
Constraints
1 <= Q <= 10^5
1 <= Ai <= 10^9Print Q lines. Each line should contain either "YES" or "NO".Sample Input 1:
3
1
2
4
Output
YES
NO
YES
Explanation:
1 and 4 are perfect squares.
Sample Input 2:
2
144
63
Output
YES
NO
Explanation:
12 * 12 = 144, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
int x = sqrt(n);
if (x * x == n) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: Given a linked list of N nodes. The task is to reverse the list by changing links between nodes (i.e if the list is 1->2->3->4 then it becomes 1<-2<-3<-4) and return the head of the modified list.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b> ReverseLinkedList</b> that takes head node as parameter.
Constraints:
1 <=N <= 1000
1 <= Node.data<= 100Return the head of the modified linked list.Input-1:
6
1 2 3 4 5 6
Output-1:
6 5 4 3 2 1
Explanation:
After reversing the list, elements are as 6->5->4->3->2->1.
Input-2:
5
1 2 8 4 5
Output-2:
5 4 8 2 1, I have written this Solution Code: public static Node ReverseLinkedList(Node head) {
Node prev = null;
Node current = head;
Node next = null;
while (current != null) {
next = current.next;
current.next = prev;
prev = current;
current = next;
}
head = prev;
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a circular singly linked list containing N nodes, the task is to delete all the even nodes from the list.
Note:-The first digit of the list will always be an odd integer.
<b>Note:</b>Examples in Sample Input and Output just shows how a linked list will look like depending on the questions. Do not copy-paste as it is in <b>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>deleteEven()</b> that takes head node of circular linked list as parameter.
Constraints:
1 <=N <= 1000
1 <= Node. data <= 1000Return the head of the modified listSample Input:-
4
1 2 3 4
Sample Output:-
1 3
Explanation:
1- >2- >3- >4- >1
After deletion of nodes
1- >3- >1
Sample Input:-
5
1 4 6 5 8
Sample Output:-
1 5
Explanation:
1- >4- >6- >5- >8->1
After deletion of nodes
1->5->1, I have written this Solution Code: static Node deleteNode(Node head_ref, Node del)
{
Node temp = head_ref;
// If node to be deleted is head node
if (head_ref == del)
head_ref = del.next;
// traverse list till not found
// delete node
while (temp.next != del)
{
temp = temp.next;
}
// copy address of node
temp.next = del.next;
return head_ref;
}
// Function to delete all even nodes
// from the singly circular linked list
static Node deleteEven(Node head)
{
Node ptr = head;
Node next;
// traverse list till the end
// if the node is even then delete it
do
{
// if node is even
if (ptr.data % 2 == 0)
deleteNode(head, ptr);
// point to next node
next = ptr.next;
ptr = next;
}
while (ptr != head);
return head;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to become rich so he came up with an idea, So, he buys some gadgets from the future at a price of C and sells them at a price of S to his friends. Now Nobita wants to know how much he gains by selling all gadget. As we all know Nobita is weak in maths help him to find the profit he getsYou don't have to worry about the input, you just have to complete the function <b>Profit()</b>
<b>Constraints:-</b>
1 <= C <= S <= 1000Print the profit Nobita gets from selling one gadget.Sample Input:-
3 5
Sample Output:-
2
Sample Input:-
9 16
Sample Output:-
7, I have written this Solution Code: def profit(C, S):
print(S - C), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to become rich so he came up with an idea, So, he buys some gadgets from the future at a price of C and sells them at a price of S to his friends. Now Nobita wants to know how much he gains by selling all gadget. As we all know Nobita is weak in maths help him to find the profit he getsYou don't have to worry about the input, you just have to complete the function <b>Profit()</b>
<b>Constraints:-</b>
1 <= C <= S <= 1000Print the profit Nobita gets from selling one gadget.Sample Input:-
3 5
Sample Output:-
2
Sample Input:-
9 16
Sample Output:-
7, I have written this Solution Code: static void Profit(int C, int S){
System.out.println(S-C);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N +1 integers containing N different elements, your task is to print the array without the repeating element in it.First line of input contains a single integer N, the next line contains N +1 space separated integers containing values of Arr.
Constraints:-
1 < = N < = 1000
1 < = Arr[i] < = 10<sup>5</sup>Print the array without the duplicate element.Sample Input:-
5
1 2 3 4 5 1
Sample Output:-
1 2 3 4 5
Sample Input:-
5
2 4 5 5 9 8
Sample Output:-
2 4 5 9 8, I have written this Solution Code: N=int(input())
Arr=list(map(int, input().split()))
arr_unrepeated=[]
for i in Arr:
if i not in arr_unrepeated:
arr_unrepeated.append(i)
for j in arr_unrepeated:
print (j, 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 +1 integers containing N different elements, your task is to print the array without the repeating element in it.First line of input contains a single integer N, the next line contains N +1 space separated integers containing values of Arr.
Constraints:-
1 < = N < = 1000
1 < = Arr[i] < = 10<sup>5</sup>Print the array without the duplicate element.Sample Input:-
5
1 2 3 4 5 1
Sample Output:-
1 2 3 4 5
Sample Input:-
5
2 4 5 5 9 8
Sample Output:-
2 4 5 9 8, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
long long a;
map<long long,int> m;
for(int i=0;i<n+1;i++){
cin>>a;
if(m.find(a)==m.end()){cout<<a<<" ";}
m[a]++;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N +1 integers containing N different elements, your task is to print the array without the repeating element in it.First line of input contains a single integer N, the next line contains N +1 space separated integers containing values of Arr.
Constraints:-
1 < = N < = 1000
1 < = Arr[i] < = 10<sup>5</sup>Print the array without the duplicate element.Sample Input:-
5
1 2 3 4 5 1
Sample Output:-
1 2 3 4 5
Sample Input:-
5
2 4 5 5 9 8
Sample Output:-
2 4 5 9 8, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine().trim());
String str[]= br.readLine().trim().split(" ");
HashSet <String> hs=new HashSet<>();
for(String s:str){
if(!hs.contains(s)){
hs.add(s);
System.out.print(s+" ");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two binary strings of length N. You have to output a resultant string. The resultant string will be calculated in the following way:
- > For every position i, if the i<sup>th</sup> character of the first string is '1' and the second string is '0', the resultant string will have '1'. Also, for every position i, if the i<sup>th</sup> character of the first string is '0' and the second string is '1', the resultant string will have '1'. Rest, all the characters of the resultant string will be '0'. Find the resultant string;The first line of the input contains a single integer N.
The next two lines of the input will contain a string of size N each.
Constraints:
1 <= N <= 10<sup>5</sup>
All characters of the string will be either '1' or '0'Print the resultant string.Sample Input:
5
10110
01101
Sample Output:
11011, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
String s1 = in.readLine().trim();
String s2 = in.readLine().trim();
StringBuilder ansString = new StringBuilder();
for(int i=0; i<n ; i++){
if(s1.charAt(i) == s2.charAt(i))
ansString.append('0');
else
ansString.append('1');
}
System.out.print(ansString);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two binary strings of length N. You have to output a resultant string. The resultant string will be calculated in the following way:
- > For every position i, if the i<sup>th</sup> character of the first string is '1' and the second string is '0', the resultant string will have '1'. Also, for every position i, if the i<sup>th</sup> character of the first string is '0' and the second string is '1', the resultant string will have '1'. Rest, all the characters of the resultant string will be '0'. Find the resultant string;The first line of the input contains a single integer N.
The next two lines of the input will contain a string of size N each.
Constraints:
1 <= N <= 10<sup>5</sup>
All characters of the string will be either '1' or '0'Print the resultant string.Sample Input:
5
10110
01101
Sample Output:
11011, I have written this Solution Code: n = int(input())
s1 = input()
s2 = input()
for i in range(n):
if s1[i] == '1' and s2[i] == '0':
print('1',end="")
elif s1[i] == '0' and s2[i] == '1':
print('1',end="")
else:
print('0',end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two binary strings of length N. You have to output a resultant string. The resultant string will be calculated in the following way:
- > For every position i, if the i<sup>th</sup> character of the first string is '1' and the second string is '0', the resultant string will have '1'. Also, for every position i, if the i<sup>th</sup> character of the first string is '0' and the second string is '1', the resultant string will have '1'. Rest, all the characters of the resultant string will be '0'. Find the resultant string;The first line of the input contains a single integer N.
The next two lines of the input will contain a string of size N each.
Constraints:
1 <= N <= 10<sup>5</sup>
All characters of the string will be either '1' or '0'Print the resultant string.Sample Input:
5
10110
01101
Sample Output:
11011, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin >> n;
string a, b;
cin >> a >> b;
for(int i = 0; i < n; i++){
if(a[i] != b[i]) cout << '1';
else cout << '0';
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John has N candies. He wants to crush all of them. He feels that it would be boring to crush the candies randomly, so he found a method to crush them. He divides these candies into a minimum number of groups such that no group contains more than 3 candies. He crushes one candy from each group. If there are G groups in a single step, then the cost incurred in crushing a single candy for that step is G dollars. After candy from each group is crushed, he takes all the remaining candies and repeats the process until he has no candies left. He hasn't started crushing yet, but he wants to know how much the total cost would be incurred. Can you help him?
You have to answer Q-independent queries.The first line of input contains a single integer, Q denoting the number of queries.
Next, Q lines contain a single integer N denoting the number of candies John has.
<b>Constraints</b>
1 <= Q <= 5 * 10^4
1 <= N <= 10^9Print Q lines containing total cost incurred for each query.Sample Input 1:
1
4
Sample Output 1:
6
<b>Explanation:</b>
Query 1: First step John divides the candies into two groups of 3 and 1 candy respectively. Crushing one-one candy from both groups would cost him 2x2 = 4 dollars. He is now left with 2 candies. He divides it into one group. He crushes one candy for 1 dollar. Now, he is left with 1 candy. He crushes the last candy for 1 dollar. So, the total cost incurred is 4+1+1 = 6 dollars., I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int cost(int n){
if(n == 0) return 0;
int g = (n-1)/3 + 1;
return g*g + cost(n-g);
}
signed main() {
IOS;
clock_t start = clock();
int q; cin >> q;
while(q--){
int n;
cin >> n;
cout << cost(n) << endl;
}
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John has N candies. He wants to crush all of them. He feels that it would be boring to crush the candies randomly, so he found a method to crush them. He divides these candies into a minimum number of groups such that no group contains more than 3 candies. He crushes one candy from each group. If there are G groups in a single step, then the cost incurred in crushing a single candy for that step is G dollars. After candy from each group is crushed, he takes all the remaining candies and repeats the process until he has no candies left. He hasn't started crushing yet, but he wants to know how much the total cost would be incurred. Can you help him?
You have to answer Q-independent queries.The first line of input contains a single integer, Q denoting the number of queries.
Next, Q lines contain a single integer N denoting the number of candies John has.
<b>Constraints</b>
1 <= Q <= 5 * 10^4
1 <= N <= 10^9Print Q lines containing total cost incurred for each query.Sample Input 1:
1
4
Sample Output 1:
6
<b>Explanation:</b>
Query 1: First step John divides the candies into two groups of 3 and 1 candy respectively. Crushing one-one candy from both groups would cost him 2x2 = 4 dollars. He is now left with 2 candies. He divides it into one group. He crushes one candy for 1 dollar. Now, he is left with 1 candy. He crushes the last candy for 1 dollar. So, the total cost incurred is 4+1+1 = 6 dollars., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)
);
long q = Long.parseLong(br.readLine());
while(q-->0)
{
long N = Long.parseLong(br.readLine());
System.out.println(candyCrush(N,0,0));
}
}
static long candyCrush(long N, long cost,long group)
{
if(N==0)
{
return cost;
}
if(N%3==0)
{
group = N/3;
cost = cost + (group*group);
return candyCrush(N-group,cost,0);
}
else
{
group = (N/3)+1;
cost = cost + (group*group);
return candyCrush(N-group,cost,0);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
int[] arr=new int[5];
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
String[] s=rd.readLine().split(" ");
int sum=0;
for(int i=0;i<5;i++){
arr[i]=Integer.parseInt(s[i]);
sum+=arr[i];
}
int i=0,j=arr.length-1;
boolean isEmergency=false;
while(i<=j)
{
int temp=arr[i];
sum-=arr[i];
if(arr[i]>= sum)
{
isEmergency=true;
break;
}
sum+=temp;
i++;
}
if(isEmergency==false)
{
System.out.println("Stable");
}
else
{
System.out.println("SPD Emergency");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: arr = list(map(int,input().split()))
m = sum(arr)
f=[]
for i in range(len(arr)):
s = sum(arr[:i]+arr[i+1:])
if(arr[i]<s):
f.append(1)
else:
f.append(0)
if(all(f)):
print("Stable")
else:
print("SPD Emergency"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
vector<int> vect(5);
int tot = 0;
for(int i=0; i<5; i++){
cin>>vect[i];
tot += vect[i];
}
sort(all(vect));
tot -= vect[4];
if(vect[4] >= tot){
cout<<"SPD Emergency";
}
else{
cout<<"Stable";
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a query that joins this submit event table to the loan table and returns the total loan balance on each user's most recent refinance submission. Return all users and the loan balance for each of them.DataFrame/SQL Table with the following schema
<schema>[{'name': 'Loans', 'columns': [{'name': 'id', 'type': 'int64'}, {'name': 'user_id', 'type': 'int64'}, {'name': 'created_at', 'type': 'datetime64[ns]'}, {'name': 'status', 'type': 'object'}, {'name': 'type', 'type': 'object'}]}, {'name': 'submissions', 'Columns': [{'name': 'id', 'type': 'int64'}, {'name': 'balance', 'type': 'float64'}, {'name': 'interest_rate', 'type': 'float64'}, {'name': 'rate_type', 'type': 'object'}, {'name': 'loan_id', 'type': 'int64'}]}]</schema>Each row in new line and each value of a row separated by a |, i. e.
0|1|2
1|2|3
2|3|4-, I have written this Solution Code: import pandas as pd
df = pd.merge(loans, submissions)
for i, row in df.iterrows():
print(f"{i}|{row['balance']}"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a query that joins this submit event table to the loan table and returns the total loan balance on each user's most recent refinance submission. Return all users and the loan balance for each of them.DataFrame/SQL Table with the following schema
<schema>[{'name': 'Loans', 'columns': [{'name': 'id', 'type': 'int64'}, {'name': 'user_id', 'type': 'int64'}, {'name': 'created_at', 'type': 'datetime64[ns]'}, {'name': 'status', 'type': 'object'}, {'name': 'type', 'type': 'object'}]}, {'name': 'submissions', 'Columns': [{'name': 'id', 'type': 'int64'}, {'name': 'balance', 'type': 'float64'}, {'name': 'interest_rate', 'type': 'float64'}, {'name': 'rate_type', 'type': 'object'}, {'name': 'loan_id', 'type': 'int64'}]}]</schema>Each row in new line and each value of a row separated by a |, i. e.
0|1|2
1|2|3
2|3|4-, I have written this Solution Code: SELECT l.user_id,
SUM (balance)
FROM
(SELECT DISTINCT id, user_id, created_at,
max(created_at) OVER (PARTITION BY user_id,
TYPE) most_recent
FROM loans
WHERE TYPE = 'Refinance') l
INNER JOIN submissions s ON l.id = s.loan_id
WHERE most_recent = created_at
GROUP BY l.user_id, In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 <= n <= 100
<b>Note:</b>
<i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:-
5
Sample Output:-
2 4
Sample Input:-
6
Sample Output:-
2 4 6, I have written this Solution Code: def For_Loop(n):
string = ""
for i in range(1, n+1):
if i % 2 == 0:
string += "%s " % i
return string
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.