Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: n = int(input())
a = input().split()
print(" ".join(a[int(x)] for x in a)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String s = br.readLine();
String[] str = s.split(" ");
int arr[] = new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(str[i]);
}
for(int i =0;i<n;i++){
System.out.print(arr[arr[i]]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
long long n,k;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cout<<a[a[i]]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string s consisting of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space characters only.Input contains a single line string.
Constraints:
1 <= |String length| <= 100000Output the length of the last word.Sampe input 1
Hello World
Sample output 1
5
Explanation
Given s = "Hello World",
return 5 as length("World") = 5.
Please make sure you try to solve this problem without using library functions. Make sure you only traverse the string once., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
String x= line.trim();
int len=0;
String part[] = line.split(" ");
System.out.println(part[part.length - 1].length());
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string s consisting of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space characters only.Input contains a single line string.
Constraints:
1 <= |String length| <= 100000Output the length of the last word.Sampe input 1
Hello World
Sample output 1
5
Explanation
Given s = "Hello World",
return 5 as length("World") = 5.
Please make sure you try to solve this problem without using library functions. Make sure you only traverse the string once., I have written this Solution Code: def length_of_last_word(s):
words = s.split()
if len(words) == 0:
return 0
return len(words[-1])
a = input()
print(length_of_last_word(a)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string s consisting of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space characters only.Input contains a single line string.
Constraints:
1 <= |String length| <= 100000Output the length of the last word.Sampe input 1
Hello World
Sample output 1
5
Explanation
Given s = "Hello World",
return 5 as length("World") = 5.
Please make sure you try to solve this problem without using library functions. Make sure you only traverse the string once., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
int A[2000][2000];
int vis[200][200];
int dist[200][200];
int xa[8]={1,1,-1,-1,2,2,-2,-2};
int ya[8]={2,-2,2,-2,1,-1,1,-1};
int n,m;
int val,hh;
int check(int x,int y)
{
if (x>=0 && y>=0 && x<n && y<m )return 1;
else return 0;
}
#define qw1 freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define qw2 freopen("input2.txt", "r", stdin); freopen("output2.txt", "w", stdout);
#define qw3 freopen("input3.txt", "r", stdin); freopen("output3.txt", "w", stdout);
#define qw4 freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout);
#define qw5 freopen("input5.txt", "r", stdin); freopen("output5.txt", "w", stdout);
#define qw6 freopen("input6.txt", "r", stdin); freopen("output6.txt", "w", stdout);
#define qw freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
signed main()
{
string s;
getline(cin,s);
int n=s.size();
int cnt=0,ans=0;
for(int i=0;i<n;i++)
{
if(s[i]==' ') cnt=0;
else cnt++;
ans=max(ans,cnt);
}
cout<<cnt<<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 length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases.
The first line of each test case contains an integer n, the length of the array A
and the next line contains n integers.
Constraints:
1<=T<=100
1 <= N <= 10^5
-10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input:
1
5
1 2 3 4 -10
Output:
10
Explanation:-
1+2+3+4=10, I have written this Solution Code: t=int(input())
while t>0:
n=int(input())
a=map(int,input().split())
m=0
c=0
for i in a:
c+=i
if c>m:m=c
elif c<0:c=0
print(m)
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, A of length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases.
The first line of each test case contains an integer n, the length of the array A
and the next line contains n integers.
Constraints:
1<=T<=100
1 <= N <= 10^5
-10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input:
1
5
1 2 3 4 -10
Output:
10
Explanation:-
1+2+3+4=10, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
static long Sum(int a[], int size)
{
long max_so_far = -1000000007, max_ending_here = 0;
for (int i = 0; i < size; i++)
{
max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
if (max_ending_here < 0)
max_ending_here = 0;
}
return max_so_far;
}
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine().trim());
while(t-->0){
int n = Integer.parseInt(br.readLine().trim());
int arr[] = new int[n];
String inputLine[] = br.readLine().trim().split(" ");
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(inputLine[i]);
}
System.out.println(Sum(arr,n));
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, A of length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases.
The first line of each test case contains an integer n, the length of the array A
and the next line contains n integers.
Constraints:
1<=T<=100
1 <= N <= 10^5
-10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input:
1
5
1 2 3 4 -10
Output:
10
Explanation:-
1+2+3+4=10, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
long long Sum(long long a[], int size)
{
long long max_so_far = INT_MIN, max_ending_here = 0;
for (int i = 0; i < size; i++)
{
max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
if (max_ending_here < 0)
max_ending_here = 0;
}
return max_so_far;
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
long long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
cout<<Sum(a,n)<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: n=int(input())
a=map(int,input().split())
b=[]
mx=-200000
cnt=0
for i in a:
if i>mx:
cnt+=1
mx=i
print(cnt), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: function numberOfRoofs(arr)
{
let count=1;
let max = arr[0];
for(let i=1;i<arrSize;i++)
{
if(arr[i] > max)
{
count++;
max = arr[i];
}
}
return count;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++){
a[i]=s.nextInt();
}
int count=1;
int max = a[0];
for(int i=1;i<n;i++)
{
if(a[i] > max)
{
count++;
max = a[i];
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list consisting of N nodes and an integer K, your task is to delete the Kth node from the end of the linked list<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>deleteElement()</b> that takes head node and K as parameter.
Constraints:
1 <=K<=N<= 1000
1 <=Node.data<= 1000Return the head of the modified linked listInput 1:
5 3
1 2 3 4 5
Output 1:
1 2 4 5
Explanation:
After deleting 3rd node from the end of the linked list, 3 will be deleted and the list will be as 1, 2, 4, 5.
Input 2:-
5 5
8 1 8 3 6
Output 2:-
1 8 3 6 , I have written this Solution Code: public static Node deleteElement(Node head,int k) {
int cnt=0;
Node temp=head;
while(temp!=null){
cnt++;
temp=temp.next;
}
temp=head;
k=cnt-k;
if(k==0){head=head.next; return head;}
temp=head;
cnt=0;
while(cnt!=k-1){
temp=temp.next;
cnt++;
}
temp.next=temp.next.next;
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a circular linked list consisting of N nodes, your task is to exchange the first and last node of the list.
<b>Note:
Examples in Sample Input and Output just show how a linked list will look depending on the questions. Do not copy-paste as it is in custom input</b><b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>exchangeNodes()</b> that takes head node as parameter.
Constraints:
3 <= N <= 1000
1 <= Node. data<= 1000Return the head of the modified linked list.Sample Input 1:-
3
1- >2- >3
Sample Output 1:-
3- >2- >1
Sample Input 2:-
4
1- >2- >3- >4
Sample Output 2:-
4- >2- >3- >1, I have written this Solution Code: public static Node exchangeNodes(Node head) {
Node p = head;
while (p.next.next != head)
p = p.next;
p.next.next = head.next;
head.next = p.next;
p.next = head;
head = head.next;
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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 integer N, find its Nth smallest non negative integer that is divisible by N.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000Output a single integer, the Nth smallest non negative multiple of N.Sample Input
5
Sample Output
20
Explanation: The 5th smallest integer divisible by 5 is 20. The smaller integers divisible by 5 are 0, 5, 10, and 15.
Sample Input
2
Sample Output
2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static boolean checkdigit(int n, int k)
{
while(n!=0)
{
int rem=n%10;
if(rem==k){
return true;
}
n=n/10;
}
return false;
}
public static int findNthNumber(int n)
{
return 0;
}
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int n=Integer.parseInt(line);
for(int i=n,count=1;count<n;i++)
{
if (checkdigit(i,n) || (i%n==0)){
count++;
}
if (count == n){
System.out.println(i);
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find its Nth smallest non negative integer that is divisible by N.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000Output a single integer, the Nth smallest non negative multiple of N.Sample Input
5
Sample Output
20
Explanation: The 5th smallest integer divisible by 5 is 20. The smaller integers divisible by 5 are 0, 5, 10, and 15.
Sample Input
2
Sample Output
2, I have written this Solution Code: n = int(input())
ans = n*(n-1)
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find its Nth smallest non negative integer that is divisible by N.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000Output a single integer, the Nth smallest non negative multiple of N.Sample Input
5
Sample Output
20
Explanation: The 5th smallest integer divisible by 5 is 20. The smaller integers divisible by 5 are 0, 5, 10, and 15.
Sample Input
2
Sample Output
2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
cout<<(n*(n-1));
}
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: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
function LeapYear(year){
// write code here
// return the output using return keyword
// do not use console.log here
if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) {
return 0;
} else {
return 1
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: year = int(input())
if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
int area = LeapYear(side);
if(area==1){
System.out.println("YES");}
else{
System.out.println("NO");}
}
static int LeapYear(int year){
if(year%400==0){return 1;}
if(year%100 != 0 && year%4==0){return 1;}
else {
return 0;}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 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 string S, your task is to print the string S.You don't have to worry about taking input, you just have to complete the function <b>printString</b>Print the string S.Sample Input 1:-
NewtonSchool
Sample Output 1:-
NewtonSchool
Sample Input 2:-
Hello
Sample Output 2:-
Hello, I have written this Solution Code: static void printString(String stringVariable){
System.out.println(stringVariable);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, your task is to print the string S.You don't have to worry about taking input, you just have to complete the function <b>printString</b>Print the string S.Sample Input 1:-
NewtonSchool
Sample Output 1:-
NewtonSchool
Sample Input 2:-
Hello
Sample Output 2:-
Hello, I have written this Solution Code: S=input()
print(S), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, your task is to print the string S.You don't have to worry about taking input, you just have to complete the function <b>printString</b>Print the string S.Sample Input 1:-
NewtonSchool
Sample Output 1:-
NewtonSchool
Sample Input 2:-
Hello
Sample Output 2:-
Hello, I have written this Solution Code: void printString(string s){
cout<<s;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: def firstTwo(N):
while(N>99):
N=N//10
return (N%10)*10 + N//10
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: static int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcase = Integer.parseInt(br.readLine());
for(int t=0;t<testcase;t++){
int num = Integer.parseInt(br.readLine().trim());
if(num==1)
System.out.println("No");
else if(num<=3)
System.out.println("Yes");
else{
if((num%2==0)||(num%3==0))
System.out.println("No");
else{
int flag=0;
for(int i=5;i*i<=num;i+=6){
if(((num%i)==0)||(num%(i+2)==0)){
System.out.println("No");
flag=1;
break;
}
}
if(flag==0)
System.out.println("Yes");
}
}
}
}catch (Exception e) {
System.out.println("I caught: " + e);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: t=int(input())
for i in range(t):
number = int(input())
if number > 1:
i=2
while i*i<=number:
if (number % i) == 0:
print("No")
break
i+=1
else:
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n,k;
cin>>n;
long x=sqrt(n);
int cnt=0;
vector<int> v;
for(long long i=2;i<=x;i++){
if(n%i==0){
cout<<"No"<<endl;
goto f;
}}
cout<<"Yes"<<endl;
f:;
}
}
, 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 number N, you need to check whether the given number is Armstrong number or not. Now what is Armstrong number let us see below:
<b>A number is said to be Armstrong if it is equal to sum of cube of its digits. </b>User task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isArmstrong()</b> which contains N as a parameter.
Constraints:
1 <= N <= 10^4You need to return "true" if the given number is an Armstrong number otherwise "false"Sample Input 1:
1
Sample Output 1:
true
Sample Input 2:
147
Sample Output 2:
false
Sample Input 3:
371
Sample Output 3:
true
, I have written this Solution Code: static boolean isArmstrong(int N)
{
int num = N;
int sum = 0;
while(N > 0)
{
int digit = N%10;
sum += digit*digit*digit;
N = N/10;
}
if(num == sum)
return true;
else return false;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to check whether the given number is Armstrong number or not. Now what is Armstrong number let us see below:
<b>A number is said to be Armstrong if it is equal to sum of cube of its digits. </b>User task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isArmstrong()</b> which contains N as a parameter.
Constraints:
1 <= N <= 10^4You need to return "true" if the given number is an Armstrong number otherwise "false"Sample Input 1:
1
Sample Output 1:
true
Sample Input 2:
147
Sample Output 2:
false
Sample Input 3:
371
Sample Output 3:
true
, I have written this Solution Code: function isArmstrong(n) {
// write code here
// do no console.log the answer
// return the output using return keyword
let sum = 0
let k = n;
while(k !== 0){
sum += Math.pow( k%10,3)
k = Math.floor(k/10)
}
return sum === n
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: You are given a large integer N. Find the sum of its digits. Eg:- if the integer is 1234, the answer is 1+2+3+4=10.The first and only line of input contains the integer N.
Constraints
The number of digits in N won't exceed 100000.Output a single integer, the sum of digits in N.Sample Input
1234
Sample Output
10
Sample Input
11111111111111111111
Sample Output
20, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int sum=0;
for(int i=0;i<str.length();i++){
char c=str.charAt(i);
int k=c-'0';
sum+=k;}
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a large integer N. Find the sum of its digits. Eg:- if the integer is 1234, the answer is 1+2+3+4=10.The first and only line of input contains the integer N.
Constraints
The number of digits in N won't exceed 100000.Output a single integer, the sum of digits in N.Sample Input
1234
Sample Output
10
Sample Input
11111111111111111111
Sample Output
20, 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(){
string s; cin>>s;
int ans = 0;
For(i, 0, sz(s)){
ans += (s[i]-'0');
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a large integer N. Find the sum of its digits. Eg:- if the integer is 1234, the answer is 1+2+3+4=10.The first and only line of input contains the integer N.
Constraints
The number of digits in N won't exceed 100000.Output a single integer, the sum of digits in N.Sample Input
1234
Sample Output
10
Sample Input
11111111111111111111
Sample Output
20, I have written this Solution Code: s = input()
count = 0
for x in s:count+=int(x)
print(count) ;, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have an empty sequence A. Along with that you are given an array B of size N. You create a new integer i = 0 and perform N operations on the sequence A in the following way:
<ul>
<li>Check if i == N + 1, break. </li>
<li>Append B<sub>i</sub> to the end of A and increment i by 1. </li>
<li>Reverse the sequence A. </li>
Find the sequence A after all the operations.The first line of the input contains a single integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= B<sub>i</sub> <= 10<sup>9</sup>Print the sequence A after all the operations.Sample Input:
4
1 2 3 4
Sample Output:
4 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 br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
Deque<Integer> dq = new LinkedList<>();
boolean flag = true;
String[] str = br.readLine().split(" ");
for(int i = 0; i < n; ++i)
{
if(flag) {
dq.addFirst(Integer.parseInt(str[i]));
flag = false;
} else {
dq.addLast(Integer.parseInt(str[i]));
flag = true;
}
}
if(flag) {
while(!dq.isEmpty()) System.out.print(dq.pollLast()+" ");
} else {
while(!dq.isEmpty()) System.out.print(dq.pollFirst()+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have an empty sequence A. Along with that you are given an array B of size N. You create a new integer i = 0 and perform N operations on the sequence A in the following way:
<ul>
<li>Check if i == N + 1, break. </li>
<li>Append B<sub>i</sub> to the end of A and increment i by 1. </li>
<li>Reverse the sequence A. </li>
Find the sequence A after all the operations.The first line of the input contains a single integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= B<sub>i</sub> <= 10<sup>9</sup>Print the sequence A after all the operations.Sample Input:
4
1 2 3 4
Sample Output:
4 2 1 3, I have written this Solution Code: N=int(input())
B=list(map(int, input().split()))
A=[]
i=0
for i in range(N):
if i==N+1:
break
A.append(B[i])
A.reverse()
for i in A:
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have an empty sequence A. Along with that you are given an array B of size N. You create a new integer i = 0 and perform N operations on the sequence A in the following way:
<ul>
<li>Check if i == N + 1, break. </li>
<li>Append B<sub>i</sub> to the end of A and increment i by 1. </li>
<li>Reverse the sequence A. </li>
Find the sequence A after all the operations.The first line of the input contains a single integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= B<sub>i</sub> <= 10<sup>9</sup>Print the sequence A after all the operations.Sample Input:
4
1 2 3 4
Sample Output:
4 2 1 3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> A(n + 1), B(n + 1);
for(int i = 1; i <= n; i++)
cin >> A[i];
int head = 1, tail = n;
int f = 0, k = n;
while(head <= tail){
if(f == 0) B[head++] = A[k--];
else B[tail--] = A[k--];
f ^= 1;
}
for(int i = 1; i < n; i++)
cout << B[i] << ' ';
printf("%d",B[n]);
}, 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: 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 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: Mohan was so excited to visit his college NIT Arunachal Pradesh campus after COVID along with his friends Shreya and Anuj. The Warden allocated the hostel room for him but he was curious to know about the fact that how students are getting rooms.
The warden told him that those students whose roll no is divisible by 2 will get PAPUM HOSTEL and if it is odd then they will get "LOHIT HOSTEL". If the student is a girl, then she will get "Upper Wing" otherwise ‘Lower Wing’.The first line of input will contain a single integer t denoting the no. of test cases
Each test case contains only one line containing two space-separated inputs R for Roll No and S
for denoting Sex ‘B’ for boy and ‘G’ for girl
<b>Constraints</b>
1 ≤ t ≤ 10000
1 ≤ R ≤ 300Print the hostel name (LOHIT/PAPUM) with the upper wing (U) and lower wing (L).Sample Input
2
30 B
35 G
Sample Output
PAPUM L
LOHIT U
<b>Explanation:</b>
Here 30 is evenly divisible by two and B is the boy so he gets the Papum Hostel and is allocated a room in the lower wing., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int T = Integer.parseInt(st.nextToken());
while(T-->0){
st = new StringTokenizer(br.readLine());
int roomNo = Integer.parseInt(st.nextToken());
String gender = st.nextToken();
if(roomNo%2==0){
if(gender.equals("B")) System.out.println("PAPUM L");
else System.out.println("PAPUM U");
} else {
if(gender.equals("B")) System.out.println("LOHIT L");
else System.out.println("LOHIT U");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohan was so excited to visit his college NIT Arunachal Pradesh campus after COVID along with his friends Shreya and Anuj. The Warden allocated the hostel room for him but he was curious to know about the fact that how students are getting rooms.
The warden told him that those students whose roll no is divisible by 2 will get PAPUM HOSTEL and if it is odd then they will get "LOHIT HOSTEL". If the student is a girl, then she will get "Upper Wing" otherwise ‘Lower Wing’.The first line of input will contain a single integer t denoting the no. of test cases
Each test case contains only one line containing two space-separated inputs R for Roll No and S
for denoting Sex ‘B’ for boy and ‘G’ for girl
<b>Constraints</b>
1 ≤ t ≤ 10000
1 ≤ R ≤ 300Print the hostel name (LOHIT/PAPUM) with the upper wing (U) and lower wing (L).Sample Input
2
30 B
35 G
Sample Output
PAPUM L
LOHIT U
<b>Explanation:</b>
Here 30 is evenly divisible by two and B is the boy so he gets the Papum Hostel and is allocated a room in the lower wing., I have written this Solution Code: n = int(input())
for i in range(n):
a = input().split()
if int(a[0])%2==0:
print("PAPUM",end=" ")
else:
print("LOHIT",end = " ")
if a[1]=='G':
print("U")
else:
print("L"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohan was so excited to visit his college NIT Arunachal Pradesh campus after COVID along with his friends Shreya and Anuj. The Warden allocated the hostel room for him but he was curious to know about the fact that how students are getting rooms.
The warden told him that those students whose roll no is divisible by 2 will get PAPUM HOSTEL and if it is odd then they will get "LOHIT HOSTEL". If the student is a girl, then she will get "Upper Wing" otherwise ‘Lower Wing’.The first line of input will contain a single integer t denoting the no. of test cases
Each test case contains only one line containing two space-separated inputs R for Roll No and S
for denoting Sex ‘B’ for boy and ‘G’ for girl
<b>Constraints</b>
1 ≤ t ≤ 10000
1 ≤ R ≤ 300Print the hostel name (LOHIT/PAPUM) with the upper wing (U) and lower wing (L).Sample Input
2
30 B
35 G
Sample Output
PAPUM L
LOHIT U
<b>Explanation:</b>
Here 30 is evenly divisible by two and B is the boy so he gets the Papum Hostel and is allocated a room in the lower wing., I have written this Solution Code: #include <stdio.h>
int main(void) {
int t;
scanf("%d", &t);
while (t--) {
int roll;
char sex;
scanf("%d %c", &roll, &sex);
if (roll % 2)
printf("LOHIT %s\n", sex == 'B' ? "L" : "U");
else
printf("PAPUM %s\n", sex == 'B' ? "L" : "U");
}
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: You are given a String S and two empty strings A and B. You are allowed to perform following two operations.
1. Remove an element from start of S and add it to the end of B.
2. Remove an element from end of B and add it to the end of A.
Find the lexicographical minimum string A that we can obtain using the above procedure.
Note: The final length of string A must be equal to initial length of string S.Input contains string S containing only lowercase alphabets.
Constraints
1 <= |S| <= 100000Print the lexicographical minimum string A that we can obtain.Input
cab
Output
abc
Input
acdb
Output
abdc, 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);
String str = sc.nextLine().trim();
int len = str.length();
Stack<Integer> st = new Stack<Integer>();
StringBuilder sb = new StringBuilder();
int count[] = new int [26];
for(int i=0;i<len;i++){
count[str.charAt(i)-'a']++;
}
int j=0;
for(int i=0;i<len;i++){
while(count[j] == 0){
j++;
}
while(!st.empty() && st.peek() <= j){
sb.append((char) (st.pop() + 'a') );
}
st.push(str.charAt(i) - 'a');
count[str.charAt(i)-'a']--;
}
while(!st.empty()){
sb.append((char) (st.pop() + 'a') );
}
System.out.println(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a String S and two empty strings A and B. You are allowed to perform following two operations.
1. Remove an element from start of S and add it to the end of B.
2. Remove an element from end of B and add it to the end of A.
Find the lexicographical minimum string A that we can obtain using the above procedure.
Note: The final length of string A must be equal to initial length of string S.Input contains string S containing only lowercase alphabets.
Constraints
1 <= |S| <= 100000Print the lexicographical minimum string A that we can obtain.Input
cab
Output
abc
Input
acdb
Output
abdc, I have written this Solution Code: s = input()
b = []
a = ""
k = 0
for i in "abcdefghijklmnopqrstuvwxyz":
if(i not in s[k:]):
continue
for j in s[k:]:
while(b and b[-1] <= i):
a += b.pop()
if(i == j):
a += j
if(i not in s[k+1:]):
k+=1
break
else:
k += 1
if(len(a) == len(s)):
break
continue
if(len(a) == len(s)):
break
b.append(j)
k += 1
if(len(a) == len(s)):
break
while(b):
a += b.pop()
print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a String S and two empty strings A and B. You are allowed to perform following two operations.
1. Remove an element from start of S and add it to the end of B.
2. Remove an element from end of B and add it to the end of A.
Find the lexicographical minimum string A that we can obtain using the above procedure.
Note: The final length of string A must be equal to initial length of string S.Input contains string S containing only lowercase alphabets.
Constraints
1 <= |S| <= 100000Print the lexicographical minimum string A that we can obtain.Input
cab
Output
abc
Input
acdb
Output
abdc, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define endl '\n'
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int nxt[N][26];
signed main() {
speed;
string s; cin >> s;
int n = s.length();
for(int i = 0; i < 26; i++)
nxt[n][i] = n;
for(int i = n-1; i >= 0; i--){
for(int j = 0; j < 26; j++)
nxt[i][j] = nxt[i+1][j];
nxt[i][s[i]-'a'] = i;
}
stack<char> st;
int cur = 0;
string t = "";
for(int i = 0; i < n; i++){
while(nxt[i][cur] == n){
cur++;
if(cur == 26)
break;
while(!st.empty() && st.top()-'a' <= cur){
t += st.top();
st.pop();
}
}
if(cur == 26){
while(!st.empty() && st.top() <= s[i]){
t += st.top();
st.pop();
}
st.push(s[i]);
}
else{
if(nxt[i][cur] == i)
t += s[i];
else
st.push(s[i]);
}
}
while(!st.empty()){
t += st.top();
st.pop();
}
cout << t;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: function PokemonMaster(a,b) {
// write code here
// do no console.log the answer
// return the output using return keyword
const ans = (a - b >= 0) ? 1 : 0
return ans
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: def PokemonMaster(A,B):
if(A>=B):
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: int PokemonMaster(int A, int B){
if(A>=B){return 1;}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: int PokemonMaster(int A, int B){
if(A>=B){return 1;}
return 0;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: static int PokemonMaster(int A, int B){
if(A>=B){return 1;}
return 0;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a non-negative Integer x, count and print the number of times 0 occurs in that number.The first line contains 1 integer x.
<b>Constraints</b>
0 ≤ x ≤ 10<sup>5</sup>Print count of zeroes in the number.Sample Input 1 :
20
Sample Output 1 :
1
Sample Input 2 :
60701
Sample Output 2 :
2, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
assert n>=0&&n<=100000 : "Input Not Valid";
int ct=0;
if(n==0) ct=1;
while(n>0){
int c=n%10;
n/=10;
if(c==0){
ct++;
}
}
System.out.print(ct);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where each element is either 1 or 0. You have to divide the array into maximum number of subarrays such that each element of the array is in exactly one subarray such that each subarray has equal number of 1's and 0's.First line of input contains N.
Second line of input contains N space separated elements of the array.
Constraints:
1 <= N <= 100000
0 <= elements of the array <= 1Print the single integer which is the maximum number of subarrays the array can be divided into. If it is not possible then print -1.Sample input 1
4
1 0 1 0
Sample output 1
2
Sample input 2
4
1 1 0 0
Sample output 2
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(reader.readLine());
StringTokenizer tokens = new StringTokenizer(reader.readLine());
int partitions = 0;
int c0 = 0, c1 = 0;
for(int i = 0; i < N; i++) {
int x = Integer.parseInt(tokens.nextToken());
if(x == 0) {
c0++;
} else {
c1++;
}
if(c0 > 0 || c1 > 0) {
if(c0 == c1) {
partitions++;
c0 = c1 = 0;
}
}
}
if(c1 > 0 || c0 > 0) {
partitions = -1;
}
System.out.println(partitions);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where each element is either 1 or 0. You have to divide the array into maximum number of subarrays such that each element of the array is in exactly one subarray such that each subarray has equal number of 1's and 0's.First line of input contains N.
Second line of input contains N space separated elements of the array.
Constraints:
1 <= N <= 100000
0 <= elements of the array <= 1Print the single integer which is the maximum number of subarrays the array can be divided into. If it is not possible then print -1.Sample input 1
4
1 0 1 0
Sample output 1
2
Sample input 2
4
1 1 0 0
Sample output 2
1, I have written this Solution Code: n = int(input())
a = input().split()
o,z = 0,0
cnt = 0
for i in a:
if i == '1':
o += 1
else:
z +=1
if o == z:
cnt += 1
if o == z:
print(cnt)
else:
print(-1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where each element is either 1 or 0. You have to divide the array into maximum number of subarrays such that each element of the array is in exactly one subarray such that each subarray has equal number of 1's and 0's.First line of input contains N.
Second line of input contains N space separated elements of the array.
Constraints:
1 <= N <= 100000
0 <= elements of the array <= 1Print the single integer which is the maximum number of subarrays the array can be divided into. If it is not possible then print -1.Sample input 1
4
1 0 1 0
Sample output 1
2
Sample input 2
4
1 1 0 0
Sample output 2
1, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int c=0;
int ans=0;
for(int i=0;i<n;++i){
int x;
cin>>x;
if(x==0)
++c;
else
--c;
if(c==0)
++ans;
}
if(c==0){
cout<<ans;
}else
{
cout<<"-1";
}
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){
n-=32;
n/=9;
n*=5;
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: Fahrenheit= int(input())
Celsius = int(((Fahrenheit-32)*5)/9 )
print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit)
{
int celsius = ((farhrenheit-32)*5)/9;
System.out.println(celsius);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import static java.lang.System.out;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader reader = new FastReader();
int n = reader.nextInt();
String S = reader.next();
int ncount = 0;
int tcount = 0;
for (char c : S.toCharArray()) {
if (c == 'N') ncount++;
else tcount++;
}
if (ncount > tcount) {
out.print("Nutan\n");
} else {
out.print("Tusla\n");
}
out.flush();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: n = int(input())
s = input()
a1 = s.count('N')
a2 = s.count('T')
if(a1 > a2):
print("Nutan")
else:
print('Tusla'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: //Author: Xzirium
//Time and Date: 02:18:28 24 March 2022
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//-----------------------------------------------------------------------------------------------------------//
READV(N);
string S;
cin>>S;
ll n=0,t=0;
FORI(i,0,N)
{
if(S[i]=='N')
{
n++;
}
else if(S[i]=='T')
{
t++;
}
}
if(n>t)
{
cout<<"Nutan"<<endl;
}
else
{
cout<<"Tusla"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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 two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args){
FastReader read = new FastReader();
int a = read.nextInt();
int b = read.nextInt();
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(){
InputStreamReader inr = new InputStreamReader(System.in);
br = new BufferedReader(inr);
}
String next(){
while(st==null || !st.hasMoreElements())
try{
st = new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
long nextLong(){
return Long.parseLong(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split())
print(a+b)
print(a-b)
print(a*b)
print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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 a number N, your task is to convert the number into a single digit by repeatedly replacing the number N with its sum of digits until the number becomes a single digit.The input contains a single integer N.
Constraints:-
1 <= N <= 100000Print the single digit after performing the given operation.Sample Input:-
987
Sample Output:-
6
Explanation:-
987 - > 9 + 8 + 7 => 24 = 2 + 4 => 6
Sample Input:-
91
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)
);
int n = Integer.parseInt(br.readLine());
int sum =0;
while(sum>9 || n>0){
if (n == 0) {
n = sum;
sum = 0;
}
sum += n%10;
n /= 10;
}
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, your task is to convert the number into a single digit by repeatedly replacing the number N with its sum of digits until the number becomes a single digit.The input contains a single integer N.
Constraints:-
1 <= N <= 100000Print the single digit after performing the given operation.Sample Input:-
987
Sample Output:-
6
Explanation:-
987 - > 9 + 8 + 7 => 24 = 2 + 4 => 6
Sample Input:-
91
Sample Output:-
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
while(n>9){
int p = n;
int sum=0;
while(p>0){
sum+=p%10;
p/=10;
}
n=sum;
}
cout<<n;
}, In this Programming Language: C++, 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.