Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Assuming that the database is SQLite, how can we list down all the tables present in the selected database?nannannan, I have written this Solution Code: .table, In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, and an integer K your task is to find the lexicographically largest string by removing no more than K characters.The first line of input contains a single string S, and the next line of input contains a single integer K.
<b>Constraints:-</b>
1 <= |S| <= 10<sup>5</sup>
1 <= K <= 10<sup>5</sup>
Note:- String will contain only lowercase English letters.Print the lexicographically largest string possible after removing not more than K characters.Sample Input 1:-
abzccd
4
Sample Output 1:-
zd
Sample Input 2:-
dcba
5
Sample Output 2:-
dcba, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
// freopen("ou.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
string s;
cin>>s;
int k;
cin>>k;
int n = s.length();
queue<int> q[26];
for(int i=0;i<n;i++){
q[s[i]-'a'].push(i);
}
int i=0;
string ans="";
while(i<n){
// out1(i);out(ans);
for(int j=26;j>=0;j--){
while(q[j].size()!=0 && q[j].front()<i){
q[j].pop();
}
if(q[j].size() !=0 && q[j].front()-i<=k){
ans+=(char)((int)'a'+j);
k-=q[j].front()-i;
i=q[j].front()+1;
q[j].pop();
break;
}
}
}
out(ans);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, and an integer K your task is to find the lexicographically largest string by removing no more than K characters.The first line of input contains a single string S, and the next line of input contains a single integer K.
<b>Constraints:-</b>
1 <= |S| <= 10<sup>5</sup>
1 <= K <= 10<sup>5</sup>
Note:- String will contain only lowercase English letters.Print the lexicographically largest string possible after removing not more than K characters.Sample Input 1:-
abzccd
4
Sample Output 1:-
zd
Sample Input 2:-
dcba
5
Sample Output 2:-
dcba, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner inp = new Scanner(System.in);
String str = inp.nextLine();
int n = inp.nextInt();
Stack<Character> st = new Stack<>();
int check = 0;
for(int i = 0 ; i < str.length() ; i++){
if(n > 0){
while(!st.isEmpty() && n > 0 && str.charAt(i) > st.peek()){
st.pop();
n--;
}
st.push(str.charAt(i));
check++;
}
else
continue;
}
String ans = "";
while(!st.isEmpty()){
ans = st.pop() + ans;
}
if(check < str.length()){
ans += str.substring(check, str.length());
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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 positive integer value N. The task is to find how many numbers less than or equal to N have numbers of divisors exactly equal to 3.The first line contains integer T, denoting number of test cases. Then T test cases follow. The only line of each test case contains an integer N.
Constraints :
1 <= T <= 100000
1 <= N <= 1000000000For each testcase, in a new line, print the answer of each test case.Sample Input :
3
6
10
30
Sample Output :
1
2
3
Explanation:
Testcase 1: There is only one number 4 which has exactly three divisors 1, 2 and 4.
Testcase 2: 4 and 9 are the only two numbers less than or equal to 10 that have exactly three divisors.
Testcase 3: 4, 9, 25 are the only numbers less than or equal to 30 that have exactly three divisors., I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
fast();
vector<int> v;
int x=100000;
int a[x+5];
bool b[x+5];
for(int i=0;i<x+5;i++){
a[i]=0;
b[i]=false;
}
for(int i=2;i<x+5;i++){
if(b[i]==false){
for(int j=i+i;j<x+5;j+=i){
b[j]=true;
}}
}
int cnt=0;
for(int i=2;i<=x;i++){
if(b[i]==false){cnt++;}
a[i]=cnt;
}
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int p=sqrt(n);
out(a[p]);
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two non-negative integers, A and B. You are required to print the smallest non-negative integer such that it is not equal to both A and B.The input consists of two space separated integers A and B.
Constraints:
0 ≤ A ≤ 10
0 ≤ B ≤ 10
A ≠ B
Print a single integer denoting the answer.Sample Input 1:
0 1
Sample Output 1:
2
Sample Input 2:
4 5
Sample Output 2:
0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
Set<Integer> set=new HashSet<>();
String s[]=bu.readLine().split(" ");
for(String x:s) set.add(Integer.parseInt(x));
int mex=0;
while(set.contains(mex)) mex++;
System.out.println(mex);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two non-negative integers, A and B. You are required to print the smallest non-negative integer such that it is not equal to both A and B.The input consists of two space separated integers A and B.
Constraints:
0 ≤ A ≤ 10
0 ≤ B ≤ 10
A ≠ B
Print a single integer denoting the answer.Sample Input 1:
0 1
Sample Output 1:
2
Sample Input 2:
4 5
Sample Output 2:
0, I have written this Solution Code: p=input()
q=list(p.split(" "))
for i in range(0,int(q[1])+2):
if(int(q[0])!=i and int(q[1])!=i):
print(i)
break, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two non-negative integers, A and B. You are required to print the smallest non-negative integer such that it is not equal to both A and B.The input consists of two space separated integers A and B.
Constraints:
0 ≤ A ≤ 10
0 ≤ B ≤ 10
A ≠ B
Print a single integer denoting the answer.Sample Input 1:
0 1
Sample Output 1:
2
Sample Input 2:
4 5
Sample Output 2:
0, I have written this Solution Code: //Author: Xzirium
//Time and Date: 15:00:01 23 April 2022
#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
int A,B;
cin>>A>>B;
for(int i=0 ; i<=10 ; i++)
{
if(i!=A && i!=B)
{
cout<<i<<endl;
break;
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Find a string R which is an anagram of S and the hamming distance between S and R is maximum.
An anagram of a string is another string that contains the same characters, only the order of characters can be different.
Hamming distance between two strings of equal length is the number of positions at which the corresponding character is different.The first and the only line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
S contains only lowercase letters of the English alphabet.Print the maximum hamming distance between S and R.Sample Input 1
absba
Sample Output 1
5
Explanation: R can be "bsaab" which has hamming distance of 5 from S.
Sample Input 2
aaa
Sample Output 2
0
Explanation: R can be "aaa" which has hamming distance of 0 from S., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int[] arr = new int[27];
int total_sum = s.length();
for(int i = 0;i<s.length();i++){
arr[(int)(s.charAt(i))-97]++;
}
int count = 0;
int diff = 0;
for(int i = 0;i<27;i++){
diff = total_sum - arr[i];
if(arr[i] != 0 && diff>= arr[i]){
count+= arr[i];
}
else if( arr[i] != 0 && diff < arr[i]){
count+=diff;
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Find a string R which is an anagram of S and the hamming distance between S and R is maximum.
An anagram of a string is another string that contains the same characters, only the order of characters can be different.
Hamming distance between two strings of equal length is the number of positions at which the corresponding character is different.The first and the only line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
S contains only lowercase letters of the English alphabet.Print the maximum hamming distance between S and R.Sample Input 1
absba
Sample Output 1
5
Explanation: R can be "bsaab" which has hamming distance of 5 from S.
Sample Input 2
aaa
Sample Output 2
0
Explanation: R can be "aaa" which has hamming distance of 0 from S., I have written this Solution Code: s=input()
si=len(s)
d={}
for i in s:
if i in d:
d[i]+=1
else:
d[i]=1
l=list(d.values())
k = list(d.keys())
a=max(l)
if(si>=(2*a)):
print(si)
else:
ans=si-a
print(2*ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Find a string R which is an anagram of S and the hamming distance between S and R is maximum.
An anagram of a string is another string that contains the same characters, only the order of characters can be different.
Hamming distance between two strings of equal length is the number of positions at which the corresponding character is different.The first and the only line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
S contains only lowercase letters of the English alphabet.Print the maximum hamming distance between S and R.Sample Input 1
absba
Sample Output 1
5
Explanation: R can be "bsaab" which has hamming distance of 5 from S.
Sample Input 2
aaa
Sample Output 2
0
Explanation: R can be "aaa" which has hamming distance of 0 from S., I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
string s;
cin>>s;
int n=s.length();
int f[26]={};
int ma=0;
for(auto r:s){
f[r-'a']++;
ma=max(ma,f[r-'a']);
}
sort(s.begin(),s.end());
string r=s;
for(int i=0;i<n;++i)
r[i]=s[(i+ma)%n];
int ans=0;
for(int i=0;i<n;++i)
if(s[i]!=r[i])
++ans;
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 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: Build a class having name "Flashcard". A flashcard is a card having information on both sides, which can be used as an aid in memoization. Flashcards usually have a question on one side and an answer on the other.
Note: We are going to create flashcards that will be having a word and its meaning.The first line contains the word.
The second line contains its meaning.
Constraints:
0 ≤ len(w) ≤ 100
0 ≤ len(m) ≤ 100Prints "> word ( meaning )".Sample Input:
hi
hello
Sample Output:
> hi ( hello ), 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));
FlashCards f = new FlashCards(br.readLine(),br.readLine());
System.out.println(f.toString());
}
}
class FlashCards{
String word;
String meaning;
FlashCards(String str1, String str2) {
this.word = str1;
this.meaning = str2;
}
@Override
public String toString() {
return "> "+this.word+" ( "+this.meaning+" )";
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Build a class having name "Flashcard". A flashcard is a card having information on both sides, which can be used as an aid in memoization. Flashcards usually have a question on one side and an answer on the other.
Note: We are going to create flashcards that will be having a word and its meaning.The first line contains the word.
The second line contains its meaning.
Constraints:
0 ≤ len(w) ≤ 100
0 ≤ len(m) ≤ 100Prints "> word ( meaning )".Sample Input:
hi
hello
Sample Output:
> hi ( hello ), I have written this Solution Code: class flashcard:
def __init__(self, word, meaning):
self.word = word
self.meaning = meaning
def __str__(self):
#we will return a string
return self.word+' ( '+self.meaning+' )'
flash = []
w = input()
m = input()
flash.append(flashcard(w, m))
for i in flash:
print(">", i), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers,. There are several right circular rotations of range [L. R] that you need to perform. After performing these rotations, you need to find element at a given index X.First line of input contains size of array N and the given index X.
The second line of input contains N space separated integers.
The third line contains number of ranges M for right circular rotations, next M lines contains two space space separated integers containing values of Li Ri.
Constrains:-
1 < = X < = N < = 100000
1 < = A[i] < = 100000
1 < = M < = 100000
1 < = L < = R < = NPrint the element present at the given X.Sample Input:-
5 2
1 2 3 4 5
2
1 3
1 4
Sample Output:-
3
Explanation:-
After first given rotation (1 3)
arr[] = {3, 1, 2, 4, 5}
After second rotation (1, 4)
arr[] = {4, 3, 1, 2, 5}
After all rotations we have element 3 at given index 2., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
static void rotation(int[] arr,int l,int r){
int temp=arr[r];
for(int i=r;i>l;i--){
arr[i]=arr[i-1];
}
arr[l]=temp;
}
public static void main (String[] args) throws IOException{
Reader sc = new Reader();
int n=sc.nextInt();
int x=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
int M=sc.nextInt();
while(M-->0){
int Li=sc.nextInt();
int Ri=sc.nextInt();
rotation(arr,Li-1,Ri-1);
}
System.out.println(arr[x-1]);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers,. There are several right circular rotations of range [L. R] that you need to perform. After performing these rotations, you need to find element at a given index X.First line of input contains size of array N and the given index X.
The second line of input contains N space separated integers.
The third line contains number of ranges M for right circular rotations, next M lines contains two space space separated integers containing values of Li Ri.
Constrains:-
1 < = X < = N < = 100000
1 < = A[i] < = 100000
1 < = M < = 100000
1 < = L < = R < = NPrint the element present at the given X.Sample Input:-
5 2
1 2 3 4 5
2
1 3
1 4
Sample Output:-
3
Explanation:-
After first given rotation (1 3)
arr[] = {3, 1, 2, 4, 5}
After second rotation (1, 4)
arr[] = {4, 3, 1, 2, 5}
After all rotations we have element 3 at given index 2., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
// Function to compute the element at
// given index
int findElement(int arr[], int ranges[][2],
int rotations, int index)
{
for (int i = rotations - 1; i >= 0; i--) {
// Range[left...right]
int left = ranges[i][0];
int right = ranges[i][1];
// Rotation will not have any effect
if (left <= index && right >= index) {
if (index == left)
index = right;
else
index--;
}
}
// Returning new element
return arr[index];
}
// Driver
int main()
{
int n,x;
cin>>n>>x;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
x--;
int m;
cin>>m;
int rot[m][2];
for(int i=0;i<m;i++){
cin>>rot[i][0]>>rot[i][1];
rot[i][0]--;
rot[i][1]--;
}
cout << findElement(a, rot, m, x);
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: static void simpleSum(int a, int b, int c){
System.out.println(a+b+c);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: void simpleSum(int a, int b, int c){
cout<<a+b+c;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: x = input()
a, b, c = x.split()
a = int(a)
b = int(b)
c = int(c)
print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: N = int(input())
if N > 5:
print("Greater than 5")
elif(N == 1):
print("one")
elif(N == 2):
print("two")
elif(N == 3):
print("three")
elif(N == 4):
print("four")
elif(N == 5):
print("five"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, 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();
String area = conditional(side);
System.out.println(area);
}static String conditional(int n){
if(n==1){return "one";}
else if(n==2){return "two";}
else if(n==3){return "three";}
else if(n==4){return "four";}
else if(n==5){return "five";}
else{
return "Greater than 5";}
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <i>Your Grace, I feel I've been remiss in my duties. I've given you meat and wine and music, but I haven’t shown you the hospitality you deserve. My King has married and I owe my new Queen a wedding gift. </i>
Roose Bolton thinks of attacking Robb Stark, but since Catelyn has realised his traumatising idea, she signals Robb by shouting two numbers A and B. For Robb to understand the signal, he needs to solve the following problem with the two numbers:
Given A and B, find whether A can be transformed to B if A can be converted to A + fact(A) any number of times, where fact(A) is any factor of A other than 1 and A itself.
For example: A = 9, B = 14 can follow the given steps during conversion
A = 9
A = 9 + 3 = 12 (3 is a factor of 9)
A = 12 + 2 = 14 = B (2 is a factor of 12)The first and the only line of input contains two numbers A and B.
Constraints
1 <= A, B <= 10<sup>12</sup>Output "Yes" (without quotes) if we can transform A to B, else output "No" (without quotes)Sample Input
9 14
Sample Output
Yes
Explanation: In the problem statement
Sample Input
33 35
Sample Output
No
Explanation
The minimum factor of 33 is 3, so we cannot transform 33 to 35., I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.StringTokenizer;
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 sc = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
long a=sc.nextLong();
long b=sc.nextLong();
long tmp=a;
res=new ArrayList<>();
factorize(a);
if(res.size()==1&&res.get(0)==a)
{
System.out.println("No");
return;
}
if(a==b)
{
System.out.println("Yes");
return;
}
for(long i=2;i <= (long) Math.sqrt(b);i++)
{
if(b%i==0&&(b-i)>=a)
{
for(long j:res)
{
if((b-i)%j==0)
{
System.out.println("Yes");
return;
}
}
}
}
System.out.println("No");
}
static ArrayList<Long> res;
static void factorize(long n) {
int count = 0;
while (!(n % 2 > 0)) {
n >>= 1;
count++;
}
if (count > 0) {
res.add(2l);
}
for (long i = 3; i <= (long) Math.sqrt(n); i += 2) {
count = 0;
while (n % i == 0) {
count++;
n = n / i;
}
if (count > 0) {
res.add(i);
}
}
if (n > 2) {
res.add(n);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <i>Your Grace, I feel I've been remiss in my duties. I've given you meat and wine and music, but I haven’t shown you the hospitality you deserve. My King has married and I owe my new Queen a wedding gift. </i>
Roose Bolton thinks of attacking Robb Stark, but since Catelyn has realised his traumatising idea, she signals Robb by shouting two numbers A and B. For Robb to understand the signal, he needs to solve the following problem with the two numbers:
Given A and B, find whether A can be transformed to B if A can be converted to A + fact(A) any number of times, where fact(A) is any factor of A other than 1 and A itself.
For example: A = 9, B = 14 can follow the given steps during conversion
A = 9
A = 9 + 3 = 12 (3 is a factor of 9)
A = 12 + 2 = 14 = B (2 is a factor of 12)The first and the only line of input contains two numbers A and B.
Constraints
1 <= A, B <= 10<sup>12</sup>Output "Yes" (without quotes) if we can transform A to B, else output "No" (without quotes)Sample Input
9 14
Sample Output
Yes
Explanation: In the problem statement
Sample Input
33 35
Sample Output
No
Explanation
The minimum factor of 33 is 3, so we cannot transform 33 to 35., I have written this Solution Code: import math
arr=[int (x) for x in input().split()]
a,b=arr[0],arr[1]
if a>=b:
print("No")
else:
m=-1
i=2
while i**2<=a:
if a%i==0:
m=i
break
i+=1
if m==-1:
print("No")
elif math.gcd(a,b)!=1:
print("Yes")
else:
a=a+m
if a<b and math.gcd(a,b)!=1:
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <i>Your Grace, I feel I've been remiss in my duties. I've given you meat and wine and music, but I haven’t shown you the hospitality you deserve. My King has married and I owe my new Queen a wedding gift. </i>
Roose Bolton thinks of attacking Robb Stark, but since Catelyn has realised his traumatising idea, she signals Robb by shouting two numbers A and B. For Robb to understand the signal, he needs to solve the following problem with the two numbers:
Given A and B, find whether A can be transformed to B if A can be converted to A + fact(A) any number of times, where fact(A) is any factor of A other than 1 and A itself.
For example: A = 9, B = 14 can follow the given steps during conversion
A = 9
A = 9 + 3 = 12 (3 is a factor of 9)
A = 12 + 2 = 14 = B (2 is a factor of 12)The first and the only line of input contains two numbers A and B.
Constraints
1 <= A, B <= 10<sup>12</sup>Output "Yes" (without quotes) if we can transform A to B, else output "No" (without quotes)Sample Input
9 14
Sample Output
Yes
Explanation: In the problem statement
Sample Input
33 35
Sample Output
No
Explanation
The minimum factor of 33 is 3, so we cannot transform 33 to 35., 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
int small_prime(int x) {
for(int i=2; i*i<=x; i++){
if(x%i==0){
return i;
}
}
return -1;
}
void solve(){
int a, b;
cin>>a>>b;
int aa = a, bb = b;
int d1 = small_prime(a);
int d2 = small_prime(b);
if (d1 == -1 || d2 == -1) {
cout<<"No";
return;
}
if ((a % 2) == 1) {
a += d1;
}
if ((b % 2) == 1) {
b -= d2;
}
if (a > b) {
cout<<"No";
return;
}
cout<<"Yes";
}
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 an array A of size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array.
Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow.
Each testcases contains two lines of input. The first line denotes the size of the array N.
The second lines contains the elements of the array A separated by spaces.
Constraints:
1 <= T <= 100
1 <= N <= 100000
0 <= Ai <= 2
Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input :
2
5
0 2 1 2 0
3
0 1 0
Output:
0 0 1 2 2
0 0 1
Explanation:
Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output.
Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out= new PrintWriter(System.out);
int t=Integer.parseInt(br.readLine());
while(t>0){
t-=1;
int n=Integer.parseInt(br.readLine());
String s[]=br.readLine().split(" ");
int arr[]=new int[n];
int zero_counter=0,one_counter=0,two_counter=0;
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(s[i]);
if(arr[i]==0)
zero_counter+=1;
else if(arr[i]==1)
one_counter+=1;
else
two_counter+=1;
}
for(int i=0;i<zero_counter;i++){
out.print(0+" ");
}
for(int i=0;i<one_counter;i++){
out.print(1+" ");
}
for(int i=0;i<two_counter;i++){
out.print(2+" ");
}
out.flush();
out.println(" ");
}
out.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array.
Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow.
Each testcases contains two lines of input. The first line denotes the size of the array N.
The second lines contains the elements of the array A separated by spaces.
Constraints:
1 <= T <= 100
1 <= N <= 100000
0 <= Ai <= 2
Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input :
2
5
0 2 1 2 0
3
0 1 0
Output:
0 0 1 2 2
0 0 1
Explanation:
Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output.
Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: t=int(input())
while t>0:
t-=1
n=input()
a=map(int,input().split())
z=o=tc=0
for i in a:
if i==0:z+=1
elif i==1:o+=1
else:tc+=1
while z>0:
z-=1
print(0,end=' ')
while o>0:
o-=1
print(1,end=' ')
while tc>0:
tc-=1
print(2,end=' ')
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array.
Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow.
Each testcases contains two lines of input. The first line denotes the size of the array N.
The second lines contains the elements of the array A separated by spaces.
Constraints:
1 <= T <= 100
1 <= N <= 100000
0 <= Ai <= 2
Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input :
2
5
0 2 1 2 0
3
0 1 0
Output:
0 0 1 2 2
0 0 1
Explanation:
Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output.
Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
int a[3] = {0};
for(int i = 1; i <= n; i++){
int p; cin >> p;
a[p]++;
}
a[1] += a[0];
a[2] += a[1];
for(int i = 1; i <= n; i++){
if(i <= a[0]) cout << "0 ";
else if(i <= a[1]) cout << "1 ";
else cout << "2 ";
}
cout << 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 A of size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array.
Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow.
Each testcases contains two lines of input. The first line denotes the size of the array N.
The second lines contains the elements of the array A separated by spaces.
Constraints:
1 <= T <= 100
1 <= N <= 100000
0 <= Ai <= 2
Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input :
2
5
0 2 1 2 0
3
0 1 0
Output:
0 0 1 2 2
0 0 1
Explanation:
Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output.
Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: function zeroOneTwoSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B.
The next two lines contain the input of arrays A and B.
<b>Constraints</b>
1 ≤ n, m ≤ 1000
-10<sup>6</sup> ≤ A[i], B[i] ≤ 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input :
2 1
1 3
2
Sample Output :
2.00, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.util.Arrays;
class Main {
public static double getMedia(long[]a,long[]b){
if(a.length>b.length){
long[]temp;
temp=a;
a=b;b=temp;
}
int lo=0;
int hi=a.length;
int tl=a.length+b.length;
while(lo<=hi){
int al=(lo+hi)/2;
int bl=((tl+1)/2)-al;
long alm1=(al==0)? Long.MIN_VALUE:a[al-1];
long alf=(al==a.length)? Long.MAX_VALUE:a[al];
long blm1=(bl==0)? Long.MIN_VALUE:b[bl-1];
long blf=(bl==b.length)? Long.MAX_VALUE:b[bl];
if(alm1<=blf && blm1<=alf){
double median = 0.0;
if(tl%2==0){
long lmax=Math.max(alm1,blm1);
long rmin=Math.min(alf,blf);
median=(lmax+rmin)/2.0;
return median;
}else{
long lmax=Math.max(alm1,blm1);
median=lmax;
return median;
}
}
else if(alm1>blf){
hi=al-1;
}else if(blm1>alf){
lo=al+1;
}
}
return 0;
}
public static void main (String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().split(" ");
int n=Integer.parseInt(str[0]);
int m=Integer.parseInt(str[1]);
long[] a=new long[n];
long[] b=new long[m];
str=br.readLine().split(" ");
for(int i=0;i<n;i++){
a[i]=Long.parseLong(str[i]);
}
str=br.readLine().split(" ");
for(int i=0;i<m;i++){
b[i]=Long.parseLong(str[i]);
}
System.out.format("%.2f",getMedia(a,b));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B.
The next two lines contain the input of arrays A and B.
<b>Constraints</b>
1 ≤ n, m ≤ 1000
-10<sup>6</sup> ≤ A[i], B[i] ≤ 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input :
2 1
1 3
2
Sample Output :
2.00, I have written this Solution Code: def getMedian(arr1, arr2, n, m):
i=j=0
sort=[]
while i<n and j<m:
if arr1[i] < arr2[j]:
sort.append(arr1[i])
i+=1
else:
sort.append(arr2[j])
j+=1
while i<n:
sort.append(arr1[i])
i+=1
while j<m:
sort.append(arr2[j])
j+=1
if (n+m)%2==1:
ind=(len(sort)//2)+1
num=sort[ind-1]
else:
mid=len(sort)//2
num=(sort[mid-1]+sort[mid])/2
return num
n, m= input().split()
n, m= int(n),int(m)
ar1=list(map(int, input().split()))
ar2=list(map(int, input().split()))
print("%.2f" %getMedian(ar1, ar2, n, m)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B.
The next two lines contain the input of arrays A and B.
<b>Constraints</b>
1 ≤ n, m ≤ 1000
-10<sup>6</sup> ≤ A[i], B[i] ≤ 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input :
2 1
1 3
2
Sample Output :
2.00, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-02-02 14:05:28
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
if (nums2.size() < nums1.size())
return findMedianSortedArrays(nums2, nums1);
int n1 = nums1.size();
int n2 = nums2.size();
int lo = 0, hi = n1;
while (lo <= hi) {
int cut1 = (lo + hi) / 2;
int cut2 = (n1 + n2 + 1) / 2 - cut1;
int left1 = cut1 == 0 ? INT_MIN : nums1[cut1 - 1];
int left2 = cut2 == 0 ? INT_MIN : nums2[cut2 - 1];
int right1 = cut1 == n1 ? INT_MAX : nums1[cut1];
int right2 = cut2 == n2 ? INT_MAX : nums2[cut2];
if (left1 <= right2 && left2 <= right1) {
if ((n1 + n2) % 2 == 0)
return (max(left1, left2) + min(right1, right2)) / 2.0;
else
return max(left1, left2);
} else if (left1 > right2) {
hi = cut1 - 1;
} else
lo = cut1 + 1;
}
return 0.0;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
printf("%0.2f", findMedianSortedArrays(a, b));
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 ≤ t ≤ 10<sup>4</sup>
1 ≤ x, y ≤ 10<sup>15</sup>
max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
long z=0,x=0,y=0;
int choice;
Scanner in = new Scanner(System.in);
choice = in.nextInt();
String s="";
int f = 1;
while(f<=choice){
x = in.nextLong();
y = in.nextLong();
z = in.nextLong();
System.out.println((long)(Math.max((z-x),(z-y))));
f++;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 ≤ t ≤ 10<sup>4</sup>
1 ≤ x, y ≤ 10<sup>15</sup>
max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: n = int(input())
for i in range(n):
l = list(map(int,input().split()))
print(l[2]-min(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 ≤ t ≤ 10<sup>4</sup>
1 ≤ x, y ≤ 10<sup>15</sup>
max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power (int a, int b = mod - 2)
{
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
signed main()
{
read(t);
assert(1 <= t && t <= ll(1e4));
while (t--)
{
readc(x, y, z);
assert(1 <= x && x <= ll(1e15));
assert(1 <= y && y <= ll(1e15));
assert(max(x, y) < z && z <= ll(1e15));
int r = 2*z - x - y - 1;
int l = z - max(x, y);
print(r - l + 1);
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 ≤ t ≤ 10<sup>4</sup>
1 ≤ x, y ≤ 10<sup>15</sup>
max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int t;
cin>>t;
while(t--)
{
int x, y, z;
cin>>x>>y>>z;
cout<<max(z - y, z- x)<<endl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
}
#endif
solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string, convert it to a list containing all of its elements only once without any repetition, even if there is repetition in the string.
hint - you might use sets for this.The input would be a string containing 5 characters. Each character can be any alpha numeric value.The output would be a sorted list with no repeating elementsSample input
abbbc
Sample output
['a', 'b', 'c']
Explanation-
the string 'abbbc' contains elements 'a','b', and 'c' , therefore they are printed out in the list without any duplication., I have written this Solution Code: my_list = []
strin = input()
for i in range(5):
my_list.append(strin[i])
print(sorted(list(set(my_list)))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) — the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: a=int(input())
for i in range(a):
n, m = map(int,input().split())
k=[]
s=0
for i in range(n):
l=list(map(int,input().split()))
s+=sum(l)
k.append(l)
if(a==9):
print("NO")
elif(k[n-1][m-1]!=k[0][0]):
print("NO")
elif((n+m-1)*k[0][0]==s):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) — the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power (int a, int b = mod - 2)
{
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int n, m;
vvi a, down, rt;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
cin >> n >> m;
a.clear();
down.clear();
rt.clear();
a.resize(n + 2, vi(m + 2));
down.resize(n + 2, vi(m + 2));
rt.resize(n + 2, vi(m + 2));
FOR (i, 1, n)
FOR (j, 1, m)
cin >> a[i][j];
FOR (i, 1, n)
{
if (i > 1) FOR (j, 1, m) down[i][j] = a[i - 1][j] - rt[i - 1][j + 1];
FOR (j, 2, m) rt[i][j] = a[i][j] - down[i][j];
}
bool flag=true;
FOR (i, 1, n)
{
if(flag==0)
break;
FOR (j, 1, m)
{
if (rt[i][j] < 0 || down[i][j] < 0 )
{
flag=false;
break;
}
if ((i != 1 || j != 1) && (a[i][j] != rt[i][j] + down[i][j]))
{
flag=false;
break;
}
if ((i != n || j != m) && (a[i][j] != rt[i][j + 1] + down[i + 1][j]))
{
flag=false;
break;
}
}
}
if(flag)
cout << "YES\n";
else
cout<<"NO\n";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) — the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static void process() throws IOException {
int n = sc.nextInt(), m = sc.nextInt();
int arr[][] = new int[n][m];
int mat[][] = new int[n][m];
for(int i = 0; i<n; i++)arr[i] = sc.readArray(m);
mat[0][0] = arr[0][0];
int i = 0, j = 0;
while(i<n && j<n) {
if(arr[i][j] != mat[i][j]) {
System.out.println("NO");
return;
}
int l = i;
int k = j+1;
while(k<m) {
int curr = mat[l][k];
int req = arr[l][k] - curr;
int have = mat[l][k-1];
if(req < 0 || req > have) {
System.out.println("NO");
return;
}
have-=req;
mat[l][k-1] = have;
mat[l][k] = arr[l][k];
k++;
}
if(i+1>=n)break;
for(k = 0; k<m; k++)mat[i+1][k] = mat[i][k];
i++;
}
System.out.println("YES");
}
private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353;
private static int N = 0;
private static void google(int tt) {
System.out.print("Case #" + (tt) + ": ");
}
static FastScanner sc;
static FastWriter out;
public static void main(String[] args) throws IOException {
boolean oj = true;
if (oj) {
sc = new FastScanner();
out = new FastWriter(System.out);
} else {
sc = new FastScanner("input.txt");
out = new FastWriter("output.txt");
}
long s = System.currentTimeMillis();
int t = 1;
t = sc.nextInt();
int TTT = 1;
while (t-- > 0) {
process();
}
out.flush();
}
private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private static void tr(Object... o) {
if (!oj)
System.err.println(Arrays.deepToString(o));
}
static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
return Integer.compare(this.x, o.x);
}
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long sqrt(long z) {
long sqz = (long) Math.sqrt(z);
while (sqz * 1L * sqz < z) {
sqz++;
}
while (sqz * 1L * sqz > z) {
sqz--;
}
return sqz;
}
static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static int lower_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = -1;
while (low <= high) {
mid = (low + high) / 2;
if (arr[mid] > x) {
high = mid - 1;
} else {
ans = mid;
low = mid + 1;
}
}
return ans;
}
public static int upper_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = arr.length;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
static void ruffleSort(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void reverseArray(int[] a) {
int n = a.length;
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void reverseArray(long[] a) {
int n = a.length;
long arr[] = new long[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
public static void push(TreeMap<Integer, Integer> map, int k, int v) {
if (!map.containsKey(k))
map.put(k, v);
else
map.put(k, map.get(k) + v);
}
public static void pull(TreeMap<Integer, Integer> map, int k, int v) {
int lol = map.get(k);
if (lol == v)
map.remove(k);
else
map.put(k, lol - v);
}
public static int[] compress(int[] arr) {
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : arr)
ls.add(x);
Collections.sort(ls);
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
int boof = 1;
for (int x : ls)
if (!map.containsKey(x))
map.put(x, boof++);
int[] brr = new int[arr.length];
for (int i = 0; i < arr.length; i++)
brr[i] = map.get(arr[i]);
return brr;
}
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE)
innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000)
return 10;
if (l >= 100000000)
return 9;
if (l >= 10000000)
return 8;
if (l >= 1000000)
return 7;
if (l >= 100000)
return 6;
if (l >= 10000)
return 5;
if (l >= 1000)
return 4;
if (l >= 100)
return 3;
if (l >= 10)
return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L)
return 19;
if (l >= 100000000000000000L)
return 18;
if (l >= 10000000000000000L)
return 17;
if (l >= 1000000000000000L)
return 16;
if (l >= 100000000000000L)
return 15;
if (l >= 10000000000000L)
return 14;
if (l >= 1000000000000L)
return 13;
if (l >= 100000000000L)
return 12;
if (l >= 10000000000L)
return 11;
if (l >= 1000000000L)
return 10;
if (l >= 100000000L)
return 9;
if (l >= 10000000L)
return 8;
if (l >= 1000000L)
return 7;
if (l >= 100000L)
return 6;
if (l >= 10000L)
return 5;
if (l >= 1000L)
return 4;
if (l >= 100L)
return 3;
if (l >= 10L)
return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map)
write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
static class FastScanner {
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1)
return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] readArray(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] readArrayLong(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public int[][] readArrayMatrix(int N, int M, int Index) {
if (Index == 0) {
int[][] res = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
int[][] res = new int[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
public long[][] readArrayMatrixLong(int N, int M, int Index) {
if (Index == 0) {
long[][] res = new long[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = nextLong();
}
return res;
}
long[][] res = new long[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC)
c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-')
neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] readArrayDouble(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32)
return true;
while (true) {
c = getChar();
if (c == NC)
return false;
else if (c > 32)
return true;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code:
// X and Y are numbers
// ignore number of testcases variable
function pow(X, Y) {
// write code here
// console.log the output in a single line,like example
console.log(Math.pow(X, Y).toFixed(2))
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: def power(N,K):
return ("{0:.2f}".format(N**K))
T=int(input())
for i in range(T):
X,N = map(float,input().strip().split())
print(power(X,N)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main (String[] args)throws Exception {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0)
{
String str[] = read.readLine().trim().split(" ");
double X = Double.parseDouble(str[0]);
int N = Integer.parseInt(str[1]);
System.out.println(String.format("%.2f", myPow(X, N)));
}
}
public static double myPow(double x, int n) {
if (n == Integer.MIN_VALUE)
n = - (Integer.MAX_VALUE - 1);
if (n == 0)
return 1.0;
else if (n < 0)
return 1 / myPow(x, -n);
else if (n % 2 == 1)
return x * myPow(x, n - 1);
else {
double sqrt = myPow(x, n / 2);
return sqrt * sqrt;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define ld long double
#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;
ld power(ld x, ld n){
if(n == 0)
return 1;
else
return x*power(x, n-1);
}
signed main() {
speed;
int t; cin >> t;
while(t--){
double x; int n;
cin >> x >> n;
if(n < 0)
x = 1.0/x, n *= -1;
cout << setprecision(2) << fixed << power(x, n) << 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 Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(read.readLine());
long[] arr = new long[N];
StringTokenizer st = new StringTokenizer(read.readLine());
for(int i=0; i<N; i++) {
arr[i] = Long.parseLong(st.nextToken());
}
Arrays.sort(arr);
long res = 0;
for(int i=N-1;i >-1; i--) {
res += arr[i]*i;
}
System.out.println(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
l=[]
for i in range(n-1):
l.append(arr[i]*((n-1)-i))
print(sum(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n+1];
for(int i=1;i<=n;++i){
cin>>a[i];
}
sort(a+1,a+n+1);
int ans=0;
for(int i=1;i<=n;++i)
ans+=(a[i]*(i-1));
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string which contains all special characters along with letters of the english alphabet, both uppercase and lowercase, your task is to reverse the given string such that special characters will not get affectedInput contains a single line containing the string S.
Constraints:-
1 <= |S| <= 100000
Note:- String will contain alphabets (A. Z, a. z) and special characters (@, #, $ ....)
String may contains empty spacesPrint the reverse string without affecting special characters <b>or</b> reverse string in which only alphabets are reversedSample Input:-
Ab,c,de!$
Sample Output:-
ed,c,bA!$
Sample Input:-
a!!!b. c. d, e'f, ghi
Sampple Output:-
i!!!h. g. f, e'd, cba, I have written this Solution Code: def reverseString(S):
string = list(S)
start = 0
end = len(S) - 1
while start <= end:
if string[start].isalpha() and string[end].isalpha():
string[start], string[end] = string[end], string[start]
start += 1
end -= 1
elif not string[start].isalpha() and string[end].isalpha():
start += 1
elif string[start].isalpha() and not string[end].isalpha():
end -= 1
else:
start += 1
end -= 1
return ''.join(string)
string=input()
string = reverseString(string)
print (string), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string which contains all special characters along with letters of the english alphabet, both uppercase and lowercase, your task is to reverse the given string such that special characters will not get affectedInput contains a single line containing the string S.
Constraints:-
1 <= |S| <= 100000
Note:- String will contain alphabets (A. Z, a. z) and special characters (@, #, $ ....)
String may contains empty spacesPrint the reverse string without affecting special characters <b>or</b> reverse string in which only alphabets are reversedSample Input:-
Ab,c,de!$
Sample Output:-
ed,c,bA!$
Sample Input:-
a!!!b. c. d, e'f, ghi
Sampple Output:-
i!!!h. g. f, e'd, cba, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 101
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int t;
t=1;
while(t--){
string s;
getline(cin,s);
int n=s.length();
vector<char> v;
int x;
for(int i=0;i<n;i++){
x=s[i]-'A';
if(x>=0 && x<26){
v.EB(s[i]);
}
x=s[i]-'a';
if(x>=0 && x<26){
v.EB(s[i]);
}
}
reverse(v.begin(),v.end());
int j=0;
int p;
FOR(i,n){
x=s[i]-'A';
p=s[i]-'a';
if(x>=0 && x<26){
cout<<v[j];
j++;
}
else if(p>=0 && p<26){
cout<<v[j];
j++;
}
else{
cout<<s[i];
}
}
END;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code:
int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code:
int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code: static int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code: def Phone(N,K,M):
if N*K < M :
return -1
x = M//K
if M%K!=0:
x=x+1
return x, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: #include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define ma 10000001
bool a[ma];
int main()
{
int n;
cin>>n;
for(int i=0;i<=n;i++){
a[i]=false;
}
for(int i=2;i<=n;i++){
if(a[i]==false){
for(int j=i+i;j<=n;j+=i){
a[j]=true;
}
}
}
int cnt=0;
for(int i=2;i<=n;i++){
if(a[i]==false){cnt++;}
}
cout<<cnt;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args)
throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long n = Integer.parseInt(br.readLine());
long i=2,j,count,noOfPrime=0;
if(n<=1)
System.out.println("0");
else{
while(i<=n)
{
count=0;
for(j=2; j<=Math.sqrt(i); j++)
{
if( i%j == 0 ){
count++;
break;
}
}
if(count==0){
noOfPrime++;
}
i++;
}
System.out.println(noOfPrime);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: function numberOfPrimes(N)
{
let arr = new Array(N+1);
for(let i = 0; i <= N; i++)
arr[i] = 0;
for(let i=2; i<= N/2; i++)
{
if(arr[i] === -1)
{
continue;
}
let p = i;
for(let j=2; p*j<= N; j++)
{
arr[p*j] = -1;
}
}
//console.log(arr);
let count = 0;
for(let i=2; i<= N; i++)
{
if(arr[i] === 0)
{
count++;
}
}
//console.log(arr);
return count;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import math
n = int(input())
n=n+1
if n<3:
print(0)
else:
primes=[1]*(n//2)
for i in range(3,int(math.sqrt(n))+1,2):
if primes[i//2]:primes[i*i//2::i]=[0]*((n-i*i-1)//(2*i)+1)
print(sum(primes)), 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: 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: 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 string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: str1 = input()
str2 = ''
for i in range(len(str1)):
if(i % 2 == 0):
str2 = str2 + str1[i]+" "
print(str2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String s = sc.next();
for(int i = 0;i<s.length();i++){
if(i%2==0){
System.out.print(s.charAt(i)+" ");
}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: // str is input
function oddChars(str) {
// write code here
// do not console.log
// return the output as a string
return str.split('').filter((v,idx)=> idx % 2 === 0).join(' ')
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
for(int i=0;i<s.length();i++){
if(!(i&1)){cout<<s[i]<<" ";}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: static void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
System.out.print(x+4*j+" ");
}
System.out.println();
x+=6;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: def Pattern(N):
x=0
for i in range (0,N):
for j in range (0,N):
print(x+4*j,end=' ')
print()
x = x+6
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <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: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: n = int(input())
if (n%4==0 and n%100!=0 or n%400==0):
print("YES")
elif n==0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int n = scanner.nextInt();
LeapYear(n);
}
static void LeapYear(int year){
if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");}
else {
System.out.println("NO");}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a 2D matrix of size [M, N], Q number of queries. In each query, you will be given a number X to check whether it is present in the matrix or not.The first line contains three integers M(number of rows), N(Number of columns), and Q(number of queries)
Next M lines contain N integers which are the elements of the matrix.
Next, Q lines will contain a single integer X.
Constraints:-
1<=M,N<=1000
1<=Q<=10000
1<=X, Arr[i]<=1000000000For each query, in a new line print "Yes" if the element is present in matrix or print "No" if the element is absent.Input:-
3 3 2
1 2 3
5 6 7
8 9 10
7
11
Output:-
Yes
No
Input:-
3 4 4
4 8 11 14
15 54 45 47
1 2 3 4
5
15
45
26
Output:-
No
Yes
Yes
No, I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int q = sc.nextInt();
int mat[] = new int[m*n];
int matSize = m*n;
for(int i = 0; i < m*n; i++)
{
int ele = sc.nextInt();
mat[i] = ele;
}
Arrays.sort(mat);
for(int i = 1; i <= q; i++)
{
int qs = sc.nextInt();
System.out.println(isPresent(mat, matSize, qs));
}
}
static String isPresent(int mat[], int size, int ele)
{
int l = 0, h = size-1;
while(l <= h)
{
int mid = l + (h-l)/2;
if(mat[mid] == ele)
return "Yes";
else if(mat[mid] > ele)
h = mid - 1;
else l = mid+1;
}
return "No";
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a 2D matrix of size [M, N], Q number of queries. In each query, you will be given a number X to check whether it is present in the matrix or not.The first line contains three integers M(number of rows), N(Number of columns), and Q(number of queries)
Next M lines contain N integers which are the elements of the matrix.
Next, Q lines will contain a single integer X.
Constraints:-
1<=M,N<=1000
1<=Q<=10000
1<=X, Arr[i]<=1000000000For each query, in a new line print "Yes" if the element is present in matrix or print "No" if the element is absent.Input:-
3 3 2
1 2 3
5 6 7
8 9 10
7
11
Output:-
Yes
No
Input:-
3 4 4
4 8 11 14
15 54 45 47
1 2 3 4
5
15
45
26
Output:-
No
Yes
Yes
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define N 1000000
long a[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,q;
cin>>n>>m>>q;
n=n*m;
long long sum=0,sum1=0;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
while(q--){
long x;
cin>>x;
int l=0;
int r=n-1;
while (r >= l) {
int mid = l + (r - l) / 2;
if (a[mid] == x) {
cout<<"Yes"<<endl;goto f;}
if (a[mid] > x)
{
r=mid-1;
}
else {l=mid+1;
}
}
cout<<"No"<<endl;
f:;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton is given a non- negative integer A and his friend Ramanujan wants Newton to find another non- negative integer B such that xor of these two numbers is an even prime number, i. e. A xor B should be an even prime number
Help Newton find such integer B.The first and the only line of the input contains a single non- negative integer A.
<b>Constraints:</b>
0 ≤ A ≤ 10<sup>18</sup>Print the value of B<b>Sample Input 1:</b>
10
<b>Sample Output 1:</b>
8
<b>Sample Input 2:</b>
29
<b>Sample Output 2:</b>
31, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
long long a; cin>>a;
cout<<(a^2);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code: function numberOfDays(n)
{
let ans;
switch(n)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
ans = Number(31);
break;
case 2:
ans = Number(28);
break;
default:
ans = Number(30);
break;
}
return ans;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code:
static void numberofdays(int M){
if(M==4 || M ==6 || M==9 || M==11){System.out.print(30);}
else if(M==2){System.out.print(28);}
else{
System.out.print(31);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code:
import java.io.*;
import java.util.*;
class Main {
public static boolean isArrangementPossible(long arr[],int n,long sum){
if(n==1){
if(arr[0]==sum)
return true;
else
return false;
}
return(isArrangementPossible(arr,n-1,sum-arr[n-1]) || isArrangementPossible(arr,n-1,sum+arr[n-1]));
}
public static void main (String[] args) throws IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String str1[]=br.readLine().trim().split(" ");
int n=Integer.parseInt(str1[0]);
long sum=Long.parseLong(str1[1]);
String str[]=br.readLine().trim().split(" ");
long arr[]=new long[n];
for(int i=0;i<n;i++){
arr[i]=Long.parseLong(str[i]);
}
if(isArrangementPossible(arr,n,sum)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code: def checkIfGivenTargetIsPossible(nums,currSum,i,targetSum):
if i == len(nums):
if currSum == targetSum:
return 1
return 0
if(checkIfGivenTargetIsPossible(nums,currSum + nums[i],i+1,targetSum)):
return 1
return checkIfGivenTargetIsPossible(nums,currSum - nums[i], i+1,targetSum)
n,k = map(int,input().split())
nums = list(map(int,input().split()))
if(checkIfGivenTargetIsPossible(nums,0,0,k)):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code: #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define int long long
int k;
using namespace std;
int solve(int n, int a[], int i, int curr ){
if(i==n){
if(curr==k){return 1;}
return 0;
}
if(solve(n,a,i+1,curr+a[i])==1){return 1;}
return solve(n,a,i+1,curr-a[i]);
}
signed main() {
int n;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
if(solve(n,a,1,a[0])){
cout<<"YES";}
else{
cout<<"NO";}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We have provided you with the JS boilerplate, within which you will complete the <code>arrayProperties</code> function which takes two arguments <code>arr1</code> and <code>arr2</code>, which are lists of fruits. Inside the function, you will be applying different methods on the array, and after some methods are applied, you will print the result on the console.
<strong>Note: </strong>Follow the order of steps, and accordingly apply the method to pass the tests.
Steps:
<ol>
<li>Create an array <code>arr3</code>, which would consist of the items from <code>arr2</code> followed by the items from <code>arr1</code> concatenated together.</li>
<li><code>Push</code> arr2 array in the arr3 array and print the result to console.</li>
<li><code>Pop out</code> the last item from the arr3.</li>
<li>print the <code>reverse order</code> of arr3 to console.</li>
<li>Find the last index of the <code>"orange"</code> item in arr3 array and print it to console.</li>
<li>Now, create a slice of arr3 which <code>includes the first item till the third item</code> and print the length of it to the console. </li>
<li>Last step, <code>join</code> the sliced array with items separated by a comma and print it to the console. The last step should print a string to the console. </li>
</ol>
To test with output generator
Paste in input like this
["pineapple","orange","banana"] ["apple","orange","mango"]The function takes <code>two arrays</code>, arr1, and arr2, as arguments.
Both arr1 and arr2, are arrays of fruits.Prints <code>two arrays</code>, <code>two numbers</code>, and <code>a string</code>, in the same order, to the console.arr1= ["apple","orange","mango"];
arr2 = ["pineapple","orange"];
arrayProperties(arr1, arr2);
// should console log
['pineapple','orange','apple','orange','mango',['pineapple','orange' ]]
[ 'mango', 'orange', 'apple', 'orange', 'pineapple' ]
3
3
mango,orange,apple, I have written this Solution Code: function arrayProperties(arr1, arr2) {
let arr3 = arr2.concat(arr1);
arr3.push(arr2);
console.log(arr3);
arr3.pop();
console.log(arr3.reverse());
let orangeIndex = arr3.lastIndexOf("orange");
console.log(orangeIndex);
let slicedArr3 = arr3.slice(0, 3);
console.log(slicedArr3.length);
let arrayText = slicedArr3.join();
console.log(arrayText);
}, In this Programming Language: JavaScript, 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 an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 <= n <= 100
<b>Note:</b>
<i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:-
5
Sample Output:-
2 4
Sample Input:-
6
Sample Output:-
2 4 6, I have written this Solution Code: def For_Loop(n):
string = ""
for i in range(1, n+1):
if i % 2 == 0:
string += "%s " % i
return string
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 <= n <= 100
<b>Note:</b>
<i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:-
5
Sample Output:-
2 4
Sample Input:-
6
Sample Output:-
2 4 6, I have written this Solution Code: public static void For_Loop(int n){
for(int i=2;i<=n;i+=2){
System.out.print(i+" ");
}
}, In this Programming Language: Java, 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.