Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code: def EqualOrNot(h1,h2,v1,v2):
if (v2>v1 and (h1-h2)%(v2-v1)==0):
return True
else:
return False
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code: static boolean EqualOrNot(int h1, int h2, int v1,int v2){
if (v2>v1&&(h1-h2)%(v2-v1)==0){
return true;
}
return false;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is class of students. Their teacher is taking their attendance in the morning as usual. But this time, the list of students in the register feels weird. There are suddenly more names there. Apparently a few mischevious students have repeated their names in the register. Find the number of these mischevious students who have multiple names in the register.The first line of the input contains a single integer N - the number of names in the register.
The next N lines of the input each contains a string.
Constraints:
1 <= N <= 10<sup>4</sup>
1 <= |S<sub>i</sub>| <= 100Find the number of mischevious students who have multiple names in the register.Sample Input:
5
Newton
Einstein
Newton
Bohr
Einstein
Sample Output:
2
Explaination:
Only two students have repeated names in the register., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
HashMap<String, Integer> hm = new HashMap<>();
for(int i=0; i<n; i++){
s = br.readLine().split(" ");
if(hm.containsKey(s[0])){
hm.put(s[0],hm.get(s[0])+1);
}else{
hm.put(s[0],1);
}
}
int count=0;
for(Integer val:hm.values()){
if(val>1){
count++;
}
}
System.out.print(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is class of students. Their teacher is taking their attendance in the morning as usual. But this time, the list of students in the register feels weird. There are suddenly more names there. Apparently a few mischevious students have repeated their names in the register. Find the number of these mischevious students who have multiple names in the register.The first line of the input contains a single integer N - the number of names in the register.
The next N lines of the input each contains a string.
Constraints:
1 <= N <= 10<sup>4</sup>
1 <= |S<sub>i</sub>| <= 100Find the number of mischevious students who have multiple names in the register.Sample Input:
5
Newton
Einstein
Newton
Bohr
Einstein
Sample Output:
2
Explaination:
Only two students have repeated names in the register., I have written this Solution Code: dicti = {}
numOfInput = int(input())
namesList = []
for _ in range(numOfInput):
st = input()
namesList.append(st);
for name in namesList:
if name not in dicti.keys():
dicti[name] = 1
else:
dicti[name] += 1
ans = 0
for count in dicti.values():
if count > 1:
ans += 1
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is class of students. Their teacher is taking their attendance in the morning as usual. But this time, the list of students in the register feels weird. There are suddenly more names there. Apparently a few mischevious students have repeated their names in the register. Find the number of these mischevious students who have multiple names in the register.The first line of the input contains a single integer N - the number of names in the register.
The next N lines of the input each contains a string.
Constraints:
1 <= N <= 10<sup>4</sup>
1 <= |S<sub>i</sub>| <= 100Find the number of mischevious students who have multiple names in the register.Sample Input:
5
Newton
Einstein
Newton
Bohr
Einstein
Sample Output:
2
Explaination:
Only two students have repeated names in the register., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin >> n;
vector<string> a(n);
map<string, int> mp;
set<string> s;
for(auto &i : a) cin >> i;
for(auto &i : a){
if(mp[i] > 0){
s.insert(i);
}
mp[i]++;
}
cout << s.size();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader(){
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1){
if (c == '\n')break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)c = read();
do{
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)return -ret;return ret;
}
public long nextLong() throws IOException{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.'){
while ((c = read()) >= '0' && c <= '9'){
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)buffer[0] = -1;
}
private byte read() throws IOException{
if (bufferPointer == bytesRead)fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException{
if (din == null)return;
din.close();
}
}
public static void main (String[] args) throws IOException{
Reader sc = new Reader();
int m = sc.nextInt();
int n = sc.nextInt();
int[][] arr = new int[m][n];
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
arr[i][j] = sc.nextInt();
}
}
int max_row_index = 0;
int j = n - 1;
for (int i = 0; i < m; i++) {
while (j >= 0 && arr[i][j] == 1) {
j = j - 1;
max_row_index = i;
}
}
System.out.println(max_row_index);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code: r, c = list(map(int, input().split()))
max_count = 0
max_r = 0
for i in range(r):
count = input().count("1")
if count > max_count:
max_count = count
max_r = i
print(max_r), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int a[max1][max1];
signed main()
{
int n,m;
cin>>n>>m;
FOR(i,n){
FOR(j,m){cin>>a[i][j];}}
int cnt=0;
int ans=0;
int res=0;
FOR(i,n){
cnt=0;
FOR(j,m){
if(a[i][j]==1){
cnt++;
}}
if(cnt>res){
res=cnt;
ans=i;
}
}
out(ans);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code: // mat is the matrix/ 2d array
// n,m are dimensions
function max1Row(mat, n, m) {
// write code here
// do not console.log
// return the answer as a number
let j, max_row_index = 0;
j = m - 1;
for (let i = 0; i < n; i++)
{
// Move left until a 0 is found
let flag = false;
// to check whether a row has more 1's than previous
while (j >= 0 && mat[i][j] == 1)
{
j = j - 1; // Update the index of leftmost 1
// seen so far
flag = true;//present row has more 1's than previous
}
// if the present row has more 1's than previous
if (flag)
{
max_row_index = i; // Update max_row_index
}
}
if (max_row_index == 0 && mat[0][m - 1] == 0)
return -1;
return max_row_index;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of positive element having size N and an integer C. Check if there exists a pair (A,B) such that A xor B = C.First line of input contains number of testcases T.
The First line of each testcase contains two integers N and C.
The 2nd line of each testcase, contains N space separated integers denoting the elements of the array A.
Constraints:
1 <= T <= 50
1 <= N <= 10000
1 <= C <= 10000
0 <= arr[i] <= 10000Print "Yes" is the pair exists else print "No" without quotes.(Change line after every answer).Input:
2
7 7
2 1 10 3 4 9 5
5 1
9 9 10 10 3
Output:
Yes
No
Explanation :
In first case, pair (2,5) give 7. Hence answer is "Yes". In second case no pair exist such that satisfies the condition hance the answer is "No"., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t>0){
boolean flag = false;
int n = sc.nextInt();
int c = sc.nextInt();
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++){
int num = sc.nextInt();
int required_num = c^num;
if (map.containsKey(required_num)){
System.out.println("Yes");
sc.nextLine();
flag = true;
break;
}
map.put(num, i);
}
if (flag == false){
System.out.println("No");
}
t--;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of positive element having size N and an integer C. Check if there exists a pair (A,B) such that A xor B = C.First line of input contains number of testcases T.
The First line of each testcase contains two integers N and C.
The 2nd line of each testcase, contains N space separated integers denoting the elements of the array A.
Constraints:
1 <= T <= 50
1 <= N <= 10000
1 <= C <= 10000
0 <= arr[i] <= 10000Print "Yes" is the pair exists else print "No" without quotes.(Change line after every answer).Input:
2
7 7
2 1 10 3 4 9 5
5 1
9 9 10 10 3
Output:
Yes
No
Explanation :
In first case, pair (2,5) give 7. Hence answer is "Yes". In second case no pair exist such that satisfies the condition hance the answer is "No"., I have written this Solution Code: def xorPair(N,C,array):
from itertools import combinations
for i in combinations(array,r=2):
if i[0]^i[1]==C :
return "Yes"
return "No"
test_case = int(input())
while test_case>0:
N,C = list(map(int,input().split()))
print(xorPair(N,C,list(map(int,input().split()))))
test_case -=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of positive element having size N and an integer C. Check if there exists a pair (A,B) such that A xor B = C.First line of input contains number of testcases T.
The First line of each testcase contains two integers N and C.
The 2nd line of each testcase, contains N space separated integers denoting the elements of the array A.
Constraints:
1 <= T <= 50
1 <= N <= 10000
1 <= C <= 10000
0 <= arr[i] <= 10000Print "Yes" is the pair exists else print "No" without quotes.(Change line after every answer).Input:
2
7 7
2 1 10 3 4 9 5
5 1
9 9 10 10 3
Output:
Yes
No
Explanation :
In first case, pair (2,5) give 7. Hence answer is "Yes". In second case no pair exist such that satisfies the condition hance the answer is "No"., 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
signed main()
{
int t;
cin>>t;
while(t>0)
{
t--;
int n,C;
cin>>n>>C;
set<int> ss;
int ch=0;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
int p=a^C;
if(ss.find(p)!=ss.end()) ch=1;
ss.insert(a);
}
if(ch==1) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, 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--){
vector<int> v;
int n, x; cin >> n >> x;
for(int i = 1; i <= n; i++){
int p; cin >> p;
if(p == x)
v.push_back(i-1);
}
if(v.size() == 0)
cout << "Not found\n";
else{
for(auto i: v)
cout << 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 integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, I have written this Solution Code: def position(n,arr,x):
res = []
cnt = 0
for i in arr:
if(i == x):
res.append(cnt)
cnt += 1
return res
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main (String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t =Integer.parseInt(read.readLine());
while(t-- > 0)
{
String str[] = read.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
int x = Integer.parseInt(str[1]);
int arr[] = new int[n];
str = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
findPositions(arr, n, x);
}
}
static void findPositions(int arr[], int n, int x)
{
boolean flag = false;
StringBuffer sb = new StringBuffer();
for(int i = 0; i < n; i++)
{
if(arr[i] == x)
{
sb.append(i + " ");
flag = true;
}
}
if(flag ==true)
System.out.println(sb.toString());
else System.out.println("Not found");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: function easySorting(arr)
{
for(let i = 1; i < 5; i++)
{
let str = arr[i];
let j = i-1;
while(j >= 0 && (arr[j].toString().localeCompare(str)) > 0 )
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = str;
}
return arr;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
map<string,int> m;
string s;
for(int i=0;i<5;i++){
cin>>s;
m[s]++;
}
for(auto it=m.begin();it!=m.end();it++){
while(it->second>0){
cout<<it->first<<" ";
it->second--;}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: inp = input("").split(" ")
print(" ".join(sorted(inp))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static void printArray(String str[])
{
for (String string : str)
System.out.print(string + " ");
}
public static void main (String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
int len = 5;
String[] str = new String[len];
str = br.readLine().split(" ");
Arrays.sort(str, String.CASE_INSENSITIVE_ORDER);
printArray(str);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alongside acting as his personal assistant F. R. I. D. A. Y also manages the Avengers Tower. With all the heroes of the universe arriving at the place it becomes quite messy to cater to the needs of all the guests. Assuming every super hero arrives by a train, how many platforms are needed on the Avengers tower to ensure no train gets delayed. Given arrival and departure times of all trains that reach Avengers Tower. Consider that all the trains arrive on the same day and leave on the same day. Arrival and departure time can never be the same for a train but we can have the arrival time of one train equal to the departure time of the other. At any given instance of time, the same platform cannot be used for both departure of a train and arrival of another train. In such cases, we need different platforms.The first line of input has the number of visitors.
It is followed by the entry of two books in the form of two arrays.
It is not mentioned which Array contains entry time and which has exit time but it is sure all entry time is in one array and all exit time is in other array.
eg: 9:00 is written as 900.
if ab:cd is the time then it will be written as ab*100 + cd.
Constraints:-
1 ≤ n ≤ 10000The output contains a single Line the minimum number of platforms needed.Sample Input:-
6
900 940 950 1100 1500 1800
910 1200 1120 1130 1900 2000
Sample Output:-
3
Sample Input:-
3
0900 1235 1100
1000 1200 1240
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int differentPlatforms(int arrivalTime[], int departureTime[], int visitors) {
Arrays.sort(arrivalTime);
Arrays.sort(departureTime);
int platformNeeded = 1, result = 1;
int i = 1, j = 0;
while (i < visitors && j < visitors) {
if (arrivalTime[i] <= departureTime[j]) {
platformNeeded++;
i++;
}
else if (arrivalTime[i] > departureTime[j]) {
platformNeeded--;
j++;
}
if (platformNeeded > result)
result = platformNeeded;
}
return result;
}
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
int visitors = input.nextInt();
int[] arrivalTime = new int[visitors];
int[] departureTime = new int[visitors];
for(int i = 0; i < visitors; i++) {
arrivalTime[i] = input.nextInt();
}
for(int i = 0; i < visitors; i++) {
departureTime[i] = input.nextInt();
}
if(arrivalTime[0]<departureTime[0]){
System.out.print(differentPlatforms(arrivalTime, departureTime, visitors));
}else{
System.out.print(differentPlatforms(departureTime, arrivalTime, visitors));
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alongside acting as his personal assistant F. R. I. D. A. Y also manages the Avengers Tower. With all the heroes of the universe arriving at the place it becomes quite messy to cater to the needs of all the guests. Assuming every super hero arrives by a train, how many platforms are needed on the Avengers tower to ensure no train gets delayed. Given arrival and departure times of all trains that reach Avengers Tower. Consider that all the trains arrive on the same day and leave on the same day. Arrival and departure time can never be the same for a train but we can have the arrival time of one train equal to the departure time of the other. At any given instance of time, the same platform cannot be used for both departure of a train and arrival of another train. In such cases, we need different platforms.The first line of input has the number of visitors.
It is followed by the entry of two books in the form of two arrays.
It is not mentioned which Array contains entry time and which has exit time but it is sure all entry time is in one array and all exit time is in other array.
eg: 9:00 is written as 900.
if ab:cd is the time then it will be written as ab*100 + cd.
Constraints:-
1 ≤ n ≤ 10000The output contains a single Line the minimum number of platforms needed.Sample Input:-
6
900 940 950 1100 1500 1800
910 1200 1120 1130 1900 2000
Sample Output:-
3
Sample Input:-
3
0900 1235 1100
1000 1200 1240
Sample Output:-
1, I have written this Solution Code: #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define all(v) (v).begin(), (v).end()
const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 9;
inline ll add(ll a, ll b, ll m)
{
if ((a + b) >= m)
return (a + b) % m;
return a + b;
}
inline ll mul(ll a, ll b, ll m)
{
if ((a * b) < m)
return a * b;
return (a * b) % m;
}
ll power(ll x, ll y, ll m)
{
ll res = 1;
x = x % m;
if (x == 0)
return 0;
while (y > 0)
{
if (y & 1)
res = (res * x) % m;
y = y >> 1;
x = (x * x) % m;
}
return res;
}
void solve()
{
int n;
cin>>n;
vi a(n),b(n);
for(int i=0;i<n;i++) {
cin>>a[i];
}
for(int i=0;i<n;i++) {
cin>>b[i];
}
if(a[0]>b[0]) swap(a,b);
vi c(2500,0);
for(int i=0;i<n;i++) {
c[a[i]]++;
c[b[i]+1]--;
}
int ans = c[0];
for(int i=1;i<2500;i++) {
c[i]+=c[i-1];
ans = max(ans,c[i]);
}
cout<<ans;
}
int main()
{
fastio;
int t;
t = 1;
//cin >> t;
//int test=t;
while (t-- > 0)
{
//cout<<"Case #"<<(test-t)<<": ";
solve();
cout << newl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers N and M, your task is to print the number of primes present between N and M (both included).
<b>Note</b>:- You have already provided a function that will check if the given number is prime or not. To use the given function you need to call <b>check_prime(x)</b> where x is the number you want to check. If the given number is prime the function will return 1 else it returns 0.
<b>Note</b>:- Do not close your main class.The input contains two space- separated integers depicting the values of N and M.
Constraints:-
1 <= N <= M <= 10000Print the count of prime numbers in the given range.Sample Input:-
1 10
Sample Output:-
4
Sample Input:-
8 10
Sample Output:-
0, I have written this Solution Code: from math import sqrt
def isPrime(n):
if (n <= 1):
return False
for i in range(2, int(sqrt(n))+1):
if (n % i == 0):
return False
return True
x=input().split()
n=int(x[0])
m=int(x[1])
count = 0
for i in range(n,m):
if isPrime(i):
count = count +1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers N and M, your task is to print the number of primes present between N and M (both included).
<b>Note</b>:- You have already provided a function that will check if the given number is prime or not. To use the given function you need to call <b>check_prime(x)</b> where x is the number you want to check. If the given number is prime the function will return 1 else it returns 0.
<b>Note</b>:- Do not close your main class.The input contains two space- separated integers depicting the values of N and M.
Constraints:-
1 <= N <= M <= 10000Print the count of prime numbers in the given range.Sample Input:-
1 10
Sample Output:-
4
Sample Input:-
8 10
Sample Output:-
0, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int m = sc.nextInt();
int cnt=0;
for(int i=n;i<=m;i++){
if(check_prime(i)==1){cnt++;}
}
System.out.println(cnt);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array A of size N and value K. The elements of the array A contains positive integers. You have to print all the elements which are greater than K in the array in sorted order (including K as well if present in the array A), and print all the elements which are smaller than K in sorted order both of them in separate lines. If the elements greater than or equal to K are not present in the array then print "-1". Similarly, in the case of smaller elements print -1 if elements smaller than K doesn’t exist. If a number appears more than once print number more than once.First line of input contains number of testcases T. For each testcase, there are two lines, first of which contains N and K separated by space, next line contains N space separated integers.
Constraints:
1 <= T <= 100
1 <= N <= 100000
1 <= K <= 1000000
1 <= A[i] <= 1000000
Sum of N over all test cases do not exceed 100000For each testcase, print the required elements(if any), else print "-1" (without quotes)Input:
1
5 1
2 1 5 7 6
Output:
1 2 5 6 7
-1
Explanation:
Testcase 1 : Since, 1, 2, 5, 6, 7 are greater or equal to given K. Also, no element less than K is present in the array., I have written this Solution Code: import java.io.*;
import java.util.*;
class Reader{
BufferedReader reader;
Reader(){
this.reader = new BufferedReader(new InputStreamReader(System.in));
}
public String read() throws IOException {
return reader.readLine();
}
public int readInt() throws IOException {
return Integer.parseInt(reader.readLine());
}
public long readLong() throws IOException {
return Long.parseLong(reader.readLine());
}
public String[] readArray() throws IOException {
return reader.readLine().split(" ");
}
public int[] readIntegerArray() throws IOException {
String[] str = reader.readLine().split(" ");
int[] arr = new int[str.length];
for(int i=0;i<str.length;i++) arr[i] = Integer.parseInt(str[i]);
return arr;
}
public long[] readLongArray() throws IOException {
String[] str = reader.readLine().split(" ");
long[] arr = new long[str.length];
for(int i=0;i<str.length;i++) arr[i] = Long.parseLong(str[i]);
return arr;
}
}
public class Main {
public static void main(String[] args) throws IOException {
Reader rdr = new Reader();
int t = rdr.readInt();
while(t-- > 0){
int[] str = rdr.readIntegerArray();
int n = str[0];
int k = str[1];
int[] arr = rdr.readIntegerArray();
Arrays.sort(arr);
int c=0;
for(int i=0;i<n;i++){
if(arr[i]>=k){
System.out.print(arr[i]+" ");
c++;
}
}
if(c==0) System.out.print(-1);
System.out.println();
if(c==n) System.out.print(-1);
else for(int i=0;i<n-c;i++) System.out.print(arr[i]+" ");
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array A of size N and value K. The elements of the array A contains positive integers. You have to print all the elements which are greater than K in the array in sorted order (including K as well if present in the array A), and print all the elements which are smaller than K in sorted order both of them in separate lines. If the elements greater than or equal to K are not present in the array then print "-1". Similarly, in the case of smaller elements print -1 if elements smaller than K doesn’t exist. If a number appears more than once print number more than once.First line of input contains number of testcases T. For each testcase, there are two lines, first of which contains N and K separated by space, next line contains N space separated integers.
Constraints:
1 <= T <= 100
1 <= N <= 100000
1 <= K <= 1000000
1 <= A[i] <= 1000000
Sum of N over all test cases do not exceed 100000For each testcase, print the required elements(if any), else print "-1" (without quotes)Input:
1
5 1
2 1 5 7 6
Output:
1 2 5 6 7
-1
Explanation:
Testcase 1 : Since, 1, 2, 5, 6, 7 are greater or equal to given K. Also, no element less than K is present in the array., I have written this Solution Code: t=int(input())
while t>0:
a=input().split()
b=input().split()
for i in range(len(b)):
b[i]=int(b[i])
lesser=[]
greater=[]
for i in b:
if i>=int(a[1]):
greater.append(i)
else:
lesser.append(i)
if len(greater)==0:
print(-1,end="")
else:
greater.sort()
for x in greater:
print(x,end=" ")
print()
if len(lesser)==0:
print(-1,end="")
else:
lesser.sort()
for y in lesser:
print(y,end=" ")
print()
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array A of size N and value K. The elements of the array A contains positive integers. You have to print all the elements which are greater than K in the array in sorted order (including K as well if present in the array A), and print all the elements which are smaller than K in sorted order both of them in separate lines. If the elements greater than or equal to K are not present in the array then print "-1". Similarly, in the case of smaller elements print -1 if elements smaller than K doesn’t exist. If a number appears more than once print number more than once.First line of input contains number of testcases T. For each testcase, there are two lines, first of which contains N and K separated by space, next line contains N space separated integers.
Constraints:
1 <= T <= 100
1 <= N <= 100000
1 <= K <= 1000000
1 <= A[i] <= 1000000
Sum of N over all test cases do not exceed 100000For each testcase, print the required elements(if any), else print "-1" (without quotes)Input:
1
5 1
2 1 5 7 6
Output:
1 2 5 6 7
-1
Explanation:
Testcase 1 : Since, 1, 2, 5, 6, 7 are greater or equal to given K. Also, no element less than K is present in the array., 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
signed main()
{
int t;
cin>>t;
while(t>0)
{
t--;
int n,k;
cin>>n>>k;
vector<int> A,B;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
if(a<k) B.pu(a);
else A.pu(a);
}
sort(all(A));
sort(all(B));
for(auto it:A)
{
cout<<it<<" ";
}if(A.size()==0) cout<<-1;
cout<<endl;
for(auto it:B)
{
cout<<it<<" ";
}if(B.size()==0) cout<<-1;
cout<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alexa is meeting up with Bob. They have planned to meet at a place that is D meters away from Alexa's house in T minutes from now. Alexa will leave her house now and go straight to the place at a speed of
S meters per minute. Will she arrive in time?The input consists of three space separated integers.
D T S
<b>Constraints</b>
1 ≤ D ≤ 10000
1 ≤ T ≤ 10000
1 ≤ S ≤10000
All values in input are integers.If Alexa will reach the place in time, print Yes; otherwise, print No.<b>Sample Input 1</b>
1000 15 80
<b>Sample Output 1</b>
Yes
<b>Sample Input 2</b>
2000 20 100
<b>Sample Output 2</b>
Yes
<b>Sample Input 3</b>
10000 1 1
<b>Sample Output 3</b>
No, I have written this Solution Code: #include <iostream>
using namespace std;
int main() {
//Recieve the inputs
int D, T, S;
cin >> D >> T >> S;
//Calculate the duration of Takahashi's journey
double time = (double)D / S;
//Output depending on the inequality between T and time
if (T >= time) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int len = Integer.parseInt(br.readLine());
char[] str = new char[len];
for(int i = 0; i < len; i++){
if(i%2 == 0){
str[i] = 'a';
} else{
str[i] = 'b';
}
}
System.out.println(str);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
#define rep(i,n) for (int i=0; i<(n); i++)
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
string s(n,'a');
for(int i=1;i<n;i+=2)
s[i]='b';
cout<<s;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: a="ab"
inp = int(input())
print(a*(inp//2)+a[0:inp%2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You need to make an order counter to keep track of the total number of orders received.
Complete the function <code> generateOrder() </code> which returns a <code>function func()</code>. This function <code>func</code> should maintain a <code> count (initially 0)</code>. Every time <code>func</code> is called, <code> count</code> must be incremented by 1 and the string <code>"Total orders = " + count</code> must be returned.
<b>Note:</b> The function generateOrder() will be called internally. You do not need to call it yourself. The generateOrder() takes no argument. It is called internally.The generateOrder() function returns a function that returns the string <code>"Total orders = " + count</code>, where <code>count</code> is the number of times the function is called.
const initC = generateOrder(starting);
console.log(initC()) //prints "Total orders = 1"
console.log(initC()) //prints "Total orders = 2"
console.log(initC()) //prints "Total orders = 3"
, I have written this Solution Code: let generateOrder = function() {
let prefix = "Total orders = ";
let count = 0;
let totalOrders = function(){
count++
return prefix + count;
}
return totalOrders;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number where n! = n * n-1 * n-2 .....* 1First line consists of a single integer denoting n
Constraints:-
0 <= n <= 20Output is a single line containing factorial(n)Sample Input
5
Sample Output
120
Explanation:-
5!= 5 * 4 * 3 * 2 * 1 = 120
Sample Input
10
Sample Output
3628800, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
long fact=1;
for(int i=1; i<=n;i++){
fact*=i;
}
System.out.print(fact);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number where n! = n * n-1 * n-2 .....* 1First line consists of a single integer denoting n
Constraints:-
0 <= n <= 20Output is a single line containing factorial(n)Sample Input
5
Sample Output
120
Explanation:-
5!= 5 * 4 * 3 * 2 * 1 = 120
Sample Input
10
Sample Output
3628800, I have written this Solution Code: def fact(n):
if( n==0 or n==1):
return 1
return n*fact(n-1);
n=int(input())
print(fact(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number where n! = n * n-1 * n-2 .....* 1First line consists of a single integer denoting n
Constraints:-
0 <= n <= 20Output is a single line containing factorial(n)Sample Input
5
Sample Output
120
Explanation:-
5!= 5 * 4 * 3 * 2 * 1 = 120
Sample Input
10
Sample Output
3628800, I have written this Solution Code: #include <bits/stdc++.h>
// #define ll long long
using namespace std;
int main(){
int t;
t=1;
while(t--){
int n;
cin>>n;
unsigned long long sum=1;
for(int i=1;i<=n;i++){
sum*=i;
}
cout<<sum<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Let’s say Linkedin decides to rename the column photo in table `photo` to post_image. How would you update the column name using alter table?
<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': 'datetime'}, {'name': 'number_of_likes', 'type': 'int'}, {'name': 'photo', 'type': 'blob'}]}]</schema>nannannan, I have written this Solution Code: ALTER TABLE post
RENAME COLUMN photo to post_image;
, In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] with N elements, your task is to sort it using counting sort algorithm.The first line of the input contains the number of test cases T. For each test case, the first line contains the number of elements N in the array A and the next line will contain the N elements (space separated) of A[].
Constraints:
1 <= T <= 12
1 <= N <= 100
1 <= A[] <= 100000
For each test case in a new line, you need to print the sorted array using counting sort.Sample Input:
3
4
8 1 3 7
3
1 3 7
6
6 1 3 7 4 9
Sample Output:
1 3 8 7
1 3 7
1 3 4 6 7 9, I have written this Solution Code: t = int(input())
for _ in range(t):
n = int(input())
print(*(sorted(list(map(int,input().split()))))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] with N elements, your task is to sort it using counting sort algorithm.The first line of the input contains the number of test cases T. For each test case, the first line contains the number of elements N in the array A and the next line will contain the N elements (space separated) of A[].
Constraints:
1 <= T <= 12
1 <= N <= 100
1 <= A[] <= 100000
For each test case in a new line, you need to print the sorted array using counting sort.Sample Input:
3
4
8 1 3 7
3
1 3 7
6
6 1 3 7 4 9
Sample Output:
1 3 8 7
1 3 7
1 3 4 6 7 9, 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());
for(int i=0;i<t;i++){
int n=Integer.parseInt(br.readLine());
int[] ar=new int[n];
String[] i1=br.readLine().split(" ");
for(int j=0;j<n;j++){
ar[j]=Integer.parseInt(i1[j]);
}
Arrays.sort(ar);
for(int y:ar){
System.out.print(y+" ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] with N elements, your task is to sort it using counting sort algorithm.The first line of the input contains the number of test cases T. For each test case, the first line contains the number of elements N in the array A and the next line will contain the N elements (space separated) of A[].
Constraints:
1 <= T <= 12
1 <= N <= 100
1 <= A[] <= 100000
For each test case in a new line, you need to print the sorted array using counting sort.Sample Input:
3
4
8 1 3 7
3
1 3 7
6
6 1 3 7 4 9
Sample Output:
1 3 8 7
1 3 7
1 3 4 6 7 9, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];}
sort(a,a+n);
for(int i=0;i<n;i++){
cout<<a[i]<<" ";}
cout<<endl;}}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given N flags, initially set to 0. Now you have to perform two operations on them:
1. Increase(F) by 1: flag F is increased by 1.
2. max_flag: all flags are set to a maximum value of any flag.
A non-empty array arr[] will be given of size M. This array represents consecutive operations:
a) If arr[K] = F, such that 1 <= F <= N then operation K is Increase(F).
b) If arr[K] = N+1 then operation K is max_flag.
The goal is to calculate the value of every flag after all operations.The input line contains T, denoting the number of test cases.
Each test case contains two lines.
The first line contains an integer N, the number of flags, and an integer M, the size of the array 'arr'.The second line contains elements of the array 'arr' separated by space.
<b>Constraints:</b>
1 <= T <= 100
1 <= N, M <= 10^5
1 <= arr[i] <= N+1
Sum of N and M for each test case is less than or equal to 10^5For each testcase you need to print the updated array after all operations in new line.Sample Input:
1
5 7
3 4 4 6 1 4 4
Sample Output:
3 2 2 4 2
<b>Explanation:</b>
Testcase 1:
the values of the flags after each consecutive operation will be:
(0, 0, 1, 0, 0)
(0, 0, 1, 1, 0)
(0, 0, 1, 2, 0)
(2, 2, 2, 2, 2)
(3, 2, 2, 2, 2)
(3, 2, 2, 3, 2)
(3, 2, 2, 4, 2), I have written this Solution Code: t=int(input())
while t>0:
t-=1
n,m=map(int,input().split())
a=map(int,input().split())
b=[0]*(n+1)
for i in a:
if i==n+1:
v=max(b)
for i in range(1,n+1):
b[i]=v
else:b[i]+=1
for i in range(1,n+1):
print(b[i],end=' ')
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given N flags, initially set to 0. Now you have to perform two operations on them:
1. Increase(F) by 1: flag F is increased by 1.
2. max_flag: all flags are set to a maximum value of any flag.
A non-empty array arr[] will be given of size M. This array represents consecutive operations:
a) If arr[K] = F, such that 1 <= F <= N then operation K is Increase(F).
b) If arr[K] = N+1 then operation K is max_flag.
The goal is to calculate the value of every flag after all operations.The input line contains T, denoting the number of test cases.
Each test case contains two lines.
The first line contains an integer N, the number of flags, and an integer M, the size of the array 'arr'.The second line contains elements of the array 'arr' separated by space.
<b>Constraints:</b>
1 <= T <= 100
1 <= N, M <= 10^5
1 <= arr[i] <= N+1
Sum of N and M for each test case is less than or equal to 10^5For each testcase you need to print the updated array after all operations in new line.Sample Input:
1
5 7
3 4 4 6 1 4 4
Sample Output:
3 2 2 4 2
<b>Explanation:</b>
Testcase 1:
the values of the flags after each consecutive operation will be:
(0, 0, 1, 0, 0)
(0, 0, 1, 1, 0)
(0, 0, 1, 2, 0)
(2, 2, 2, 2, 2)
(3, 2, 2, 2, 2)
(3, 2, 2, 3, 2)
(3, 2, 2, 4, 2), I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
memset(a, 0, sizeof a);
int n, m;
cin >> n >> m;
int mx = 0, flag = 0;
for(int i = 1; i <= m; i++){
int p; cin >> p;
if(p == n+1){
flag = mx;
}
else{
a[p] = max(a[p], flag) + 1;
mx = max(mx, a[p]);
}
}
for(int i = 1; i <= n; i++){
a[i] = max(a[i], flag);
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: A permutation is simply a name for a reordering. So the permutations of the string
‘abc’ are ‘abc’, ‘acb’, ‘bac’, ‘bca’, ‘cab’, and ‘cba’. Note that a sequence is a
permutation of itself (the trivial permutation). For this problem, you’ll need
to write a recursive function that takes a string and returns a
list of all its permutations.
A couple of notes on the requirements:
1. The order of the returned permutations must be lexicographically.
2. Avoid returning duplicates in your final list.Input contains a single string S.
Constraints:-
1<=|S|<=8Print all the permutations of string S in lexicographical order.Sample Input:
ABC
Sample Output :
ABC ACB BAC BCA CAB CBA
Explanation:
all permutation are arranged in lexicographical order .
Sample Input:
(T(
Sample Output:-
((T (T( T((, I have written this Solution Code: def sol(arr):
dict = {}
for i in arr:
if i in dict.keys():
dict[i] = dict[i] + 1
else:
dict[i] = 1
keys = sorted(dict)
str = []
c = []
s=0
for key in keys:
str.append(key)
c.append(dict[key])
total = [0]*len(arr)
sol2(str, c, total, s)
def sol2(str, c, total, s):
if s == len(total):
str1=''
k=str1.join(total)
print(k,end=' ')
return
for i in range(len(str)):
if c[i] == 0:
continue
total[s] = str[i]
c[i] -= 1
sol2(str, c, total, s + 1)
c[i] += 1
str2=input()
n = list(str2)
sol(n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A permutation is simply a name for a reordering. So the permutations of the string
‘abc’ are ‘abc’, ‘acb’, ‘bac’, ‘bca’, ‘cab’, and ‘cba’. Note that a sequence is a
permutation of itself (the trivial permutation). For this problem, you’ll need
to write a recursive function that takes a string and returns a
list of all its permutations.
A couple of notes on the requirements:
1. The order of the returned permutations must be lexicographically.
2. Avoid returning duplicates in your final list.Input contains a single string S.
Constraints:-
1<=|S|<=8Print all the permutations of string S in lexicographical order.Sample Input:
ABC
Sample Output :
ABC ACB BAC BCA CAB CBA
Explanation:
all permutation are arranged in lexicographical order .
Sample Input:
(T(
Sample Output:-
((T (T( T((, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.util.Arrays;
class Main
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
String str = sc.next();
if(str.length()==1)
System.out.print(str);
else
permutations(str);
}
public static void permutations(String str)
{
char[] charstr = str.toCharArray();
Arrays.sort(charstr);
while (true)
{
System.out.print(new String(charstr) + " ");
if (!next_String(charstr)) {
break;
}
}
}
static void swap(char[] charstr, int i, int j)
{
char ch = charstr[i];
charstr[i] = charstr[j];
charstr[j] = ch;
}
static void reverse(char[] charstr, int start)
{
for (int i = start, j = charstr.length - 1; i < j; i++, j--) {
swap(charstr, i, j);
}
}
public static boolean next_String(char[] charstr)
{
int i = charstr.length - 1;
while (charstr[i - 1] >= charstr[i])
{
if (--i == 0) {
return false;
}
}
int j = charstr.length - 1;
while (j > i && charstr[j] <= charstr[i - 1]) {
j--;
}
swap(charstr, i - 1, j);
reverse(charstr, i);
return true;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A permutation is simply a name for a reordering. So the permutations of the string
‘abc’ are ‘abc’, ‘acb’, ‘bac’, ‘bca’, ‘cab’, and ‘cba’. Note that a sequence is a
permutation of itself (the trivial permutation). For this problem, you’ll need
to write a recursive function that takes a string and returns a
list of all its permutations.
A couple of notes on the requirements:
1. The order of the returned permutations must be lexicographically.
2. Avoid returning duplicates in your final list.Input contains a single string S.
Constraints:-
1<=|S|<=8Print all the permutations of string S in lexicographical order.Sample Input:
ABC
Sample Output :
ABC ACB BAC BCA CAB CBA
Explanation:
all permutation are arranged in lexicographical order .
Sample Input:
(T(
Sample Output:-
((T (T( T((, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
set<string> se;
// Function to find all Permutations of a given string
// containing all distinct characters
void permutations(string str, int n, string res)
{
// base condition (only one character is left in the string)
if (n == 1)
{
string s= res + str;
se.insert(s);
return;
}
// process each character of the remaining string
for (int i = 0; i < n; i++)
{
// push current character to the output string and recur
// for the remaining characters
permutations(str.substr(1), n - 1, res + str[0]);
// left rotate the string by 1 unit for next iteration
// to right rotate the string use reverse iterator
rotate(str.begin(), str.begin() + 1, str.end());
}
}
// Find all Permutations of a string
int main()
{
string s;
cin>>s;
string res="";
permutations(s, s.size(), res);
for(auto it=se.begin();it!=se.end();it++){
cout<<*it<<" ";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers containing only 0 or 1. You can do the following operations on the array:
<ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul>
You have to do the minimum number of the above operations such that the final array is non-decreasing.
<b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N.
The second line of input contains N space-separated integers denoting the array.
Constraints:
1 ≤ N ≤ 100000
elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1
5
1 1 0 0 1
Sample Output 1
2
Explanation:
Swap indices (1, 3)
Swap indices (2, 4)
Sample Input 2
5
0 0 1 1 1
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 IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine().trim());
String array[] = br.readLine().trim().split(" ");
boolean decreasingOrder = false;
int[] arr = new int[n];
int totalZeroCount = 0,
totalOneCount = 0;
for(int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(array[i]);
if(i != 0 && arr[i] < arr[i - 1])
decreasingOrder = true;
if(arr[i] % 2 == 0)
++totalZeroCount;
else
++totalOneCount;
}
if(!decreasingOrder) {
System.out.println("0");
} else {
int oneCount = 0;
for(int i = 0; i < totalZeroCount; i++) {
if(arr[i] == 1)
++oneCount;
}
System.out.println(oneCount);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers containing only 0 or 1. You can do the following operations on the array:
<ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul>
You have to do the minimum number of the above operations such that the final array is non-decreasing.
<b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N.
The second line of input contains N space-separated integers denoting the array.
Constraints:
1 ≤ N ≤ 100000
elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1
5
1 1 0 0 1
Sample Output 1
2
Explanation:
Swap indices (1, 3)
Swap indices (2, 4)
Sample Input 2
5
0 0 1 1 1
Sample Output 2
0, 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];
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i]==0) cnt++;
}
int ans = 0;
for (int i = 0; i < cnt; i++) if (a[i] == 1) ans++;
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers containing only 0 or 1. You can do the following operations on the array:
<ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul>
You have to do the minimum number of the above operations such that the final array is non-decreasing.
<b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N.
The second line of input contains N space-separated integers denoting the array.
Constraints:
1 ≤ N ≤ 100000
elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1
5
1 1 0 0 1
Sample Output 1
2
Explanation:
Swap indices (1, 3)
Swap indices (2, 4)
Sample Input 2
5
0 0 1 1 1
Sample Output 2
0, I have written this Solution Code: n=int(input())
l=list(map(int,input().split()))
x=l.count(0)
c=0
for i in range(0,x):
if(l[i]==1):
c+=1
print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not.
<b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements.
<b>Constraints:</b>
1 ≤ T ≤ 10
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 10<sup>9</sup>
1 ≤ arr[i] ≤ 10<sup>9</sup>
<b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input:
2
5 6
1 2 3 4 6
5 2
1 3 4 5 6
Sample Output:
1
-1, I have written this Solution Code: static int isPresent(long arr[], int n, long k)
{
int left = 0;
int right = n-1;
int res = -1;
while(left<=right){
int mid = (left+right)/2;
if(arr[mid] == k){
res = 1;
break;
}else if(arr[mid] < k){
left = mid + 1;
}else{
right = mid - 1;
}
}
return res;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not.
<b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements.
<b>Constraints:</b>
1 ≤ T ≤ 10
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 10<sup>9</sup>
1 ≤ arr[i] ≤ 10<sup>9</sup>
<b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input:
2
5 6
1 2 3 4 6
5 2
1 3 4 5 6
Sample Output:
1
-1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
unordered_map<long long,int> m;
long k;
cin>>k;
long long a;
for(int i=0;i<n;i++){
cin>>a;
m[a]++;
}
if(m.find(k)!=m.end()){
cout<<1<<endl;
}
else{
cout<<-1<<endl;
}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not.
<b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements.
<b>Constraints:</b>
1 ≤ T ≤ 10
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 10<sup>9</sup>
1 ≤ arr[i] ≤ 10<sup>9</sup>
<b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input:
2
5 6
1 2 3 4 6
5 2
1 3 4 5 6
Sample Output:
1
-1, I have written this Solution Code: def binary_search(arr, low, high, x):
if high >= low:
mid = (high + low) // 2
if arr[mid] == x:
return 1
elif arr[mid] > x:
return binary_search(arr, low, mid - 1, x)
else:
return binary_search(arr, mid + 1, high, x)
else:
return -1
def position(n,arr,x):
return binary_search(arr,0,n-1,x)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not.
<b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements.
<b>Constraints:</b>
1 ≤ T ≤ 10
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 10<sup>9</sup>
1 ≤ arr[i] ≤ 10<sup>9</sup>
<b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input:
2
5 6
1 2 3 4 6
5 2
1 3 4 5 6
Sample Output:
1
-1, I have written this Solution Code: // arr is they array to search from
// x is target
function binSearch(arr, x) {
// write code here
// do not console.log
// return the 1 or -1
let l = 0;
let r = arr.length - 1;
let mid;
while (r >= l) {
mid = l + Math.floor((r - l) / 2);
// If the element is present at the middle
// itself
if (arr[mid] == x)
return 1;
// If element is smaller than mid, then
// it can only be present in left subarray
if (arr[mid] > x)
r = mid - 1;
// Else the element can only be present
// in right subarray
else
l = mid + 1;
}
// We reach here when element is not
// present in array
return -1;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: static void Icecreams (int N, int D){
int x=N;
while(D-->0){
x-=x/2;
x*=3;
}
System.out.println(x);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){
int x=N;
while(D--){
x-=x/2;
x*=3;
}
cout << x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){
int x=N;
while(D--){
x-=x/2;
x*=3;
}
printf("%d", x);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: def Icecreams(N,D):
ans = N
while D > 0:
ans = ans - ans//2
ans = ans*3
D = D-1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a function <code>reverseString</code>, which takes in a string as a parameter. Your task is to complete the function such that it returns the reverse of the string.(hello changes to olleh)
// Complete the reverseString function
function reverseString(n) {
//Write Code Here
}A string nReturns the reverse of nconst n = 'hello'
reverseString(n) //displays 'olleh' in console, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String n=sc.nextLine();
char tra[] = n.toCharArray();
for(int i=tra.length-1;i>=0;i--){
System.out.print(tra[i]);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a function <code>reverseString</code>, which takes in a string as a parameter. Your task is to complete the function such that it returns the reverse of the string.(hello changes to olleh)
// Complete the reverseString function
function reverseString(n) {
//Write Code Here
}A string nReturns the reverse of nconst n = 'hello'
reverseString(n) //displays 'olleh' in console, I have written this Solution Code: function reverseString (n) {
return n.split("").reverse().join("");
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 ≤ X ≤ 1000
1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
if(s==null){
System.exit(0);
}
StringTokenizer st = new StringTokenizer(s, " ");
int power = Integer.parseInt(st.nextToken());
int multiple = Integer.parseInt(st.nextToken());
int res = power;
for(int i = 1;i<=multiple;i++){
res = res*2;
}
System.out.println(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 ≤ X ≤ 1000
1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: #include <iostream>
using namespace std;
int main()
{
int x, n;
cin >> x >> n;
cout << x*(1 << n);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 ≤ X ≤ 1000
1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: x,n = map(int,input().split())
print(x*(2**n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked 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>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code: int ludo(int N){
return (N==1||N==6);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked 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>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code: def ludo(N):
if N==1 or N==6:
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked 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>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code:
int ludo(int N){
return (N==1||N==6);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked 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>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code: static int ludo(int N){
if(N==1 || N==6){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sky (the blue ranger) wants to replace Jack (the red ranger) from his position. For this, he needs to conquer the entire Base.
The Base can be represented as an M*N grid, and Sky needs to conquer it cell by cell. Sky starts conquering the Base from the cell (1, 1). In each move, he conquers the cell, and moves to an adjacent non- conquered cell (he cannot move if there is no adjacent non- conquered cell). Now, there is a catch, the last cell he needs to conquer is (M, N) so as to complete the quest for the red ranger tag!
Please let us know if Sky can replace Jack by conquering all the cells in the Base.
Note: The diagonal cells are not considered as adjacent cells.The first and the only line of input contains two integers M and N.
Constraints
1 <= M, N <= 1000Output "YES" (without quotes) if Sky can conquer the entire Base to replace Jack, else output "NO" (without quotes).Sample Input
2 2
Sample Output
NO
Explanation
The possible journeys of Sky ending at (2, 2) can be:
(1, 1) - > (1, 2) - > (2, 2)
(1, 1) - > (2, 1) - > (2, 2)
Since, in each of the path that Sky takes, the total cells covered are not 4, hence Sky cannot conquer the entire base.
Sample Input
3 3
Sample Output
YES, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s[]=br.readLine().split(" ");
int m=Integer.parseInt(s[0]);
int n=Integer.parseInt(s[1]);
if(m%2==0 && n%2==0)
System.out.println("NO");
else
System.out.println("YES");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sky (the blue ranger) wants to replace Jack (the red ranger) from his position. For this, he needs to conquer the entire Base.
The Base can be represented as an M*N grid, and Sky needs to conquer it cell by cell. Sky starts conquering the Base from the cell (1, 1). In each move, he conquers the cell, and moves to an adjacent non- conquered cell (he cannot move if there is no adjacent non- conquered cell). Now, there is a catch, the last cell he needs to conquer is (M, N) so as to complete the quest for the red ranger tag!
Please let us know if Sky can replace Jack by conquering all the cells in the Base.
Note: The diagonal cells are not considered as adjacent cells.The first and the only line of input contains two integers M and N.
Constraints
1 <= M, N <= 1000Output "YES" (without quotes) if Sky can conquer the entire Base to replace Jack, else output "NO" (without quotes).Sample Input
2 2
Sample Output
NO
Explanation
The possible journeys of Sky ending at (2, 2) can be:
(1, 1) - > (1, 2) - > (2, 2)
(1, 1) - > (2, 1) - > (2, 2)
Since, in each of the path that Sky takes, the total cells covered are not 4, hence Sky cannot conquer the entire base.
Sample Input
3 3
Sample Output
YES, I have written this Solution Code: m,n=map(int, input().split())
if(m%2 or n%2):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sky (the blue ranger) wants to replace Jack (the red ranger) from his position. For this, he needs to conquer the entire Base.
The Base can be represented as an M*N grid, and Sky needs to conquer it cell by cell. Sky starts conquering the Base from the cell (1, 1). In each move, he conquers the cell, and moves to an adjacent non- conquered cell (he cannot move if there is no adjacent non- conquered cell). Now, there is a catch, the last cell he needs to conquer is (M, N) so as to complete the quest for the red ranger tag!
Please let us know if Sky can replace Jack by conquering all the cells in the Base.
Note: The diagonal cells are not considered as adjacent cells.The first and the only line of input contains two integers M and N.
Constraints
1 <= M, N <= 1000Output "YES" (without quotes) if Sky can conquer the entire Base to replace Jack, else output "NO" (without quotes).Sample Input
2 2
Sample Output
NO
Explanation
The possible journeys of Sky ending at (2, 2) can be:
(1, 1) - > (1, 2) - > (2, 2)
(1, 1) - > (2, 1) - > (2, 2)
Since, in each of the path that Sky takes, the total cells covered are not 4, hence Sky cannot conquer the entire base.
Sample Input
3 3
Sample Output
YES, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n, m; cin>>n>>m;
if(n%2 || m%2){
cout<<"YES";
}
else{
cout<<"NO";
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono loves to do shopping. Today, she went to the market where there are N different types of products. She wants to buy exactly K of them at the minimum cost. Although she is super smart, she wants to check your smartness as well. Can you tell her the minimum cost required to buy exactly K products if she has already decided to buy product J?
<b>Note:</b> Tono does not buy the same product twice, and Tono will definitely buy product J (J is the <b>index</b> of the item).The first line of the input contains three integers, N, K, and J, denoting the number of products in the market, the number of products Tono needs to buy, and the product that Tono will definitely buy.
The next line contains N singly spaced integers, the cost of the N products C[1], C[2], ..., C[N].
<b>Constraints:</b>
1 <= N <= 200000
1 <= K <= N
1 <= J <= N
1 <= C[i] <= 1000
Output a single integer, the minimum amount Tono needs to pay.Sample Input 1:
5 3 4
1 2 3 4 5
Sample Output 1:
7
Sample Input 2:
5 1 3
2 4 3 1 1
Sample Output 2:
3
<b>Explanation:</b>
Tono needs to buy exactly 3 products, and she will definitely buy the 4th product. Thus, she will buy the 1st, 2nd, and the 4th product. The total cost she pays is 1+2+4=7.
, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
int n = io.nextInt(), k = io.nextInt(), j = io.nextInt() - 1;
int[] arr = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = io.nextInt();
}
int cost = arr[j];
arr[j] = Integer.MAX_VALUE;
Arrays.sort(arr);
for(int i = 0; i < k - 1; i++) {
cost += arr[i];
}
io.println(cost);
io.close();
}
static IO io = new IO();
static class IO {
private byte[] buf;
private InputStream in;
private PrintWriter pw;
private int total, index;
public IO() {
buf = new byte[1024];
in = System.in;
pw = new PrintWriter(System.out);
}
public int next() throws IOException {
if(total < 0)
throw new InputMismatchException();
if(index >= total) {
index = 0;
total = in.read(buf);
if(total <= 0)
return -1;
}
return buf[index++];
}
public int nextInt() throws IOException {
int n = next(), integer = 0;
while(isWhiteSpace(n))
n = next();
int neg = 1;
if(n == '-') {
neg = -1;
n = next();
}
while(!isWhiteSpace(n)) {
if(n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = next();
}
else
throw new InputMismatchException();
}
return neg * integer;
}
public int[] nextIntArray(int n) throws IOException {
int[] arr = new int[n];
for(int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
public long nextLong() throws IOException {
long integer = 0l;
int n = next();
while(isWhiteSpace(n))
n = next();
int neg = 1;
if(n == '-') {
neg = -1;
n = next();
}
while(!isWhiteSpace(n)) {
if(n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = next();
}
else
throw new InputMismatchException();
}
return neg * integer;
}
public double nextDouble() throws IOException {
double doub = 0;
int n = next();
while(isWhiteSpace(n))
n = next();
int neg = 1;
if(n == '-') {
neg = -1;
n = next();
}
while(!isWhiteSpace(n) && n != '.') {
if(n >= '0' && n <= '9') {
doub *= 10;
doub += n - '0';
n = next();
}
else
throw new InputMismatchException();
}
if(n == '.') {
n = next();
double temp = 1;
while(!isWhiteSpace(n)) {
if(n >= '0' && n <= '9') {
temp /= 10;
doub += (n - '0') * temp;
n = next();
}
else
throw new InputMismatchException();
}
}
return doub * neg;
}
public String nextString() throws IOException {
StringBuilder sb = new StringBuilder();
int n = next();
while(isWhiteSpace(n))
n = next();
while(!isWhiteSpace(n)) {
sb.append((char)n);
n = next();
}
return sb.toString();
}
public String nextLine() throws IOException {
int n = next();
while(isWhiteSpace(n))
n = next();
StringBuilder sb = new StringBuilder();
while(!isEndOfLine(n)) {
sb.append((char)n);
n = next();
}
return sb.toString();
}
private boolean isWhiteSpace(int n) {
return n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1;
}
private boolean isEndOfLine(int n) {
return n == '\n' || n == '\r' || n == -1;
}
public void print(Object obj) {
pw.print(obj);
}
public void println(Object... obj) {
if(obj.length == 1)
pw.println(obj[0]);
else {
for(Object o: obj)
pw.print(o + " ");
pw.println();
}
}
public void flush() throws IOException {
pw.flush();
}
public void close() throws IOException {
pw.close();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono loves to do shopping. Today, she went to the market where there are N different types of products. She wants to buy exactly K of them at the minimum cost. Although she is super smart, she wants to check your smartness as well. Can you tell her the minimum cost required to buy exactly K products if she has already decided to buy product J?
<b>Note:</b> Tono does not buy the same product twice, and Tono will definitely buy product J (J is the <b>index</b> of the item).The first line of the input contains three integers, N, K, and J, denoting the number of products in the market, the number of products Tono needs to buy, and the product that Tono will definitely buy.
The next line contains N singly spaced integers, the cost of the N products C[1], C[2], ..., C[N].
<b>Constraints:</b>
1 <= N <= 200000
1 <= K <= N
1 <= J <= N
1 <= C[i] <= 1000
Output a single integer, the minimum amount Tono needs to pay.Sample Input 1:
5 3 4
1 2 3 4 5
Sample Output 1:
7
Sample Input 2:
5 1 3
2 4 3 1 1
Sample Output 2:
3
<b>Explanation:</b>
Tono needs to buy exactly 3 products, and she will definitely buy the 4th product. Thus, she will buy the 1st, 2nd, and the 4th product. The total cost she pays is 1+2+4=7.
, I have written this Solution Code:
a=input().split()
b=input().split()
for j in [a,b]:
for i in range(0,len(j)):
j[i]=int(j[i])
n,k,j=a[0],a[1],a[2]
c_j=b[j-1]
b.sort()
if b[k-1]<=c_j:
b[k-1]=c_j
sum=0
for i in range(0,k):
sum+=b[i]
print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono loves to do shopping. Today, she went to the market where there are N different types of products. She wants to buy exactly K of them at the minimum cost. Although she is super smart, she wants to check your smartness as well. Can you tell her the minimum cost required to buy exactly K products if she has already decided to buy product J?
<b>Note:</b> Tono does not buy the same product twice, and Tono will definitely buy product J (J is the <b>index</b> of the item).The first line of the input contains three integers, N, K, and J, denoting the number of products in the market, the number of products Tono needs to buy, and the product that Tono will definitely buy.
The next line contains N singly spaced integers, the cost of the N products C[1], C[2], ..., C[N].
<b>Constraints:</b>
1 <= N <= 200000
1 <= K <= N
1 <= J <= N
1 <= C[i] <= 1000
Output a single integer, the minimum amount Tono needs to pay.Sample Input 1:
5 3 4
1 2 3 4 5
Sample Output 1:
7
Sample Input 2:
5 1 3
2 4 3 1 1
Sample Output 2:
3
<b>Explanation:</b>
Tono needs to buy exactly 3 products, and she will definitely buy the 4th product. Thus, she will buy the 1st, 2nd, and the 4th product. The total cost she pays is 1+2+4=7.
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n, k, j; cin>>n>>k>>j;
vector<int> vect;
int ans = 0;
For(i, 1, n+1){
int a; cin>>a;
if(i!=j)
vect.pb(a);
else
ans += a;
}
sort(all(vect));
for(int i=0; i<k-1; i++){
ans += vect[i];
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N and K, find the lexicographically smallest string of length N using only the first K lowercase letters of the alphabet such that each letter is used at least once and no two adjacent characters are equal.
If such a string doesn't exist, print -1.The first line of input contains a single integer, T (1 <= T <= 100).
Then T lines follow, each containing two space-separated integers, N (1 <= N <= 10<sup>5</sup>) and K (1 <= K <= 26).
It is guaranteed that sum of N over all test cases does not exceed 10<sup>6</sup>For each test case, output its answer in a new line.Sample Input:
2
2 3
3 2
Sample Output:
-1
aba, 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));
BufferedWriter bo=new BufferedWriter(new OutputStreamWriter(System.out));
int t;
try{
t=Integer.parseInt(br.readLine());
}
catch(Exception e)
{
return;
}
while(t-->0)
{
String[] g=br.readLine().split(" ");
int n=Integer.parseInt(g[0]);
int k=Integer.parseInt(g[1]);
if(k>n || (k==1) || (k>26))
{
if(n==1 && k==1)
bo.write("a\n");
else
bo.write(-1+"\n");
}
else
{
int extra=k-2;
boolean check=true;
while(n>extra)
{
if(check==true)
bo.write("a");
else
bo.write("b");
if(check==true)
check=false;
else
check=true;
n--;
}
for(int i=0;i<extra;i++)
bo.write((char)(i+99));
bo.write("\n");
}
}
bo.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N and K, find the lexicographically smallest string of length N using only the first K lowercase letters of the alphabet such that each letter is used at least once and no two adjacent characters are equal.
If such a string doesn't exist, print -1.The first line of input contains a single integer, T (1 <= T <= 100).
Then T lines follow, each containing two space-separated integers, N (1 <= N <= 10<sup>5</sup>) and K (1 <= K <= 26).
It is guaranteed that sum of N over all test cases does not exceed 10<sup>6</sup>For each test case, output its answer in a new line.Sample Input:
2
2 3
3 2
Sample Output:
-1
aba, I have written this Solution Code: t=int(input())
for tt in range(t):
n,k=map(int,input().split())
if (k==1 and n>1) or (k>n):
print(-1)
continue
s="abcdefghijklmnopqrstuvwxyz"
ss="ab"
if (n-k)%2==0:
a=ss*((n-k)//2)+s[:k]
else:
a=ss*((n-k)//2)+s[:2]+"a"+s[2:k]
print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N and K, find the lexicographically smallest string of length N using only the first K lowercase letters of the alphabet such that each letter is used at least once and no two adjacent characters are equal.
If such a string doesn't exist, print -1.The first line of input contains a single integer, T (1 <= T <= 100).
Then T lines follow, each containing two space-separated integers, N (1 <= N <= 10<sup>5</sup>) and K (1 <= K <= 26).
It is guaranteed that sum of N over all test cases does not exceed 10<sup>6</sup>For each test case, output its answer in a new line.Sample Input:
2
2 3
3 2
Sample Output:
-1
aba, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef unsigned long long int ull;
const long double PI = acos(-1);
const ll mod=1e9+7;
const ll mod1=998244353;
const int inf = 1e9;
const ll INF=1e18;
void precompute(){
}
void TEST_CASE(){
int n,k;
cin >> n >> k;
if(k==1){
if(n>1){
cout << -1 << endl;
}else{
cout << 'a' << endl;
}
}else if(n<k){
cout << -1 << endl;
}else if(n==k){
string s="";
for(int i=0 ; i<k ; i++){
s+=('a'+i);
}
cout << s << endl;
}else{
string s="";
for(int i=0 ; i<(n-k+2) ; i++){
if(i%2){
s+="b";
}else{
s+="a";
}
}
for(int i=2 ; i<k ; i++){
s+=('a'+i);
}
cout << s << endl;
}
}
signed main(){
fast;
//freopen ("INPUT.txt","r",stdin);
//freopen ("OUTPUT.txt","w",stdout);
int test=1,TEST=1;
precompute();
cin >> test;
while(test--){
TEST_CASE();
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, your task is to find if it is a perfect square or not.The first line of input contains the number of test cases T, the next T lines contains a single integer N.
<b>Constraints:</b>
1 < = T < = 1000
1 < = N < = 10<sup>12</sup>For each test case, print "YES" if the number N is a perfect square else print "NO".Sample Input:-
2
625
624
Sample Output:-
YES
NO, I have written this Solution Code: import math
cases=int(input(""))
for case in range(cases):
n=int(input())
if math.sqrt(n) % 1 == 0:print("YES")
else:print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, your task is to find if it is a perfect square or not.The first line of input contains the number of test cases T, the next T lines contains a single integer N.
<b>Constraints:</b>
1 < = T < = 1000
1 < = N < = 10<sup>12</sup>For each test case, print "YES" if the number N is a perfect square else print "NO".Sample Input:-
2
625
624
Sample Output:-
YES
NO, I have written this Solution Code: /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
long n = sc.nextLong();
if(check(n)==1){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
static int check(long n){
long l=1;
long h = 10000000;
long m=0;
long p=0;
long ans=0;
while(l<=h){
m=l+h;
m/=2;
p=m*m;
if(p > n){
h=m-1;
}
else{
l=m+1;
ans=m;
}
//System.out.println(l+" "+h);
}
if(ans*ans==n){return 1;}
return 0;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, your task is to find if it is a perfect square or not.The first line of input contains the number of test cases T, the next T lines contains a single integer N.
<b>Constraints:</b>
1 < = T < = 1000
1 < = N < = 10<sup>12</sup>For each test case, print "YES" if the number N is a perfect square else print "NO".Sample Input:-
2
625
624
Sample Output:-
YES
NO, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
long long x=sqrt(n);
long long p = x*x;
if(p==n){cout<<"YES"<<endl;;}
else{
cout<<"NO"<<endl;
}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: static void Icecreams (int N, int D){
int x=N;
while(D-->0){
x-=x/2;
x*=3;
}
System.out.println(x);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){
int x=N;
while(D--){
x-=x/2;
x*=3;
}
cout << x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){
int x=N;
while(D--){
x-=x/2;
x*=3;
}
printf("%d", x);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: def Icecreams(N,D):
ans = N
while D > 0:
ans = ans - ans//2
ans = ans*3
D = D-1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You think that integers divisible by K are nice. Given L and R (L<=R), find the number of nice integers from L to R (both inclusive).First Line of input contains three integers L R K
Constraints :
0 <= L <= R <= 1000000000000000000(10^18)
1 <= K <= 1000000000000000000(10^18)Output a single integer which is the number of nice integers from L to R (both inclusive).Sample input 1
1 10 2
Sample output 1
5
Sample intput 2
4 5 3
Sample output 2
0
Explanation:-
Required divisors = 2 4 6 8 10, I have written this Solution Code:
import java.io.*;
import java.util.*;
class Main{
public static void main(String[] args)throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str[]=br.readLine().split(" ");
long l=Long.parseLong(str[0]);
long r=Long.parseLong(str[1]);
long k=Long.parseLong(str[2]);
long count=(r/k)-((l-1)/k);
System.out.print(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You think that integers divisible by K are nice. Given L and R (L<=R), find the number of nice integers from L to R (both inclusive).First Line of input contains three integers L R K
Constraints :
0 <= L <= R <= 1000000000000000000(10^18)
1 <= K <= 1000000000000000000(10^18)Output a single integer which is the number of nice integers from L to R (both inclusive).Sample input 1
1 10 2
Sample output 1
5
Sample intput 2
4 5 3
Sample output 2
0
Explanation:-
Required divisors = 2 4 6 8 10, I have written this Solution Code: l,r,k=[int(x)for x in input().split()]
print(r//k - (l-1)//k), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You think that integers divisible by K are nice. Given L and R (L<=R), find the number of nice integers from L to R (both inclusive).First Line of input contains three integers L R K
Constraints :
0 <= L <= R <= 1000000000000000000(10^18)
1 <= K <= 1000000000000000000(10^18)Output a single integer which is the number of nice integers from L to R (both inclusive).Sample input 1
1 10 2
Sample output 1
5
Sample intput 2
4 5 3
Sample output 2
0
Explanation:-
Required divisors = 2 4 6 8 10, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
unsigned long long x,l,r,k;
cin>>l>>r>>k;
x=l/k;
if(l%k==0){x--;}
cout<<r/k-x;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Suppose if you want to change the name of the table `profile` to `profile_info`. How will you rename the table?
<schema>[{'name': 'profile', 'columns': [{'name': 'username', 'type': 'varchar (24)'}, {'name': 'full_name', 'type': 'varchar (72)'}, {'name': 'headline', 'type': 'varchar (72)'}]}]</schema>nannannan, I have written this Solution Code: ALTER TABLE profile
RENAME TO profile_info;, In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N.
Constraints:
1 < = T < = 100
1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input:
2
5
10
Sample Output:
15
55, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t-->0){
int n=Integer.parseInt(br.readLine());
System.out.println(n*(n+1)/2);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N.
Constraints:
1 < = T < = 100
1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input:
2
5
10
Sample Output:
15
55, I have written this Solution Code: for t in range(int(input())):
n = int(input())
print(n*(n+1)//2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N.
Constraints:
1 < = T < = 100
1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input:
2
5
10
Sample Output:
15
55, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
cout<<(n*(n+1))/2<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int len = Integer.parseInt(br.readLine());
char[] str = new char[len];
for(int i = 0; i < len; i++){
if(i%2 == 0){
str[i] = 'a';
} else{
str[i] = 'b';
}
}
System.out.println(str);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
#define rep(i,n) for (int i=0; i<(n); i++)
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
string s(n,'a');
for(int i=1;i<n;i+=2)
s[i]='b';
cout<<s;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: a="ab"
inp = int(input())
print(a*(inp//2)+a[0:inp%2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given N ropes of L[i] lengths, you need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. The task is to connect the ropes with minimum cost.The first line of input contains an integer T denoting the number of test cases. The first line of each test case is N where N is the number of ropes. The second line of each test case contains N input L[i],length of ropes.
Constraints:
1 ≤ T ≤ 100
1 <= N <= 10^5
1 <= L[i] <= 10^5
Sum of N over all test cases does not exceed 5*10^5.For each testcase, print the minimum cost to connect all the ropes.Sample Input:
2
4
4 3 2 6
5
4 2 7 6 9
Sample Output:
29
62
Explanation:
For example if we are given 4 ropes of lengths 4, 3, 2 and 6. We can connect the ropes in following ways.
1) First connect ropes of lengths 2 and 3. Now we have three ropes of lengths 4, 6 and 5.
2) Now connect ropes of lengths 4 and 5. Now we have two ropes of lengths 6 and 9.
3) Finally connect the two ropes and all ropes have connected.
Total cost for connecting all ropes is 5 + 9 + 15 = 29. This is the optimized cost for connecting ropes. Other ways of connecting ropes would always have same or more cost. For example, if we connect 4 and 6 first (we get three strings of 3, 2 and 10), then connect 10 and 3 (we get two strings of 13 and 2). Finally we connect 13 and 2. Total cost in this way is 10 + 13 + 15 = 38, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static long minCost(long arr[], int n)
{
PriorityQueue<Long> pq = new PriorityQueue<>();
for (int i = 0; i < n; i++) pq.add(arr[i]);
Long cost = new Long("0");
while (pq.size() != 1)
{
long x = pq.poll();
long y = pq.poll();
cost += (x + y);
pq.add(x + y);
}
arr = null;
System.gc();
return cost;
}
public static void main (String[] args) {
FastReader sc = new FastReader();
OutputStream outputstream = System.out;
PrintWriter out = new PrintWriter(outputstream);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
long[] arr = new long[n];
for(int i = 0; i < n; i++)
arr[i] = sc.nextLong();
System.out.println(minCost(arr, arr.length));
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given N ropes of L[i] lengths, you need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. The task is to connect the ropes with minimum cost.The first line of input contains an integer T denoting the number of test cases. The first line of each test case is N where N is the number of ropes. The second line of each test case contains N input L[i],length of ropes.
Constraints:
1 ≤ T ≤ 100
1 <= N <= 10^5
1 <= L[i] <= 10^5
Sum of N over all test cases does not exceed 5*10^5.For each testcase, print the minimum cost to connect all the ropes.Sample Input:
2
4
4 3 2 6
5
4 2 7 6 9
Sample Output:
29
62
Explanation:
For example if we are given 4 ropes of lengths 4, 3, 2 and 6. We can connect the ropes in following ways.
1) First connect ropes of lengths 2 and 3. Now we have three ropes of lengths 4, 6 and 5.
2) Now connect ropes of lengths 4 and 5. Now we have two ropes of lengths 6 and 9.
3) Finally connect the two ropes and all ropes have connected.
Total cost for connecting all ropes is 5 + 9 + 15 = 29. This is the optimized cost for connecting ropes. Other ways of connecting ropes would always have same or more cost. For example, if we connect 4 and 6 first (we get three strings of 3, 2 and 10), then connect 10 and 3 (we get two strings of 13 and 2). Finally we connect 13 and 2. Total cost in this way is 10 + 13 + 15 = 38, I have written this Solution Code: import heapq
from heapq import heappush, heappop
def findMinCost(prices):
heapq.heapify(prices)
cost = 0
while len(prices) > 1:
x = heappop(prices)
y = heappop(prices)
total = x + y
heappush(prices, total)
cost += total
return cost
t=int(input())
for _ in range(t):
n=int(input())
prices=list(map(int,input().split()))
print( findMinCost(prices)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given N ropes of L[i] lengths, you need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. The task is to connect the ropes with minimum cost.The first line of input contains an integer T denoting the number of test cases. The first line of each test case is N where N is the number of ropes. The second line of each test case contains N input L[i],length of ropes.
Constraints:
1 ≤ T ≤ 100
1 <= N <= 10^5
1 <= L[i] <= 10^5
Sum of N over all test cases does not exceed 5*10^5.For each testcase, print the minimum cost to connect all the ropes.Sample Input:
2
4
4 3 2 6
5
4 2 7 6 9
Sample Output:
29
62
Explanation:
For example if we are given 4 ropes of lengths 4, 3, 2 and 6. We can connect the ropes in following ways.
1) First connect ropes of lengths 2 and 3. Now we have three ropes of lengths 4, 6 and 5.
2) Now connect ropes of lengths 4 and 5. Now we have two ropes of lengths 6 and 9.
3) Finally connect the two ropes and all ropes have connected.
Total cost for connecting all ropes is 5 + 9 + 15 = 29. This is the optimized cost for connecting ropes. Other ways of connecting ropes would always have same or more cost. For example, if we connect 4 and 6 first (we get three strings of 3, 2 and 10), then connect 10 and 3 (we get two strings of 13 and 2). Finally we connect 13 and 2. Total cost in this way is 10 + 13 + 15 = 38, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
priority_queue<long long> pq;
int n;
cin>>n;
long long x;
long long sum=0;
for(int i=0;i<n;i++){
cin>>x;
x=-x;
pq.push(x);
}
long long y;
while(pq.size()!=1){
x=pq.top();
pq.pop();
y=pq.top();
pq.pop();
sum+=x+y;
pq.push(x+y);
}
cout<<-sum<<endl;
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code:
#include <iostream>
using namespace std;
int Dishes(int N, int T){
return T-N;
}
int main(){
int n,k;
scanf("%d%d",&n,&k);
printf("%d",Dishes(n,k));
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an unsorted array of length n and must sort it using merge sort while also printing the amount of merges that occur throughout the sorting process.The first line of input will be n, which represents the array's length, followed by the n array items in the second line.
Constraints:
0<= n <=100000First- line should be the sorted array and the second should be the number of mergers that occurs when the array is sorted using merge sort.Sample Input:
5
5 1 2 7 3
Output:
1 2 3 5 7
4, I have written this Solution Code: def mergeSort(arr,count):
if len(arr)>1:
mid= len(arr)//2
a=arr[:mid]
b=arr[mid:]
count=mergeSort(a,count)
count=mergeSort(b,count)
count+=1
i = j = k = 0
l1 = len(a)
l2 = len(b)
while i< l1 and j <l2:
if a[i]<b[j]:
arr[k]=a[i]
i +=1
else:
arr[k]=b[j]
j+=1
k+=1
while i <l1:
arr[k]=a[i]
i+=1
k+=1
while j<l2:
arr[k]=b[j]
j+=1
k+=1
return count
N=int(input())
arr=list(map(int,input().split()))
count=mergeSort(arr,0)
print(' '.join(map(str,arr)))
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an unsorted array of length n and must sort it using merge sort while also printing the amount of merges that occur throughout the sorting process.The first line of input will be n, which represents the array's length, followed by the n array items in the second line.
Constraints:
0<= n <=100000First- line should be the sorted array and the second should be the number of mergers that occurs when the array is sorted using merge sort.Sample Input:
5
5 1 2 7 3
Output:
1 2 3 5 7
4, I have written this Solution Code: import java.util.Scanner;
public class Main
{
int noOfMerge=0;
void merge(int arr[], int l, int m, int r)
{
int n1 = m - l + 1;
int n2 = r - m;
int L[] = new int [n1];
int R[] = new int [n2];
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
int i = 0, j = 0,k=l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
void sort(int arr[], int l, int r)
{
if (l < r)
{
int m = (l+r)/2;
sort(arr, l, m);
sort(arr , m+1, r);
merge(arr, l, m, r);
noOfMerge+=1;
}
}
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] array=new int[n];
for(int i=0;i<n;i++)
array[i]=scanner.nextInt();
Main ob = new Main();
ob.sort(array, 0, n-1);
for (int i=0; i<n; ++i)
System.out.print(array[i] + " ");
System.out.println();
System.out.println(ob.noOfMerge);
}
}, 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 calculate the number of integers which are factors of atleast two given numbers.<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>CommonFactors()</b> that takes the integers A, B and C as parameters.
<b>Constraints:</b>
1 <= A, B, C <= 100000Return the count of common factors.Sample Input:-
3 6 12
Sample Output:-
4
Explanation:- 1, 2, 3, 6 are the required factors
Sample Input:-
1 2 3
Sample Output:-
1, I have written this Solution Code:
int commonFactors(int A,int B,int C){
int cnt=0;
for(int i=1;i<=A;i++){
if(A%i==0){
if(B%i==0 || C%i==0){cnt++;}
}
}
for(int i=1;i<=B;i++){
if(B%i==0){
if(A%i!=0 && C%i==0){cnt++;}
}
}
return cnt;
}
, 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 calculate the number of integers which are factors of atleast two given numbers.<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>CommonFactors()</b> that takes the integers A, B and C as parameters.
<b>Constraints:</b>
1 <= A, B, C <= 100000Return the count of common factors.Sample Input:-
3 6 12
Sample Output:-
4
Explanation:- 1, 2, 3, 6 are the required factors
Sample Input:-
1 2 3
Sample Output:-
1, I have written this Solution Code:
static int commonFactors(int A,int B,int C){
int cnt=0;
for(int i=1;i<=A;i++){
if(A%i==0){
if(B%i==0 || C%i==0){cnt++;}
}
}
for(int i=1;i<=B;i++){
if(B%i==0){
if(A%i!=0 && C%i==0){cnt++;}
}
}
return cnt;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.