Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void insertionSort(int[] arr){
for(int i = 0; i < arr.length-1; i++){
for(int j = i+1; j < arr.length; j++){
if(arr[i] > arr[j]){
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
}
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while(T > 0){
int n = scan.nextInt();
int arr[] = new int[n];
for(int i = 0; i<n; i++){
arr[i] = scan.nextInt();
}
insertionSort(arr);
for(int i = 0; i<n; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
T--;
System.gc();
}
}
}, 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 positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: def InsertionSort(arr):
arr.sort()
return arr, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 ≤ |<i>s</i>| ≤ 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1
abbb
Sample Output 1
2
Explanation:
The possible palindromes are:
1. abba
2. bbbb
========================================================================
Sample Input 2
abba
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 br = new BufferedReader(new InputStreamReader(System.in));
char str[] = br.readLine().toCharArray();
int ans = 0;
char arr[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
Set<String> set = new HashSet<>();
for(int i=0;i<str.length;i++){
char p = str[i];
for(char ch:arr){
if(ch==p) continue;
str[i] = ch;
if(isPallindrome(str)){
if(set.contains(String.valueOf(str))==false){
set.add(String.valueOf(str));
ans++;
}
}
str[i] = p;
}
}
System.out.println(ans);
}
static boolean isPallindrome(char[] str){
int i = 0;
int j = str.length-1;
while(i<j){
if(str[i]!=str[j]) return false;
i++;
j--;
}
return true;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 ≤ |<i>s</i>| ≤ 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1
abbb
Sample Output 1
2
Explanation:
The possible palindromes are:
1. abba
2. bbbb
========================================================================
Sample Input 2
abba
Sample Output 2
0
, I have written this Solution Code: n=input()
n=list(n)
ln=len(n)
cnt=0
for i in range(ln//2):
if not(n[i]==n[ln-i-1]):
cnt+=1
if(cnt==1):
print(2)
elif(cnt==0 and ln%2==1):
print(25)
else:
print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 ≤ |<i>s</i>| ≤ 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1
abbb
Sample Output 1
2
Explanation:
The possible palindromes are:
1. abba
2. bbbb
========================================================================
Sample Input 2
abba
Sample Output 2
0
, I have written this Solution Code: #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define endl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define sz(x) ((ll)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x = min(x,y)
#define maxi(x,y) x = max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(0, 1e9);
// DEBUG FUNCTIONS START
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void deb() {cerr << "\n";}
template <typename T, typename... V> void deb(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; deb(v...);}
// DEBUG FUNCTIONS END
const int N = 2e5 + 5;
void solve(){
string s;
cin >> s;
int n = sz(s);
int x = 0;
rep(i, 0, n / 2){
x += s[i] != s[n - 1 - i];
}
if(x == 1){
cout << 2 << endl;
}
else if(x > 1){
cout << 0 << endl;
}
else{
if(n & 1){
cout << 25 << endl;
}
else{
cout << 0 << endl;
}
}
}
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
cout << fixed << setprecision(15);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
int powm(int a, int b){
int res = 1;
while (b) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
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 n, m;
cin >> n >> m;
cout << __gcd(n, m);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: def hcf(a, b):
if(b == 0):
return a
else:
return hcf(b, a % b)
li= list(map(int,input().strip().split()))
print(hcf(li[0], li[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] sp = br.readLine().trim().split(" ");
long m = Long.parseLong(sp[0]);
long n = Long.parseLong(sp[1]);
System.out.println(GCDAns(m,n));
}
private static long GCDAns(long m,long n){
if(m==0)return n;
if(n==0)return m;
return GCDAns(n%m,m);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two numbers m and n, multiply them using only "addition" operations.<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>Multiply()</b> that takes the integer M and N as a parameter.
Constraints:
1 ≤ T ≤ 100
0 ≤ M, N ≤ 100Return the product of N and M.Sample Input
2
2 3
3 4
Sample Output
6
12, I have written this Solution Code: static int Multiply(int n, int m)
{
if(n==0 || m==0){return 0;}
if (m == 1)
{ return n;}
return n + Multiply(n,m-1);
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two numbers m and n, multiply them using only "addition" operations.<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>Multiply()</b> that takes the integer M and N as a parameter.
Constraints:
1 ≤ T ≤ 100
0 ≤ M, N ≤ 100Return the product of N and M.Sample Input
2
2 3
3 4
Sample Output
6
12, I have written this Solution Code: def multiply_by_recursion(n,m):
# Base Case
if n==0 or m==0:
return 0
# Recursive Case
if m==1:
return n
return n + multiply_by_recursion(n,m-1)
# Driver Code
t=int(input())
while t>0:
l=list(map(int,input().strip().split()))
n=l[0]
m=l[1]
print(multiply_by_recursion(n,m))
t=t-1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is playing a game in which there are N monsters standing in a circle and the ith (1 <= i <= N) monster has A[i] HP.
Rules:-
At the end of each second, all the monster's HP decreases by 1 if it is not 0.
At the end of each second, the player will jump to the next monster (monster standing to the right of the current).
The game ends when the current monster has 0 health.
If the player starts at index 1 then find the index at which the game ends.First line of input contains a single integer N. The next line of input contains N space-separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
0 <= A[i] <= 1000000000Print a single index at which the game ends.Sample Input:-
5
3 2 3 2 1
Sample Output:-
4
Explanation:-
[ 3(P), 2, 3, 2, 1] - > [2, 1(P), 2, 1, 0] - > [1, 0, 1(P), 0, 0 ] - > [0, 0, 0, 0(P), 0]
Sample Input:-
3
10 10 10
Sample Output:-
2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String s[]=br.readLine().split(" ");
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(s[i]);
}
int count=0;
int i=0;
int ans=0;
while(true)
{
if(arr[i]-count<=0)
{
ans=i+1;
break;
}
i=(++i)%n;
count++;
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is playing a game in which there are N monsters standing in a circle and the ith (1 <= i <= N) monster has A[i] HP.
Rules:-
At the end of each second, all the monster's HP decreases by 1 if it is not 0.
At the end of each second, the player will jump to the next monster (monster standing to the right of the current).
The game ends when the current monster has 0 health.
If the player starts at index 1 then find the index at which the game ends.First line of input contains a single integer N. The next line of input contains N space-separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
0 <= A[i] <= 1000000000Print a single index at which the game ends.Sample Input:-
5
3 2 3 2 1
Sample Output:-
4
Explanation:-
[ 3(P), 2, 3, 2, 1] - > [2, 1(P), 2, 1, 0] - > [1, 0, 1(P), 0, 0 ] - > [0, 0, 0, 0(P), 0]
Sample Input:-
3
10 10 10
Sample Output:-
2, I have written this Solution Code: n = int(input())
a = list(map(int,input().split()))
i=0
while(True):
if(a[i%n]-i<=0):
print(i%n+1)
break
i+=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is playing a game in which there are N monsters standing in a circle and the ith (1 <= i <= N) monster has A[i] HP.
Rules:-
At the end of each second, all the monster's HP decreases by 1 if it is not 0.
At the end of each second, the player will jump to the next monster (monster standing to the right of the current).
The game ends when the current monster has 0 health.
If the player starts at index 1 then find the index at which the game ends.First line of input contains a single integer N. The next line of input contains N space-separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
0 <= A[i] <= 1000000000Print a single index at which the game ends.Sample Input:-
5
3 2 3 2 1
Sample Output:-
4
Explanation:-
[ 3(P), 2, 3, 2, 1] - > [2, 1(P), 2, 1, 0] - > [1, 0, 1(P), 0, 0 ] - > [0, 0, 0, 0(P), 0]
Sample Input:-
3
10 10 10
Sample Output:-
2, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 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(){
fast();
int n;
cin>>n;
int a[n];
FOR(i,n){
cin>>a[i];}
int ans=0;
int l=0;
int h=1e10;
int m;
ans=h;
int p;
FOR(i,n){
int k;
l=0;
h=1e10;
while(l<h){
m=l+h;
m/=2;
// out1(l);out(h);
if(a[i]<=(m*n+i)){
h=m;
}
else{
l=m+1;
}
}
//out(l);
if((l*n+i)<ans){
ans=l*n+1;
p=i+1;
}
}
out(p);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A basic queue has the following operations:
Enqueue: add a new element to the end of the queue.
Dequeue: remove the element from the front of the queue and return it.
In this challenge, you must first implement a queue using two stacks. Then process q queries, where each query is one of the following 3 types:
1 x: Enqueue element x into the end of the queue.
2: Dequeue the element at the front of the queue.
3: Print the element at the front of the queue.<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>enQueue()</b> that takes the integer x(input element) as a parameter.
<b>deQueue()</b>that takes no parameter
<b>Print1()</b>that print the element which is at the front of the queue
Constraints:-
1 <= x <= 10^9
1 <= number of queries <= 1000
Note:- It is guaranteed that the queue will never be empty whenever Print function or deQueue function is called.Print the value of the element which is at the front of the queue on a new line in Print1().Sample Input:-
10
1 42
2
1 14
3
1 28
3
1 60
1 78
2
2
Sample Output:-
14
14, I have written this Solution Code:
static void enQueue(int x)
{
// Move all elements from s1 to s2
while (!s1.isEmpty())
{
s2.push(s1.pop());
//s1.pop();
}
// Push item into s1
s1.push(x);
// Push everything back to s1
while (!s2.isEmpty())
{
s1.push(s2.pop());
//s2.pop();
}
}
// Dequeue an item from the queue
static void deQueue()
{
// if first stack is empty
if (s1.isEmpty())
{
System.out.println("Q is Empty");
System.exit(0);
}
// Return top of s1
int x = s1.peek();
s1.pop();
}
static void Print1(){
int x=s1.peek();
System.out.println(x);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array in which all numbers except two are repeated once. (i. e. we have 2N+2 numbers and N numbers are occurring twice and remaining two have occurred once). Find those two numbers.First line of input contains a single integer N. The next line of input contains 2*N+2 space separated integers.
Constraints:-
1 < = N < = 10000
1 < = Arr[i] < = 100000000Print the two elements separated by space (print the lower element first).Sample Input:-
2
1 3 4 1 5 3
Sample Output:-
4 5
Sample Input:-
3
1 2 3 5 4 3 2 1
Sample Output:-
4 5, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(bf.readLine());
int arr[]=new int[2*n+2];
long xor=0;
String str[]=bf.readLine().split(" ");
for(int i=0;i<2*n+2;i++)
{
arr[i]=Integer.parseInt(str[i]);
xor=xor^arr[i];
}
int bit=1;
while(bit<=xor)
{
if((bit&xor)!=0)
{
for(int i=0;i<(2*n+2);i++)
{
if((arr[i]&bit)!=0)
{
arr[i]=0;
}
}
break;
}
else
{
bit=(bit<<1);
}
}
long v=0;
for(int i=0;i<(2*n+2);i++)
{
v=v^arr[i];
}
long q=v^xor;
if(v>q)
System.out.print(q+" "+v);
else
System.out.print(v+" "+q);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array in which all numbers except two are repeated once. (i. e. we have 2N+2 numbers and N numbers are occurring twice and remaining two have occurred once). Find those two numbers.First line of input contains a single integer N. The next line of input contains 2*N+2 space separated integers.
Constraints:-
1 < = N < = 10000
1 < = Arr[i] < = 100000000Print the two elements separated by space (print the lower element first).Sample Input:-
2
1 3 4 1 5 3
Sample Output:-
4 5
Sample Input:-
3
1 2 3 5 4 3 2 1
Sample Output:-
4 5, I have written this Solution Code: n=int(input())
l=list(map(int,input().split()))
d={}
for i in l:
d[i]=d.get(i,0)+1
res=[]
for i,j in d.items():
if(j==1):
res.append(i)
print(*sorted(res)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array in which all numbers except two are repeated once. (i. e. we have 2N+2 numbers and N numbers are occurring twice and remaining two have occurred once). Find those two numbers.First line of input contains a single integer N. The next line of input contains 2*N+2 space separated integers.
Constraints:-
1 < = N < = 10000
1 < = Arr[i] < = 100000000Print the two elements separated by space (print the lower element first).Sample Input:-
2
1 3 4 1 5 3
Sample Output:-
4 5
Sample Input:-
3
1 2 3 5 4 3 2 1
Sample Output:-
4 5, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int x=2*n+2;
long long a[x];
for(int i=0;i<x;i++){
cin>>a[i];
}
sort(a,a+x);
int j=1;
for(int i=j;i<x;i+=2){
if(a[i]!=a[i-1]){cout<<a[i-1]<<" ";i--;}
}
if(a[x-1]!=a[x-2]){cout<<a[x-1];}
}
, 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, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int m = 100001;
int main(){
int n,k;
cin>>n>>k;
long long a[n],sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]<0){
a[i]=-a[i];
}
}
sort(a,a+n);
for(int i=0;i<k;i++){
sum+=a[n-i-1]*a[n-i-1];
}
cout<<sum;
}
, 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, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
String[] NK = br.readLine().split(" ");
String[] inputs = br.readLine().split(" ");
int N = Integer.parseInt(NK[0]);
int K = Integer.parseInt(NK[1]);
long[] arr = new long[N];
long answer = 0;
for(int i = 0; i < N; i++){
arr[i] = Math.abs(Long.parseLong(inputs[i]));
}
quicksort(arr, 0, N-1);
for(int i = (N-K); i < N;i++){
answer += (arr[i]*arr[i]);
}
System.out.println(answer);
}
static void quicksort(long[] arr, int start, int end){
if(start < end){
int pivot = partition(arr, start, end);
quicksort(arr, start, pivot-1);
quicksort(arr, pivot+1, end);
}
}
static int partition(long[] arr, int start, int end){
long pivot = arr[end];
int i = start - 1;
for(int j = start; j < end; j++){
if(arr[j] < pivot){
i++;
swap(arr, i, j);
}
}
swap(arr, i+1, end);
return (i+1);
}
static void swap(long[] arr, int i, int j){
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}, 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, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: x,y = map(int,input().split())
arr = list(map(int,input().split()))
s=0
for i in range(x):
if arr[i]<0:
arr[i]=abs(arr[i])
arr=sorted(arr,reverse=True)
for i in range(0,y):
s = s+arr[i]*arr[i]
print(s)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: for i in range(int(input())):
n, x = map(int, input().split())
if x >= 10:
print(0)
else:
print((10-x)*(n-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, 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, x;
cin >> n >> x;
if(x >= 10)
cout << 0 << endl;
else
cout << (10-x)*(n-1) << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
while (T -->0){
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int p = Integer.parseInt(s[1]);
if (p<10)
System.out.println(Math.abs(n-1)*(10-p));
else System.out.println(0);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: n=int(input())
a=map(int,input().split())
b=[]
mx=-200000
cnt=0
for i in a:
if i>mx:
cnt+=1
mx=i
print(cnt), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: function numberOfRoofs(arr)
{
let count=1;
let max = arr[0];
for(let i=1;i<arrSize;i++)
{
if(arr[i] > max)
{
count++;
max = arr[i];
}
}
return count;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++){
a[i]=s.nextInt();
}
int count=1;
int max = a[0];
for(int i=1;i<n;i++)
{
if(a[i] > max)
{
count++;
max = a[i];
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){cout<<"FizzBuzz"<<" ";}
else if(i%5==0){cout<<"Buzz ";}
else if(i%3==0){cout<<"Fizz ";}
else{cout<<i<<" ";}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
fizzbuzz(x);
}
static void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");}
else if(i%5==0){System.out.print("Buzz ");}
else if(i%3==0){System.out.print("Fizz ");}
else{System.out.print(i+" ");}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: def fizzbuzz(n):
for i in range (1,n+1):
if (i%3==0 and i%5==0):
print("FizzBuzz",end=' ')
elif i%3==0:
print("Fizz",end=' ')
elif i%5==0:
print("Buzz",end=' ')
else:
print(i,end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){printf("FizzBuzz ");}
else if(i%5==0){printf("Buzz ");}
else if(i%3==0){printf("Fizz ");}
else{printf("%d ",i);}
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array Arr of n integers. You can perform the following operations on the array any number of times.
Operation 1: Add or Subtract 2 from any element of the array any number of times
Operation 2: Remove a number from the array
Your aim is to make all the elements of the array equal after performing the above operations any number of times. Report the maximum size of the array possible.The first line of input contains N, the size of the array
The second line of input contains N space-separated integers
Constraints
1 ≤ N ≤ 100000
1 ≤ Arr[i] ≤ 1000000000The output should contain only one integer, the maximum size of the array possible such that all elements of the array are equal.Sample Input 1
5
1 2 3 3 2
Sample Output 1
3
Sample Input 2
2
1 2
Sample Output 2
1
Explanation:-
Testcase1 :- you can remove both 2 from the array making the array equal to 1,3,3. Now subtract 2 from both 3 making the array equal 1,1,1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int size = Integer.parseInt(bf.readLine());
String s[] = bf.readLine().split(" ");
int countEven =0;
int countOdd = 0;
for(int i=0;i<size;i++){
if(Integer.parseInt(s[i])%2 == 0){
countEven++;
}else{
countOdd++;
}
}
System.out.println(Math.max(countOdd,countEven));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array Arr of n integers. You can perform the following operations on the array any number of times.
Operation 1: Add or Subtract 2 from any element of the array any number of times
Operation 2: Remove a number from the array
Your aim is to make all the elements of the array equal after performing the above operations any number of times. Report the maximum size of the array possible.The first line of input contains N, the size of the array
The second line of input contains N space-separated integers
Constraints
1 ≤ N ≤ 100000
1 ≤ Arr[i] ≤ 1000000000The output should contain only one integer, the maximum size of the array possible such that all elements of the array are equal.Sample Input 1
5
1 2 3 3 2
Sample Output 1
3
Sample Input 2
2
1 2
Sample Output 2
1
Explanation:-
Testcase1 :- you can remove both 2 from the array making the array equal to 1,3,3. Now subtract 2 from both 3 making the array equal 1,1,1, I have written this Solution Code: n=int(input())
l=list(map(int,input().split()))
c=0
for i in l:
if(i%2==0):
c+=1
if(n-c>c):
print(abs(n-c))
else:
print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array Arr of n integers. You can perform the following operations on the array any number of times.
Operation 1: Add or Subtract 2 from any element of the array any number of times
Operation 2: Remove a number from the array
Your aim is to make all the elements of the array equal after performing the above operations any number of times. Report the maximum size of the array possible.The first line of input contains N, the size of the array
The second line of input contains N space-separated integers
Constraints
1 ≤ N ≤ 100000
1 ≤ Arr[i] ≤ 1000000000The output should contain only one integer, the maximum size of the array possible such that all elements of the array are equal.Sample Input 1
5
1 2 3 3 2
Sample Output 1
3
Sample Input 2
2
1 2
Sample Output 2
1
Explanation:-
Testcase1 :- you can remove both 2 from the array making the array equal to 1,3,3. Now subtract 2 from both 3 making the array equal 1,1,1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
long long a;
int cnt;
for(int i=0;i<n;i++){
cin>>a;
if(a&1){cnt++;}
}
cout<<max(cnt,n-cnt);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John has N candies. He wants to crush all of them. He feels that it would be boring to crush the candies randomly, so he found a method to crush them. He divides these candies into a minimum number of groups such that no group contains more than 3 candies. He crushes one candy from each group. If there are G groups in a single step, then the cost incurred in crushing a single candy for that step is G dollars. After candy from each group is crushed, he takes all the remaining candies and repeats the process until he has no candies left. He hasn't started crushing yet, but he wants to know how much the total cost would be incurred. Can you help him?
You have to answer Q-independent queries.The first line of input contains a single integer, Q denoting the number of queries.
Next, Q lines contain a single integer N denoting the number of candies John has.
<b>Constraints</b>
1 <= Q <= 5 * 10^4
1 <= N <= 10^9Print Q lines containing total cost incurred for each query.Sample Input 1:
1
4
Sample Output 1:
6
<b>Explanation:</b>
Query 1: First step John divides the candies into two groups of 3 and 1 candy respectively. Crushing one-one candy from both groups would cost him 2x2 = 4 dollars. He is now left with 2 candies. He divides it into one group. He crushes one candy for 1 dollar. Now, he is left with 1 candy. He crushes the last candy for 1 dollar. So, the total cost incurred is 4+1+1 = 6 dollars., I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int cost(int n){
if(n == 0) return 0;
int g = (n-1)/3 + 1;
return g*g + cost(n-g);
}
signed main() {
IOS;
clock_t start = clock();
int q; cin >> q;
while(q--){
int n;
cin >> n;
cout << cost(n) << endl;
}
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John has N candies. He wants to crush all of them. He feels that it would be boring to crush the candies randomly, so he found a method to crush them. He divides these candies into a minimum number of groups such that no group contains more than 3 candies. He crushes one candy from each group. If there are G groups in a single step, then the cost incurred in crushing a single candy for that step is G dollars. After candy from each group is crushed, he takes all the remaining candies and repeats the process until he has no candies left. He hasn't started crushing yet, but he wants to know how much the total cost would be incurred. Can you help him?
You have to answer Q-independent queries.The first line of input contains a single integer, Q denoting the number of queries.
Next, Q lines contain a single integer N denoting the number of candies John has.
<b>Constraints</b>
1 <= Q <= 5 * 10^4
1 <= N <= 10^9Print Q lines containing total cost incurred for each query.Sample Input 1:
1
4
Sample Output 1:
6
<b>Explanation:</b>
Query 1: First step John divides the candies into two groups of 3 and 1 candy respectively. Crushing one-one candy from both groups would cost him 2x2 = 4 dollars. He is now left with 2 candies. He divides it into one group. He crushes one candy for 1 dollar. Now, he is left with 1 candy. He crushes the last candy for 1 dollar. So, the total cost incurred is 4+1+1 = 6 dollars., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)
);
long q = Long.parseLong(br.readLine());
while(q-->0)
{
long N = Long.parseLong(br.readLine());
System.out.println(candyCrush(N,0,0));
}
}
static long candyCrush(long N, long cost,long group)
{
if(N==0)
{
return cost;
}
if(N%3==0)
{
group = N/3;
cost = cost + (group*group);
return candyCrush(N-group,cost,0);
}
else
{
group = (N/3)+1;
cost = cost + (group*group);
return candyCrush(N-group,cost,0);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: m,n = map(int , input().split())
if (m%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 an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
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,m;
cin>>n>>m;
if(n%m==0)
cout<<"Yes";
else
cout<<"No";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, 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);
long n = sc.nextLong();
Long m = sc.nextLong();
if(n%m==0){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
, 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: 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: Determine the number of employees in each department.
Output the department name together with the corresponding number of employees.DataFrame/SQL Table with the following schema -
<schema>[{'name': 'worker', 'columns': [{'name': 'worker_id', 'type': 'int64'}, {'name': 'first_name', 'type': 'object'}, {'name': 'last_name', 'type': 'object'}, {'name': 'salary', 'type': 'int64'}, {'name': 'joining_date', 'type': 'datetime64[ns]'}, {'name': 'department', 'type': 'object'}]}]</schema>Each row in the new line and each value of a row separated by a |, i.e.,
0|1|2
1|2|3
2|3|4-, I have written this Solution Code: ser = worker['department'].value_counts()
ser = ser.sort_index() #index should be alphabetically arranged
for i,v in ser.items():
print(f"{i}|{v}"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Determine the number of employees in each department.
Output the department name together with the corresponding number of employees.DataFrame/SQL Table with the following schema -
<schema>[{'name': 'worker', 'columns': [{'name': 'worker_id', 'type': 'int64'}, {'name': 'first_name', 'type': 'object'}, {'name': 'last_name', 'type': 'object'}, {'name': 'salary', 'type': 'int64'}, {'name': 'joining_date', 'type': 'datetime64[ns]'}, {'name': 'department', 'type': 'object'}]}]</schema>Each row in the new line and each value of a row separated by a |, i.e.,
0|1|2
1|2|3
2|3|4-, I have written this Solution Code: SELECT
department,
count(DISTINCT worker_id) AS num_of_workers
FROM worker
GROUP BY
department, In this Programming Language: SQL, 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: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), 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 bf = new BufferedReader(new InputStreamReader(System.in));
String[] st = bf.readLine().split(" ");
if(Integer.parseInt(st[1])==0)
System.out.print(-1);
else {
int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1]));
System.out.print(f);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split()
D = int(D)
Q = int(Q)
if(0<=D and Q<=100 and Q >0):
print(int(D/Q))
else:
print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
if(m==0){cout<<-1;return 0;}
cout<<n/m;
}, 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 <b>Palindrome</b> or not. A number is said to be Palindrome when it reads the same from backward as forward.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>isPalindrome()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 9999You need to return "True" is the number is palindrome otherwise "False".Sample Input:
5
Sample Output:
True
Sample Input:
121
Sample Output:
True, I have written this Solution Code: static void isPalindrome(int N)
{
int digit = 0, sum = 0, temp = N;
while(N > 0)
{
digit = N %10;
sum = sum*10 + digit;
N = N/10;
}
if(sum == temp)
System.out.println("True");
else System.out.println("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 <b>Palindrome</b> or not. A number is said to be Palindrome when it reads the same from backward as forward.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>isPalindrome()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 9999You need to return "True" is the number is palindrome otherwise "False".Sample Input:
5
Sample Output:
True
Sample Input:
121
Sample Output:
True, I have written this Solution Code: void isPalindrome(int N){
int digit=0, sum=0, temp = N;
while(N > 0)
{
digit = N%10;
sum = sum*10 + digit;
N = N/10;
}
if(sum == temp)
cout << "True";
else cout << "False";
}
, 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 <b>Palindrome</b> or not. A number is said to be Palindrome when it reads the same from backward as forward.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>isPalindrome()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 9999You need to return "True" is the number is palindrome otherwise "False".Sample Input:
5
Sample Output:
True
Sample Input:
121
Sample Output:
True, I have written this Solution Code: def isPalindrome(N):
res = str(N) == str(N)[::-1]
return res, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square.
<b>Constraints:</b>
1 <= side <=100You just have to print the area of a squareSample Input:-
3
Sample Output:-
9
Sample Input:-
6
Sample Output:-
36, I have written this Solution Code: def area(side_of_square):
print(side_of_square*side_of_square)
def main():
N = int(input())
area(N)
if __name__ == '__main__':
main(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square.
<b>Constraints:</b>
1 <= side <=100You just have to print the area of a squareSample Input:-
3
Sample Output:-
9
Sample Input:-
6
Sample Output:-
36, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int side = Integer.parseInt(br.readLine());
System.out.print(side*side);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The government has launched a missile to destroy the enemy bases which are represented by a 1-indexed array of N integers.
At the time of launch, all the enemy bases which have defense lower than or equal to A will be destroyed immediately. Then after, each destroyed defense will act as government source and will lower the enemy base defense by A when it attacks any particular base. If the current base is i (1 <= i < = N) then on the first day it will attack i+1 and i-1 base the next day it will attack the i+2 and i-2 base (the attack happens only if a base exists at the attack position). The base will be destroyed if its defense goes below or equal to 0.
Since the missile is costly, the government wants to know the minimum A requires so that the project can be ended within D days.
For more clarification see the example
Note:- Only the defenses which were destroyed at the time of launch will act as a sourceFirst line of input contains two space separated integer N and D. Second line of input contains N space separated integers denoting the value of the Array.
Constraints:-
1 < = N < = 100000
1 < = Arr[i] < = 100000000
1 < = D < = 10000Print the minimum attack power requires to complete the project within D days.Sample Input:-
3 1
5 10 5
Sample Output:-
5
Explanation:-
1st and 3rd defense will be destroyed immediately then at first day 1st will attack 2nd defense and lowers its defense by 5 and on the same day 3rd defense will also attack the second and destroys it.
Sample Input:-
6 3
2 15 4 2 6 9
Sample Output:-
5
Explanation:-
After launch :- 0 15 0 0 6 9 (1st 3rd and 4th will act as source)
Day 1:- 0 5 0 0 1 9
Day 2:- 0 0 0 0 0 4
Day 3:- 0 0 0 0 0 0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
int n = Integer.parseInt(input[0]);
int d = Integer.parseInt(input[1]);
long[] arr = new long[n];
long[] pre = new long[n];
long max = 0;
input = br.readLine().split(" ");
for(int i = 0; i < n; i++){
arr[i] = Integer.parseInt(input[i]);
max = Math.max(max, arr[i]);
}
long low = 1, high = max+1;
while(low < high) {
long mid = (low + high)/2;
if(check(mid, d, arr, pre, n))
high = mid;
else
low = mid + 1;
}
System.out.println(low);
}
public static boolean check(long a, int d, long[] arr, long[] pre, int n) {
int count = 0;
for(int i = 0; i < n; i++){
if(arr[i] <= a)
count++;
pre[i] = count;
}
long ans;
for(int i = 0; i < n; i++) {
if(arr[i] > a){
ans = pre[i];
if(i > d)
ans -= pre[i-d-1];
if(i+d < n)
ans += pre[i+d] - pre[i];
else
ans += pre[n-1] - pre[i];
if(ans*a < arr[i])
return false;
}
}
return true;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The government has launched a missile to destroy the enemy bases which are represented by a 1-indexed array of N integers.
At the time of launch, all the enemy bases which have defense lower than or equal to A will be destroyed immediately. Then after, each destroyed defense will act as government source and will lower the enemy base defense by A when it attacks any particular base. If the current base is i (1 <= i < = N) then on the first day it will attack i+1 and i-1 base the next day it will attack the i+2 and i-2 base (the attack happens only if a base exists at the attack position). The base will be destroyed if its defense goes below or equal to 0.
Since the missile is costly, the government wants to know the minimum A requires so that the project can be ended within D days.
For more clarification see the example
Note:- Only the defenses which were destroyed at the time of launch will act as a sourceFirst line of input contains two space separated integer N and D. Second line of input contains N space separated integers denoting the value of the Array.
Constraints:-
1 < = N < = 100000
1 < = Arr[i] < = 100000000
1 < = D < = 10000Print the minimum attack power requires to complete the project within D days.Sample Input:-
3 1
5 10 5
Sample Output:-
5
Explanation:-
1st and 3rd defense will be destroyed immediately then at first day 1st will attack 2nd defense and lowers its defense by 5 and on the same day 3rd defense will also attack the second and destroys it.
Sample Input:-
6 3
2 15 4 2 6 9
Sample Output:-
5
Explanation:-
After launch :- 0 15 0 0 6 9 (1st 3rd and 4th will act as source)
Day 1:- 0 5 0 0 1 9
Day 2:- 0 0 0 0 0 4
Day 3:- 0 0 0 0 0 0, 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 100001
#define MOD 1000000007
#define read(type) readInt<type>()
#define int long long
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int n,d;
int a[max1],pre[max1];
bool check(int A){
int cnt=0;
FOR(i,n){
if(a[i]<=A){cnt++;}
pre[i]=cnt;
}
int ans;
FOR(i,n){
if(a[i]>A){
ans=pre[i];
if(i>d){ans-=pre[i-d-1];}
if(i+d<n){ans+=pre[i+d]-pre[i];}
else{ans+=pre[n-1]-pre[i];}
//out1(A);out(ans);
if(ans*A<a[i]){return false;}
}}
return true;
}
signed main(){
fast();
cin>>n>>d;
FOR(i,n){cin>>a[i];}
int low=1;
int high=10e10+1;
while(low<high){
int mid=low+high;
mid=mid/2;
if(check(mid)==true){high=mid;}
else{
low=mid+1;
}
}
cout<<low<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
String s[]=bu.readLine().split(" ");
long a=Long.parseLong(s[0]),b=Long.parseLong(s[1]);
if(a>=b) sb.append("Chandler");
else sb.append("Joey");
System.out.print(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
template<class C> void mini(C&a4, C b4){a4=min(a4,b4);}
typedef unsigned long long ull;
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define mod 1000000007ll
#define pii pair<int,int>
/////////////
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int a,b;
cin>>a>>b;
if(a>=b)
cout<<"Chandler";
else
cout<<"Joey";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: ch,jo=map(int,input().split())
if ch>=jo:
print('Chandler')
else:
print('Joey'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int[]sort(int n, int a[]){
int i,key;
for(int j=1;j<n;j++){
key=a[j];
i=j-1;
while(i>=0 && a[i]>key){
a[i+1]=a[i];
i=i-1;
}
a[i+1]=key;
}
return a;
}
public static void main (String[] args) throws IOException {
InputStreamReader io = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(io);
int n = Integer.parseInt(br.readLine());
String str = br.readLine();
String stra[] = str.trim().split(" ");
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = Integer.parseInt(stra[i]);
}
a=sort(n,a);
int max=0;
for(int i=0;i<n;i++)
{
if(a[i]+a[n-i-1]>max)
{
max=a[i]+a[n-i-1];
}
}
System.out.println(max);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: n=int(input())
arr=input().split()
for i in range(0,n):
arr[i]=int(arr[i])
arr=sorted(arr,key=int)
start=0
end=n-1
ans=0
while(start<end):
ans=max(ans,arr[end]+arr[start])
start+=1
end-=1
print (ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
sort(a,a+n);
int ma=0;
for(int i=0;i<n;++i){
ma=max(ma,a[i]+a[n-i-1]);
}
cout<<ma;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: // arr is unsorted array
// n is the number of elements in the array
function insertionSort(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 an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void insertionSort(int[] arr){
for(int i = 0; i < arr.length-1; i++){
for(int j = i+1; j < arr.length; j++){
if(arr[i] > arr[j]){
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
}
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while(T > 0){
int n = scan.nextInt();
int arr[] = new int[n];
for(int i = 0; i<n; i++){
arr[i] = scan.nextInt();
}
insertionSort(arr);
for(int i = 0; i<n; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
T--;
System.gc();
}
}
}, 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 positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: def InsertionSort(arr):
arr.sort()
return arr, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<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>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: def MaximumProduct(N):
ans=N//4
if N %4 !=0:
ans=ans+1
return ans, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<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>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<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>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<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>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: static int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code:
int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code: static int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code: int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code:
def DragonSlayer(A,B,C,D):
x = C//B
if(C%B!=0):
x=x+1
y = A//D
if(A%D!=0):
y=y+1
if(x<y):
return 0
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Now let us create a table to store the post created by various users. Create a table POST with the following fields (ID INT, USERNAME VARCHAR(24), POST_TITLE VARCHAR(72), POST_DESCRIPTION TEXT, DATETIME_CREATED DATETIME, NUMBER_OF_LIKES INT, PHOTO BLOB)
( USE ONLY UPPERCASE LETTERS )
<schema>[{'name': 'POST', 'columns': [{'name': 'ID', 'type': 'INT'}, {'name': 'USERNAME', 'type': 'VARCHAR(24)'}, {'name': 'POST_TITLE', 'type': 'VARCHAR (72)'}, {'name': 'POST_DESCRIPTION', 'type': 'TEXT'}, {'name': 'DATETIME_CREATED', 'type': 'TEXT'}, {'name': 'NUMBER_OF_LIKES', 'type': 'INT'}, {'name': 'PHOTO', 'type': 'BLOB'}]}]</schema>nannannan, I have written this Solution Code: CREATE TABLE POST(
ID INT,
USERNAME VARCHAR(24),
POST_TITLE VARCHAR(72),
POST_DESCRIPTION TEXT,
DATETIME_CREATED TEXT,
NUMBER_OF_LIKES INT,
PHOTO BLOB
);, In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty).
Implement the Myqueue class:
void push(int x) Pushes element x to the back of the queue.
int pop() Removes the element from the front of the queue and returns it.
int peek() Returns the element at the front of the queue.
boolean empty() Returns true if the queue is empty, false otherwise.
Note:
You must use only standard operations of a stack, which means only push, peek, size, and is empty operations are valid.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions in class Myqueue.
Push : Takes the element to be pushed at end as parameter.
Pop : Remove the element from front of queue and returns it.
Peek : Returns the front element of queue.
Empty: Return true if the queue is empty.
Expected Time Complexities:
Push: O(Size of Queue)
Pop: O(1)
Peek: O(1)
Empty: O(1)No need to output anything. Just complete the functions.Sample Input 1:-
8
Push 10
Push 5
Push 3
Pop
Pop
Peek
Pop
Empty
Sample Output 1:-
10
5
3
3
YES
Explanation
Initially Queue : {}
Push 10 - > Queue : {10 }
Push 5 -> Queue : {10, 5}
Push 3 -> Queue : {10, 5, 3}
Pop -> Queue : {5 , 3}
Pop -> Queue : {3}
Peek -> 3
Pop -> Queue: {}
Yes it's empty now
Sample Input 2:-
4
Push 3
Pop
Push 5
Empty
Sample Output 2:-
3
NO
Explanation:
Initially Queue : {}
Push 3 -> Queue : {3}
Pop -> Queue: {}
Push 5 -> Queue : {5}
Empty -> NO, I have written this Solution Code: static class Myqueue{
Stack<Integer>s1=new Stack<Integer>();
Stack<Integer>s2=new Stack<Integer>();
public void push(int x) {
while(s1.size()>0){
s2.push(s1.peek());
s1.pop();
}
s1.push(x);
while(s2.size()>0){
s1.push(s2.peek());
s2.pop();
}
}
public int pop() {
return s1.pop();
}
public int peek() {
return s1.peek();
}
public boolean empty() {
if(s1.size()==0)return true;
else return false;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long x;
BigInteger sum = new BigInteger("0");
for(int i=0;i<n;i++){
x=sc.nextLong();
sum= sum.add(BigInteger.valueOf(x));
}
sum=sum.divide(BigInteger.valueOf(n));
System.out.print(sum);
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, 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 n, cur = 0, rem = 0;
cin >> n;
for(int i = 1; i <= n; i++){
int p; cin >> p;
cur += (p + rem)/n;
rem = (p + rem)%n;
}
cout << cur;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, I have written this Solution Code: n = int(input())
a =list
a=list(map(int,input().split()))
sum=0
for i in range (0,n):
sum=sum+a[i]
print(int(sum//n))
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Your task is to implement a stack using a linked list and perform given queries
Note:-if stack is already empty than pop operation will do nothing and 0 will be printed as a top element of stack if it is empty.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>push()</b>:- that takes the integer to be added as a parameter.
<b>pop()</b>:- that takes no parameter.
<b>top()</b> :- that takes no parameter.
Constraints:
1 <= N(number of queries) <= 10<sup>3</sup>You don't need to print anything else other than in top function in which you require to print the top most element of your stack in a new line, if the stack is empty you just need to print 0.Input:
7
push 1
push 2
top
pop
top
pop
top
Output:
2
1
0
, I have written this Solution Code:
Node top = null;
public void push(int x)
{
Node temp = new Node(x);
temp.next = top;
top = temp;
}
public void pop()
{
if (top == null) {
}
else {
top = (top).next;}
}
public void top()
{
// check for stack underflow
if (top == null) {
System.out.println("0");
}
else {
Node temp = top;
System.out.println(temp.val);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a function f(x) = ax<sup>2 </sup> + bx + c. You are given an integer P. Print the value of f(P).The first input line contains three integers a, b, c - the coefficients of the quadratic equations.
The second line contains integer P
Constraints:
0 <= a, b, c, P <= 100Print the value of f(P).Sample Input 1:
1 1 1
1
Output:
3
Explanation:
f(x) = x<sup>2 </sup> + x + 1
f(1) = 1*1 + 1 +1 = 3
Sample Input 2:
1 2 3
7
Output:
66
Explanation:
f(x) = x<sup>2</sup> + 2x + 3
f(7) = 7*7 + 2*7 + 3 = 66, I have written this Solution Code: l=list(map(int,input().strip().split()))
a=l[0]
b=l[1]
c=l[2]
if len(l)<4:
x=int(input())
else:
x=l[3]
f=a*x*x+b*x+c
print(f), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a function f(x) = ax<sup>2 </sup> + bx + c. You are given an integer P. Print the value of f(P).The first input line contains three integers a, b, c - the coefficients of the quadratic equations.
The second line contains integer P
Constraints:
0 <= a, b, c, P <= 100Print the value of f(P).Sample Input 1:
1 1 1
1
Output:
3
Explanation:
f(x) = x<sup>2 </sup> + x + 1
f(1) = 1*1 + 1 +1 = 3
Sample Input 2:
1 2 3
7
Output:
66
Explanation:
f(x) = x<sup>2</sup> + 2x + 3
f(7) = 7*7 + 2*7 + 3 = 66, I have written this Solution Code: /*package whatever //do not write package name here */
import java.io.*;
import java.util.Scanner;
class Main {
public static void main (String[] args) {
int a,b,c,d;
Scanner s = new Scanner(System.in);
a = s.nextInt();
b = s.nextInt();
c = s.nextInt();
d = s.nextInt();
System.out.println(a*d*d + b*d + c);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists.
NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture.
If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only
and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N.
Constraints:
1 ≤ T ≤ 100
2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input:
2
8
3
Sample Output:
3 5
-1, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1073741824
#define read(type) readInt<type>()
#define max1 1000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
bool isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
return power(n, p-2, p);
}
// Returns nCr % p using Fermat's little
// theorem.
ll ncr(ll n, ll r,ll p)
{
// Base case
if (r==0)
return 1;
// Fill factorial array so that we
// can find all factorial of r, n
// and n-r
ll fac[n+1];
fac[0] = 1;
for (ll i=1 ; i<=n; i++)
fac[i] = fac[i-1]*i%p;
return (fac[n]* modInverse(fac[r], p) % p *
modInverse(fac[n-r], p) % p) % p;
}
ll fastexp (ll a, ll b, ll n) {
ll res = 1;
while (b) {
if (b & 1) res = res*a%n;
a = a*a%n;
b >>= 1;
}
return res;
}
bool a[max1];
int main() {
FOR(i,max1){
a[i]=false;}
for(int i=2;i<max1;i++){
if(a[i]==false){
for(int j=i+i;j<max1;j+=i){
a[j]=true;
}
}}
vector<int> v;
map<int,int> m;
for(int i=2;i<max1;i++){
if(a[i]==false){
v.EB(i);
m[i]++;
}
}
int t;
cin>>t;
while(t--){
int n;
cin>>n;
bool win=false;
for(int i=0;i<v.size();i++){
if(m.find(n-v[i])!=m.end()){
if(v[i]>n){break;}
cout<<v[i]<<" "<<n-v[i]<<endl;win=true;break;
}
}
if(win==false){out(-1);}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists.
NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture.
If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only
and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N.
Constraints:
1 ≤ T ≤ 100
2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input:
2
8
3
Sample Output:
3 5
-1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static boolean isPrime(int n)
{
boolean ans=true;
if(n<=1)
{
ans=false;
}
else if(n==2 || n==3)
{
ans=true;
}
else if(n%2==0 || n%3==0)
{
ans=false;
}
else
{
for(int i=5;i*i<=n;i+=6)
{
if(n%i==0 || n%(i+2)==0)
{
ans=false;
break;
}
}
}
return ans;
}
public static void main (String[] args) throws IOException {
BufferedReader scan=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(scan.readLine());
while(t-->0)
{
int n=Integer.parseInt(scan.readLine());
int a=0,b=0;
if(n%2==1)
{
if(isPrime(n-2))
{
a=2;b=n-2;
}
}
else
{
for(int i=2;i<=n/2;i++)
{
if(isPrime(i))
{
if(isPrime(n-i))
{
a=i;b=n-i;
break;
}
}
}
}
if(a!=0 && b!=0)
{
System.out.println(a+" "+b);
}
else
{
System.out.println(-1);
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists.
NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture.
If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only
and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N.
Constraints:
1 ≤ T ≤ 100
2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input:
2
8
3
Sample Output:
3 5
-1, I have written this Solution Code: def isprime(num):
if(num==1 or num==0):
return False
for i in range(2,int(num**0.5)+1):
if(num%i==0):
return False
return True
T = int(input())
for test in range(T):
N = int(input())
value = -1
if(N%2==0):
for i in range(2,int(N/2)+1):
if(isprime(i)):
if(isprime(N-i)):
value = i
break
else:
if(isprime(N-2)):
value = 2
if(value==-1):
print(value)
else:
print(str(value)+" "+str(N-value)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have been given a graph consisting of N nodes and M edges. The nodes in this graph are enumerated from 1 to N . The graph can consist of self-loops as well as multiple edges. This graph consists of a special node called the head node. You need to consider this and the entry point of this graph. You need to find and print the number of nodes that are unreachable from this head node. (Using DFS)The first line consists of a 2 integers N and M denoting the number of nodes and edges in this graph. The next M lines consist of 2 integers a and b denoting an undirected edge between node a and b. The next line consists of a single integer x denoting the index of the head node.
Constraints
1<=N=100000
1<=M<=100000
1<=x<=NYou need to print a single integer denoting the number of nodes that are unreachable from the given head node.
Sample Input:
10 10
8 1
8 3
7 4
7 5
2 6
10 7
2 8
10 9
2 10
5 10
2
Sample Output :
0
Explanation : As from node 2 we can reach all vertices. Unreachable vertices are zero., 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));
ArrayList<ArrayList<Integer>>list=new ArrayList<>();
String str[] = br.readLine().trim().split(" ");
int v = Integer.parseInt(str[0]);
int e = Integer.parseInt(str[1]);
for(int i=0;i<=v;i++)
{
list.add(i,new ArrayList<>());
}
for(int i=0;i<e;i++)
{
String st[] = br.readLine().trim().split(" ");
int s = Integer.parseInt(st[0]);
int d = Integer.parseInt(st[1]);
list.get(s).add(d);
list.get(d).add(s);
}
String stp[] = br.readLine().trim().split(" ");
int head=Integer.parseInt(stp[0]);
boolean visit[]=new boolean[v+1];
for(int i=0;i<=v;i++)
{
visit[i]=false;
}
long count=0;
dfs(list,visit,head);
for(int i=0;i<=v;i++)
{
if(visit[i]==false)
{
count++;
}
}
System.out.println(count-1);
}
static void dfs(ArrayList<ArrayList<Integer>>list,boolean visi[],int k)
{
visi[k]=true;
Iterator<Integer> i = list.get(k).listIterator();
while (i.hasNext())
{
int n = i.next();
if (!visi[n])
dfs(list,visi,n);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have been given a graph consisting of N nodes and M edges. The nodes in this graph are enumerated from 1 to N . The graph can consist of self-loops as well as multiple edges. This graph consists of a special node called the head node. You need to consider this and the entry point of this graph. You need to find and print the number of nodes that are unreachable from this head node. (Using DFS)The first line consists of a 2 integers N and M denoting the number of nodes and edges in this graph. The next M lines consist of 2 integers a and b denoting an undirected edge between node a and b. The next line consists of a single integer x denoting the index of the head node.
Constraints
1<=N=100000
1<=M<=100000
1<=x<=NYou need to print a single integer denoting the number of nodes that are unreachable from the given head node.
Sample Input:
10 10
8 1
8 3
7 4
7 5
2 6
10 7
2 8
10 9
2 10
5 10
2
Sample Output :
0
Explanation : As from node 2 we can reach all vertices. Unreachable vertices are zero., I have written this Solution Code: def dfs(grapg,s):
stack=[]
visited={}
for v in grapg:
visited[v]=0
stack.append(s)
visited[s]=1
while(stack):
s=stack.pop(-1)
if(s in visited):
visited[s]=1
for i in grapg[s]:
if(visited[str(i)]==0):
stack.append(i)
visited[i]=1
count=0
for i in visited:
if(visited[i]==1):
count+=1
return count
dic={}
n,m=input().split()
n=int(n)
m=int(m)
for i in range(0,m):
a,b=input().split()
if(a not in dic):
dic[a]=[b]
else:
dic[a].append(b)
if(b not in dic):
dic[b]=[a]
else:
dic[b].append(a)
s=input()
ans=dfs(dic,s)
print(n-ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have been given a graph consisting of N nodes and M edges. The nodes in this graph are enumerated from 1 to N . The graph can consist of self-loops as well as multiple edges. This graph consists of a special node called the head node. You need to consider this and the entry point of this graph. You need to find and print the number of nodes that are unreachable from this head node. (Using DFS)The first line consists of a 2 integers N and M denoting the number of nodes and edges in this graph. The next M lines consist of 2 integers a and b denoting an undirected edge between node a and b. The next line consists of a single integer x denoting the index of the head node.
Constraints
1<=N=100000
1<=M<=100000
1<=x<=NYou need to print a single integer denoting the number of nodes that are unreachable from the given head node.
Sample Input:
10 10
8 1
8 3
7 4
7 5
2 6
10 7
2 8
10 9
2 10
5 10
2
Sample Output :
0
Explanation : As from node 2 we can reach all vertices. Unreachable vertices are zero., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
int vis[sz];
int cnt=0;
vector<int> NEB[sz];
void dfs(int s)
{
vis[s]=1;
cnt++;
for(auto it:NEB[s])
{
if(vis[it]==0)
{
dfs(it);
}
}
}
signed main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++)
{
int a,b;
cin>>a>>b;
NEB[a].pu(b);
NEB[b].pu(a);
}
int x;
cin>>x;
dfs(x);
cout<<n-cnt;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N consisting of integers. In one move, you can select any element of the array, and either increase or decrease it by one. In other words, in one move you select an index i (1 ≤ i ≤ N) and replace A<sub>i</sub> by either A<sub>i</sub>-1 or A<sub>i</sub>+1.
For example, if A = [1, 4, -2, 0, 1], if you select i = 3 and decide to increase it, after this move A = [1, 4, -1, 0, 1]. Lets say now you select i = 1 and decrease it, after this move A = [0, 4, -1, 0, 1].
You are also given an integer K in the input. Your task is to find the minimum number of moves you must perform, so that there exist two indices i, j, such that 1 ≤ i ≤ j ≤ N and A[i] + A[i+1] +. . A[j-1] + A[j] = K.The first line contains two integers N and K.
The second line contains N space separated integers - A<sub>1</sub>, A<sub>2</sub>,. . A<sub>n</sub>.
<b> Constraints: </b>
1 ≤ N ≤ 50000
-10<sup>9</sup> ≤ K ≤ 10<sup>9</sup>
-10<sup>9</sup> ≤ A[i] ≤ 10<sup>9</sup>Print a single integer denoting the minimum number of moves required.Sample Input 1:
3 4
-2 8 2
Sample Output 1:
2
Sample Explanation 1:
Decrement the 2nd element twice, the array become [-2, 6, 2]. Now the segment [1, 2], i. e, [-2, 6] has sum 4., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main{
public static void main(String[] args)throws IOException
{
StringBuilder out=new StringBuilder();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] s1=br.readLine().split(" ");
int n=Integer.parseInt(s1[0]);
int k=Integer.parseInt(s1[1]);
String[] s=br.readLine().split(" ");
int[] a=new int[n];
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(s[i]);
}
TreeMap<Long,Long>tm=new TreeMap();
tm.put(0L,1L);
long presum=0,mini=Long.MAX_VALUE;
for(int i=0;i<n;i++)
{
presum+=a[i];
long ch=presum-k;
Long f=tm.floorKey(presum-k);
if(f!=null)
{
if(mini>(ch-f))
{
mini=(ch-f);
}
}
Long s2=tm.ceilingKey(presum-k);
if(s2!=null)
{
if(mini>(s2-ch))
{
mini=(s2-ch);
}
}
tm.put(presum,(long)i);
}
out.append(mini+"\n");
System.out.print(out);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N consisting of integers. In one move, you can select any element of the array, and either increase or decrease it by one. In other words, in one move you select an index i (1 ≤ i ≤ N) and replace A<sub>i</sub> by either A<sub>i</sub>-1 or A<sub>i</sub>+1.
For example, if A = [1, 4, -2, 0, 1], if you select i = 3 and decide to increase it, after this move A = [1, 4, -1, 0, 1]. Lets say now you select i = 1 and decrease it, after this move A = [0, 4, -1, 0, 1].
You are also given an integer K in the input. Your task is to find the minimum number of moves you must perform, so that there exist two indices i, j, such that 1 ≤ i ≤ j ≤ N and A[i] + A[i+1] +. . A[j-1] + A[j] = K.The first line contains two integers N and K.
The second line contains N space separated integers - A<sub>1</sub>, A<sub>2</sub>,. . A<sub>n</sub>.
<b> Constraints: </b>
1 ≤ N ≤ 50000
-10<sup>9</sup> ≤ K ≤ 10<sup>9</sup>
-10<sup>9</sup> ≤ A[i] ≤ 10<sup>9</sup>Print a single integer denoting the minimum number of moves required.Sample Input 1:
3 4
-2 8 2
Sample Output 1:
2
Sample Explanation 1:
Decrement the 2nd element twice, the array become [-2, 6, 2]. Now the segment [1, 2], i. e, [-2, 6] has sum 4., I have written this Solution Code:
import sys,math,heapq,bisect
input = sys.stdin.readline
sys.setrecursionlimit(10**5)
ints = lambda : list(map(int,input().split()))
p = 10**9+7
inf = 10**20+7
n,k = ints()
a = ints()
ans = inf
s = 0
store = [0]
for i in range(n):
s += a[i]
x = s-k
ind = bisect.bisect_left(store,x)
if ind!=0:
ans = min(ans,abs(x-store[ind-1]))
if ind!=i+1:
ans = min(ans,abs(x-store[ind]))
bisect.insort(store,s)
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N consisting of integers. In one move, you can select any element of the array, and either increase or decrease it by one. In other words, in one move you select an index i (1 ≤ i ≤ N) and replace A<sub>i</sub> by either A<sub>i</sub>-1 or A<sub>i</sub>+1.
For example, if A = [1, 4, -2, 0, 1], if you select i = 3 and decide to increase it, after this move A = [1, 4, -1, 0, 1]. Lets say now you select i = 1 and decrease it, after this move A = [0, 4, -1, 0, 1].
You are also given an integer K in the input. Your task is to find the minimum number of moves you must perform, so that there exist two indices i, j, such that 1 ≤ i ≤ j ≤ N and A[i] + A[i+1] +. . A[j-1] + A[j] = K.The first line contains two integers N and K.
The second line contains N space separated integers - A<sub>1</sub>, A<sub>2</sub>,. . A<sub>n</sub>.
<b> Constraints: </b>
1 ≤ N ≤ 50000
-10<sup>9</sup> ≤ K ≤ 10<sup>9</sup>
-10<sup>9</sup> ≤ A[i] ≤ 10<sup>9</sup>Print a single integer denoting the minimum number of moves required.Sample Input 1:
3 4
-2 8 2
Sample Output 1:
2
Sample Explanation 1:
Decrement the 2nd element twice, the array become [-2, 6, 2]. Now the segment [1, 2], i. e, [-2, 6] has sum 4., I have written this Solution Code:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename t>
using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
// #pragma gcc optimize("ofast")
// #pragma gcc target("avx,avx2,fma")
#define int long long
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
#define fi first
#define se second
const int mod = 1e9 + 7;
// const int mod=998'244'353;
const long long INF = 2e18 + 10;
// const int INF=1e9+10;
#define readv(x, n) \
vector<int> x(n); \
for (auto &i : x) \
cin >> i;
template <typename t>
using v = vector<t>;
template <typename t>
using vv = vector<vector<t>>;
template <typename t>
using vvv = vector<vector<vector<t>>>;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<vector<int>>>> vvvvi;
typedef vector<vector<double>> vvd;
typedef pair<int, int> pii;
int multiply(int a, int b, int in_mod) { return (int)(1ll * a * b % in_mod); }
int mult_identity(int a) { return 1; }
const double pi = acosl(-1);
auto power(auto a, auto b, const int in_mod)
{
auto prod = mult_identity(a);
auto mult = a % in_mod;
while (b != 0)
{
if (b % 2)
{
prod = multiply(prod, mult, in_mod);
}
if(b/2)
mult = multiply(mult, mult, in_mod);
b /= 2;
}
return prod;
}
auto mod_inv(auto q, const int in_mod)
{
return power(q, in_mod - 2, in_mod);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define stp cout << fixed << setprecision(20);
vector<pair<int,int>> adj;
void solv()
{
int n, k;
cin>>n>>k;
assert(1<=n && n<=50000);
assert(-1e9<=k && k<=1e9);
readv(a,n);
for(int i = 0;i<n;i++)
assert(-1e9<=a[i] && a[i]<=1e9);
set<int> pref_sm;
pref_sm.insert(0);
int sm = 0;
int mn = INF;
for(int i = 0;i<n;i++)
{
sm += a[i];
int needed = sm - k;
auto p = pref_sm.lower_bound(needed);
if(p!=pref_sm.end())
{
int x = *p;
int diff = x - needed;
assert(diff>=0);
mn = min(mn, diff);
}
if(p!=pref_sm.begin())
{
p--;
int x = *p;
int diff = needed - x;
assert(diff>=0);
mn = min(mn, diff);
}
pref_sm.insert(sm);
}
cout<<mn<<endl;
}
void solve()
{
int t = 1;
// cin>>t;
while(t--)
{
solv();
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
#ifdef ONLINE_JUDGE
#ifdef ASC
namespace fs = std::filesystem;
std::string path = "./";
string filename;
for (const auto & entry : fs::directory_iterator(path)){
if( entry.path().extension().string() == ".in"){
filename = entry.path().filename().stem().string();
}
}
if(filename != ""){
string input_file = filename +".in";
string output_file = filename +".out";
if (fopen(input_file.c_str(), "r"))
{
freopen(input_file.c_str(), "r", stdin);
freopen(output_file.c_str(), "w", stdout);
}
}
#endif
#endif
auto clk = clock();
// -------------------------------------Code starts here---------------------------------------------------------------------
signed t = 1;
// cin >> t;
for (signed test = 1; test <= t; test++)
{
// cout<<"Case #"<<test<<": ";
solve();
}
// -------------------------------------Code ends here------------------------------------------------------------------
clk = clock() - clk;
#ifndef ONLINE_JUDGE
// cerr << fixed << setprecision(6) << "\nTime: " << ((float)clk) / CLOCKS_PER_SEC << "\n";
#endif
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, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int m = 100001;
int main(){
int n,k;
cin>>n>>k;
long long a[n],sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]<0){
a[i]=-a[i];
}
}
sort(a,a+n);
for(int i=0;i<k;i++){
sum+=a[n-i-1]*a[n-i-1];
}
cout<<sum;
}
, 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, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
String[] NK = br.readLine().split(" ");
String[] inputs = br.readLine().split(" ");
int N = Integer.parseInt(NK[0]);
int K = Integer.parseInt(NK[1]);
long[] arr = new long[N];
long answer = 0;
for(int i = 0; i < N; i++){
arr[i] = Math.abs(Long.parseLong(inputs[i]));
}
quicksort(arr, 0, N-1);
for(int i = (N-K); i < N;i++){
answer += (arr[i]*arr[i]);
}
System.out.println(answer);
}
static void quicksort(long[] arr, int start, int end){
if(start < end){
int pivot = partition(arr, start, end);
quicksort(arr, start, pivot-1);
quicksort(arr, pivot+1, end);
}
}
static int partition(long[] arr, int start, int end){
long pivot = arr[end];
int i = start - 1;
for(int j = start; j < end; j++){
if(arr[j] < pivot){
i++;
swap(arr, i, j);
}
}
swap(arr, i+1, end);
return (i+1);
}
static void swap(long[] arr, int i, int j){
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}, 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, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: x,y = map(int,input().split())
arr = list(map(int,input().split()))
s=0
for i in range(x):
if arr[i]<0:
arr[i]=abs(arr[i])
arr=sorted(arr,reverse=True)
for i in range(0,y):
s = s+arr[i]*arr[i]
print(s)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.