Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given an array A of positive integers. Your task is to sort them in such a way that the first part of the array contains odd numbers sorted in descending order, rest portion contains even numbers sorted in ascending order.First line of each test case contains an integer N denoting the size of the array. The next line contains N space separated values of the array.
<b>Constraints:</b>
1 <b>≤</b> N <b>≤</b> 10<sup>5</sup>
0 <b>≤</b> A[i] <b>≤</b> 10<sup>6</sup>Print the space separated values of the modified array.Sample Input
7
1 2 3 5 4 7 10
Sample Output
7 5 3 1 2 4 10
Sample Input
7
0 4 5 3 7 2 1
Sample Output
7 5 3 1 0 2 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int n = Integer.parseInt(br.readLine());
long[] arr = new long[n];
String[] raw = br.readLine().split("\\s+");
int eCount = 0;
for (int i = 0; i < n; i++) {
long tmp = Long.parseLong(raw[i]);
if (tmp % 2 == 0) arr[i] = tmp;
else arr[i] = -tmp;
}
Arrays.sort(arr);
int k = 0;
while (arr[k] % 2 != 0) {
arr[k] = -arr[k];
k++;
}
for (int i = 0; i < n; i++)
pw.print(arr[i] + " ");
pw.println();
pw.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rick's family and Jerry are playing Tic Tac Toe. Rules are simple:
<li> Game is played in pairs.
<li> If Rick plays against anyone, Rick wins.
<li> If Jerry plays against anyone, Jerry Loses.
<li> A game between any other players is a draw.
Given a pair of players, find who wins the game or if the game is draw.Input Contains two space separated characters denoting the players that will have the match.
R denotes Rick.
J denotes Jerry.
B denotes Beth.
M denotes Morty.
S denotes Summer.If the game is draw print 'D', else print the first letter of the name of the player who wins in capital.Sample Input 1
R S
Sample Output 1
R
Sample Input 2
B J
Sample Output 2
B
Sample Input 3
M S
Sample Output 3
D, 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
char p1,p2;
cin>>p1>>p2;
if(p1=='R'||p2=='R')
cout<<"R";
else{
if(p1=='J')
cout<<p2;
else{
if(p2=='J')
cout<<p1;
else
cout<<"D";
}
}
#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: Rick's family and Jerry are playing Tic Tac Toe. Rules are simple:
<li> Game is played in pairs.
<li> If Rick plays against anyone, Rick wins.
<li> If Jerry plays against anyone, Jerry Loses.
<li> A game between any other players is a draw.
Given a pair of players, find who wins the game or if the game is draw.Input Contains two space separated characters denoting the players that will have the match.
R denotes Rick.
J denotes Jerry.
B denotes Beth.
M denotes Morty.
S denotes Summer.If the game is draw print 'D', else print the first letter of the name of the player who wins in capital.Sample Input 1
R S
Sample Output 1
R
Sample Input 2
B J
Sample Output 2
B
Sample Input 3
M S
Sample Output 3
D, I have written this Solution Code: a,b=input().split()
if(a=="R" or b=="R"):
print("R")
elif(a=="J" or b=="J"):
if(a=="J"):
print(b)
else:
print(a)
else:
print("D"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rick's family and Jerry are playing Tic Tac Toe. Rules are simple:
<li> Game is played in pairs.
<li> If Rick plays against anyone, Rick wins.
<li> If Jerry plays against anyone, Jerry Loses.
<li> A game between any other players is a draw.
Given a pair of players, find who wins the game or if the game is draw.Input Contains two space separated characters denoting the players that will have the match.
R denotes Rick.
J denotes Jerry.
B denotes Beth.
M denotes Morty.
S denotes Summer.If the game is draw print 'D', else print the first letter of the name of the player who wins in capital.Sample Input 1
R S
Sample Output 1
R
Sample Input 2
B J
Sample Output 2
B
Sample Input 3
M S
Sample Output 3
D, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
String[] rowcol = rd.readLine().split(" ");
String name = rowcol[0];
String name2 = rowcol[1];
if(name.equals("R")|| name2.equals("R")){
System.out.print('R');
return;
}
else if(name.equals("J")){
System.out.print(name2);
return;
}else if(name2.equals("J")){
System.out.print(name);
return;
}
else if(!name.equals("R") && !name.equals("J")){
System.out.print('D');
return;
}
else if(!name2.equals("J") && !name2.equals("R")){
System.out.print('D');
return;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a singly linked list, delete middle node of the linked list. For example, if given linked list is 1->2->3->4->5 then linked list should be modified to 1->2->4->5.
If there are even nodes, then there would be two middle nodes, we need to delete the second middle element. For example, if given linked list is 1->2->3->4->5->6 then it should be modified to 1->2->3->5->6.
In case of a single node return the head of a linked list containing only 1 node which has value -1<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>deleteMiddleElement()</b> that takes head node of the linked list as parameter.
Constraints:
1 <=N<= 1000
1 <=value<= 1000
Return the head of the modified linked listSample Input 1:
5
1 2 3 4 5
Sample Output:
1 2 4 5
Explanation: After deleting middle of the linked list, 3 will be deleted and the list will be as 1, 2, 4, 5.
Sample Input 2:
6
1 2 3 4 5 6
Sample Output:-
1 2 3 5 6
, I have written this Solution Code: public static Node deleteMiddleElement(Node head) {
int cnt=0;
Node temp=head;
while(temp!=null){
cnt++;
temp=temp.next;
}
if(cnt==1){
head.val=-1;
return head;
}
if(cnt==2){
head.next=null;
return head;
}
temp=head;
int I=1;
cnt=cnt/2;
while(I!=cnt){
temp=temp.next;
I++;
}
temp.next=temp.next.next;
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N. You need to find the root mean square (RMS) of the array i. e you first need to square all values of array and take its mean. Then you need to return the square root of mean. Print the answer with precision upto 6 decimal places.The first line contains an integer N - the size of the array
The next line contains N space-separated integers - the elements of the array.
<b>Constraints:</b>
1 <= N <= 100
1 <= Ai <= 100Print the RMS value of the array.Sample Input 1:
4
1 2 3 4
Output:
2.738613
Sample Input 2:
2
7 13
Output:
10.440307
<b>Explanation 1:</b>
Sum of squares = 1 + 4 + 9 + 16 = 30
Mean = 30 / 4 = 7.5
Taking a square root of 7.5 gives 2.738613
</b>Explanation 2:</b>
Sum of squares = 49 + 169 = 218
Mean = 218 / 2 = 109
Taking the square root of 109 gives 10.440307, I have written this Solution Code: try:
n=int(input())
a=[int(x)**2 for x in input().split()]
s=sum(a)/n
r=s**(1/2)
print('%.6f' % r)
except EOFError as e:
pass, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N. You need to find the root mean square (RMS) of the array i. e you first need to square all values of array and take its mean. Then you need to return the square root of mean. Print the answer with precision upto 6 decimal places.The first line contains an integer N - the size of the array
The next line contains N space-separated integers - the elements of the array.
<b>Constraints:</b>
1 <= N <= 100
1 <= Ai <= 100Print the RMS value of the array.Sample Input 1:
4
1 2 3 4
Output:
2.738613
Sample Input 2:
2
7 13
Output:
10.440307
<b>Explanation 1:</b>
Sum of squares = 1 + 4 + 9 + 16 = 30
Mean = 30 / 4 = 7.5
Taking a square root of 7.5 gives 2.738613
</b>Explanation 2:</b>
Sum of squares = 49 + 169 = 218
Mean = 218 / 2 = 109
Taking the square root of 109 gives 10.440307, I have written this Solution Code: /*package whatever //do not write package name here */
import java.io.*;
import java.util.Scanner;
import java.lang.Math;
class Main {
public static void main (String[] args) {
int n;
Scanner s = new Scanner(System.in);
n = s.nextInt();
double x=0;
double sum=0;
for(int i=0;i<n;i++){
x=s.nextDouble();
sum+=x*x;
}
sum/=n;
sum=Math.sqrt(sum);
System.out.printf("%.6f",sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rick's family and Jerry are playing Tic Tac Toe. Rules are simple:
<li> Game is played in pairs.
<li> If Rick plays against anyone, Rick wins.
<li> If Jerry plays against anyone, Jerry Loses.
<li> A game between any other players is a draw.
Given a pair of players, find who wins the game or if the game is draw.Input Contains two space separated characters denoting the players that will have the match.
R denotes Rick.
J denotes Jerry.
B denotes Beth.
M denotes Morty.
S denotes Summer.If the game is draw print 'D', else print the first letter of the name of the player who wins in capital.Sample Input 1
R S
Sample Output 1
R
Sample Input 2
B J
Sample Output 2
B
Sample Input 3
M S
Sample Output 3
D, 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
char p1,p2;
cin>>p1>>p2;
if(p1=='R'||p2=='R')
cout<<"R";
else{
if(p1=='J')
cout<<p2;
else{
if(p2=='J')
cout<<p1;
else
cout<<"D";
}
}
#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: Rick's family and Jerry are playing Tic Tac Toe. Rules are simple:
<li> Game is played in pairs.
<li> If Rick plays against anyone, Rick wins.
<li> If Jerry plays against anyone, Jerry Loses.
<li> A game between any other players is a draw.
Given a pair of players, find who wins the game or if the game is draw.Input Contains two space separated characters denoting the players that will have the match.
R denotes Rick.
J denotes Jerry.
B denotes Beth.
M denotes Morty.
S denotes Summer.If the game is draw print 'D', else print the first letter of the name of the player who wins in capital.Sample Input 1
R S
Sample Output 1
R
Sample Input 2
B J
Sample Output 2
B
Sample Input 3
M S
Sample Output 3
D, I have written this Solution Code: a,b=input().split()
if(a=="R" or b=="R"):
print("R")
elif(a=="J" or b=="J"):
if(a=="J"):
print(b)
else:
print(a)
else:
print("D"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rick's family and Jerry are playing Tic Tac Toe. Rules are simple:
<li> Game is played in pairs.
<li> If Rick plays against anyone, Rick wins.
<li> If Jerry plays against anyone, Jerry Loses.
<li> A game between any other players is a draw.
Given a pair of players, find who wins the game or if the game is draw.Input Contains two space separated characters denoting the players that will have the match.
R denotes Rick.
J denotes Jerry.
B denotes Beth.
M denotes Morty.
S denotes Summer.If the game is draw print 'D', else print the first letter of the name of the player who wins in capital.Sample Input 1
R S
Sample Output 1
R
Sample Input 2
B J
Sample Output 2
B
Sample Input 3
M S
Sample Output 3
D, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
String[] rowcol = rd.readLine().split(" ");
String name = rowcol[0];
String name2 = rowcol[1];
if(name.equals("R")|| name2.equals("R")){
System.out.print('R');
return;
}
else if(name.equals("J")){
System.out.print(name2);
return;
}else if(name2.equals("J")){
System.out.print(name);
return;
}
else if(!name.equals("R") && !name.equals("J")){
System.out.print('D');
return;
}
else if(!name2.equals("J") && !name2.equals("R")){
System.out.print('D');
return;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Abhijit has an Array <b>Arr</b> which may or may not be in strictly increasing order. He wants to make this array increasing but does not wish to change the position of any element so he came with an idea that he will replace an element with any of its divisors i.e <b> he changes an element X to M if X%M=0.</b>
Your task is to tell whether the given array can be transformed to <b>strictly increasing</b> by performing the operation given above.First line of input contains the size of the array N. Next line of input contains N space- separated integers depicting the values of the array Arr.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print "YES" if the array can be transformed in the strictly increasing order else print "NO".Sample Input:-
5
1 2 16 16 16
Sample Output:-
YES
Sample Input:-
4
1 3 8 4
Sample Output:-
NO, I have written this Solution Code: // arr is the array of numbers, n is the number fo elements
function increaseArray(arr, n) {
// write code here
// do not console.log
// return "YES" or "NO"
let cnt = 2;
for (let i = 1; i < n; i++) {
while (cnt <= arr[i] && arr[i] % cnt != 0) {
cnt++;
}
if (cnt > arr[i]) { return "NO" }
cnt++;
}
return "YES"
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Abhijit has an Array <b>Arr</b> which may or may not be in strictly increasing order. He wants to make this array increasing but does not wish to change the position of any element so he came with an idea that he will replace an element with any of its divisors i.e <b> he changes an element X to M if X%M=0.</b>
Your task is to tell whether the given array can be transformed to <b>strictly increasing</b> by performing the operation given above.First line of input contains the size of the array N. Next line of input contains N space- separated integers depicting the values of the array Arr.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print "YES" if the array can be transformed in the strictly increasing order else print "NO".Sample Input:-
5
1 2 16 16 16
Sample Output:-
YES
Sample Input:-
4
1 3 8 4
Sample Output:-
NO, I have written this Solution Code: #include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];}
int cnt=2;
for(int i=1;i<n;i++){
while(cnt<=a[i] && a[i]%cnt!=0){
cnt++;}
if(cnt>a[i]){cout<<"NO";return 0;}
cnt++;
}
cout<<"YES";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Abhijit has an Array <b>Arr</b> which may or may not be in strictly increasing order. He wants to make this array increasing but does not wish to change the position of any element so he came with an idea that he will replace an element with any of its divisors i.e <b> he changes an element X to M if X%M=0.</b>
Your task is to tell whether the given array can be transformed to <b>strictly increasing</b> by performing the operation given above.First line of input contains the size of the array N. Next line of input contains N space- separated integers depicting the values of the array Arr.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print "YES" if the array can be transformed in the strictly increasing order else print "NO".Sample Input:-
5
1 2 16 16 16
Sample Output:-
YES
Sample Input:-
4
1 3 8 4
Sample Output:-
NO, I have written this Solution Code: n = int(input())
lst = list(map(int, input().split()))
count = 1
ls = []
for i in range(n):
if (lst[i]%count == 0):
lst[i] = count
ls.append(lst[i])
count += 1
change = 0
while( count > lst[i-1] and count <= lst[i]):
if (lst[i]%count == 0) :
lst[i] = count
change = 1
ls.append(lst[i])
count += 1
break
else:
count += 1
if len(ls) == n:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Abhijit has an Array <b>Arr</b> which may or may not be in strictly increasing order. He wants to make this array increasing but does not wish to change the position of any element so he came with an idea that he will replace an element with any of its divisors i.e <b> he changes an element X to M if X%M=0.</b>
Your task is to tell whether the given array can be transformed to <b>strictly increasing</b> by performing the operation given above.First line of input contains the size of the array N. Next line of input contains N space- separated integers depicting the values of the array Arr.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print "YES" if the array can be transformed in the strictly increasing order else print "NO".Sample Input:-
5
1 2 16 16 16
Sample Output:-
YES
Sample Input:-
4
1 3 8 4
Sample Output:-
NO, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String str[] = br.readLine().split(" ");
boolean flag=true;
int arr[] = new int[n];
for(int i=0;i<n;i++)
arr[i]=Integer.parseInt(str[i]);
arr[0]=1;
int j=2;
for(int i=1;i<n;i++){
if(arr[i]%j==0)
j=j+1;
else if((arr[i]%j)!=0 && (arr[i]/j)>=1){
int fight=1;
while(fight==1){
for(int x=j+1;x<=arr[i];x++){
if(arr[i]%x==0){
j=x+1;
fight=0;
break;
}
else
fight=1;
}
}
}
else
flag=false;
}
if(flag)
System.out.println("YES");
else
System.out.println("NO");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has an MCQ exam containing 100 questions this sunday but she isn't prepared. She came to know that in her exam
- >P number of Questions will have A as the correct option
- >Q number of Questions will have B as the correct option
- >R number of Questions will have C as the correct option
- >S number of Questions will have D as the correct option
Sara doesn't know the order of the questions. If Sara filled the MCQs optimally (same option for each question) using the above information what will be the maximum marks she can get.The input contains 4 integers P, Q, R, and S.
Constraints:-
0 <= P, Q, R, S <= 100
Note:- P + Q + R + S will always be 100Print the maximum marks Sara can get.Sample Input:-
8 10 20 62
Sample Output:-
62, 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().toString();
String str[] = s.split(" ");
int P = Integer.parseInt(str[0]);
int Q = Integer.parseInt(str[1]);
int R = Integer.parseInt(str[2]);
int S = Integer.parseInt(str[3]);
if(P>=Q && P>=R && P>=S)
System.out.println(P);
else if(Q>=P && Q>=R && Q>=S)
System.out.println(Q);
else if(R>=P && R>=Q && R>=S)
System.out.println(R);
else
System.out.println(S);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has an MCQ exam containing 100 questions this sunday but she isn't prepared. She came to know that in her exam
- >P number of Questions will have A as the correct option
- >Q number of Questions will have B as the correct option
- >R number of Questions will have C as the correct option
- >S number of Questions will have D as the correct option
Sara doesn't know the order of the questions. If Sara filled the MCQs optimally (same option for each question) using the above information what will be the maximum marks she can get.The input contains 4 integers P, Q, R, and S.
Constraints:-
0 <= P, Q, R, S <= 100
Note:- P + Q + R + S will always be 100Print the maximum marks Sara can get.Sample Input:-
8 10 20 62
Sample Output:-
62, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<max(a,max(b,max(c,d)));
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has an MCQ exam containing 100 questions this sunday but she isn't prepared. She came to know that in her exam
- >P number of Questions will have A as the correct option
- >Q number of Questions will have B as the correct option
- >R number of Questions will have C as the correct option
- >S number of Questions will have D as the correct option
Sara doesn't know the order of the questions. If Sara filled the MCQs optimally (same option for each question) using the above information what will be the maximum marks she can get.The input contains 4 integers P, Q, R, and S.
Constraints:-
0 <= P, Q, R, S <= 100
Note:- P + Q + R + S will always be 100Print the maximum marks Sara can get.Sample Input:-
8 10 20 62
Sample Output:-
62, I have written this Solution Code: print(max(list(map(int, input().strip().split(" "))))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We need a problem on xor again. Given an array A of N integers (1- indexed), you need to find the sum of (N- i) xor A[i] for all i from 1 to N.The first line of the input contains an integer N, the number of elements of the array.
The second line of the input contains N singly spaced integers of the array A[i].
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ A[i] ≤ 10<sup>9</sup>Output a single integer, the answer to the problem.Sample Input
5
1 2 3 4 5
Sample Output
17
Explanation
(5-1)xor1 = 5, (5-2)xor2 = 1, (5-3)xor3 = 1, (5-4)xor4 = 5, (5-5)xor5 = 5.
Sample Input
5
1 1 0 4 6
Sample Output
20, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
void xorOps(int n, long[] input){
long res=0;
for(int i=0;i<n;i++){
long temp = (n-(i+1))^(input[i]);
res=res+temp;
}
System.out.print(res);
}
public static void main (String[] args)throws java.lang.Exception {
Main obj = new Main();
BufferedReader br = new BufferedReader(new InputStreamReader
(System.in));
int n = Integer.parseInt(br.readLine());
String[] raw_input= br.readLine().split(" ");
long[] input = new long[n];
for(int i=0; i<n;i++){
input[i]=Long.parseLong(raw_input[i]);
}
obj.xorOps(n,input);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We need a problem on xor again. Given an array A of N integers (1- indexed), you need to find the sum of (N- i) xor A[i] for all i from 1 to N.The first line of the input contains an integer N, the number of elements of the array.
The second line of the input contains N singly spaced integers of the array A[i].
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ A[i] ≤ 10<sup>9</sup>Output a single integer, the answer to the problem.Sample Input
5
1 2 3 4 5
Sample Output
17
Explanation
(5-1)xor1 = 5, (5-2)xor2 = 1, (5-3)xor3 = 1, (5-4)xor4 = 5, (5-5)xor5 = 5.
Sample Input
5
1 1 0 4 6
Sample Output
20, I have written this Solution Code: n=int(input())
g=map(int,input().split())
count=0
i=0
while i<n:
for j in (g):
i=i+1
t=((n-i)^j)
count=count+t
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We need a problem on xor again. Given an array A of N integers (1- indexed), you need to find the sum of (N- i) xor A[i] for all i from 1 to N.The first line of the input contains an integer N, the number of elements of the array.
The second line of the input contains N singly spaced integers of the array A[i].
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ A[i] ≤ 10<sup>9</sup>Output a single integer, the answer to the problem.Sample Input
5
1 2 3 4 5
Sample Output
17
Explanation
(5-1)xor1 = 5, (5-2)xor2 = 1, (5-3)xor3 = 1, (5-4)xor4 = 5, (5-5)xor5 = 5.
Sample Input
5
1 1 0 4 6
Sample Output
20, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
int ans = 0;
For(i, 1, n+1){
int a; cin>>a;
ans += (a^(n-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: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<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>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: static int Help(int N, int M){
if(N%M==0){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<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>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: function Help(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const ans = (n % m === 0) ? 1 : 0
return ans
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<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>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: def Help(N,M):
if N%M==0:
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<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>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code:
int Help(int N, int M){
return N%M==0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<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>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code:
int Help(int N, int M){
return N%M==0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We need a problem on xor again. Given an array A of N integers (1- indexed), you need to find the sum of (N- i) xor A[i] for all i from 1 to N.The first line of the input contains an integer N, the number of elements of the array.
The second line of the input contains N singly spaced integers of the array A[i].
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ A[i] ≤ 10<sup>9</sup>Output a single integer, the answer to the problem.Sample Input
5
1 2 3 4 5
Sample Output
17
Explanation
(5-1)xor1 = 5, (5-2)xor2 = 1, (5-3)xor3 = 1, (5-4)xor4 = 5, (5-5)xor5 = 5.
Sample Input
5
1 1 0 4 6
Sample Output
20, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
void xorOps(int n, long[] input){
long res=0;
for(int i=0;i<n;i++){
long temp = (n-(i+1))^(input[i]);
res=res+temp;
}
System.out.print(res);
}
public static void main (String[] args)throws java.lang.Exception {
Main obj = new Main();
BufferedReader br = new BufferedReader(new InputStreamReader
(System.in));
int n = Integer.parseInt(br.readLine());
String[] raw_input= br.readLine().split(" ");
long[] input = new long[n];
for(int i=0; i<n;i++){
input[i]=Long.parseLong(raw_input[i]);
}
obj.xorOps(n,input);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We need a problem on xor again. Given an array A of N integers (1- indexed), you need to find the sum of (N- i) xor A[i] for all i from 1 to N.The first line of the input contains an integer N, the number of elements of the array.
The second line of the input contains N singly spaced integers of the array A[i].
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ A[i] ≤ 10<sup>9</sup>Output a single integer, the answer to the problem.Sample Input
5
1 2 3 4 5
Sample Output
17
Explanation
(5-1)xor1 = 5, (5-2)xor2 = 1, (5-3)xor3 = 1, (5-4)xor4 = 5, (5-5)xor5 = 5.
Sample Input
5
1 1 0 4 6
Sample Output
20, I have written this Solution Code: n=int(input())
g=map(int,input().split())
count=0
i=0
while i<n:
for j in (g):
i=i+1
t=((n-i)^j)
count=count+t
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We need a problem on xor again. Given an array A of N integers (1- indexed), you need to find the sum of (N- i) xor A[i] for all i from 1 to N.The first line of the input contains an integer N, the number of elements of the array.
The second line of the input contains N singly spaced integers of the array A[i].
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ A[i] ≤ 10<sup>9</sup>Output a single integer, the answer to the problem.Sample Input
5
1 2 3 4 5
Sample Output
17
Explanation
(5-1)xor1 = 5, (5-2)xor2 = 1, (5-3)xor3 = 1, (5-4)xor4 = 5, (5-5)xor5 = 5.
Sample Input
5
1 1 0 4 6
Sample Output
20, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
int ans = 0;
For(i, 1, n+1){
int a; cin>>a;
ans += (a^(n-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 a singly linked list, delete middle node of the linked list. For example, if given linked list is 1->2->3->4->5 then linked list should be modified to 1->2->4->5.
If there are even nodes, then there would be two middle nodes, we need to delete the second middle element. For example, if given linked list is 1->2->3->4->5->6 then it should be modified to 1->2->3->5->6.
In case of a single node return the head of a linked list containing only 1 node which has value -1<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>deleteMiddleElement()</b> that takes head node of the linked list as parameter.
Constraints:
1 <=N<= 1000
1 <=value<= 1000
Return the head of the modified linked listSample Input 1:
5
1 2 3 4 5
Sample Output:
1 2 4 5
Explanation: After deleting middle of the linked list, 3 will be deleted and the list will be as 1, 2, 4, 5.
Sample Input 2:
6
1 2 3 4 5 6
Sample Output:-
1 2 3 5 6
, I have written this Solution Code: public static Node deleteMiddleElement(Node head) {
int cnt=0;
Node temp=head;
while(temp!=null){
cnt++;
temp=temp.next;
}
if(cnt==1){
head.val=-1;
return head;
}
if(cnt==2){
head.next=null;
return head;
}
temp=head;
int I=1;
cnt=cnt/2;
while(I!=cnt){
temp=temp.next;
I++;
}
temp.next=temp.next.next;
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N integers, your task is to print the sum of elements present at even places and print the product of elements present at the odd places.
Note:- Consider the first element to start from 1.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 50
1 <= Arr[i] <= 5Print the sum of elements present at even places and print the product of elements present at the odd places separated by a space.Sample Input:-
5
1 2 3 4 5
Sample Output:-
6 15
Explanation:-
Sum = 2 + 4
Product = 1*3*5
Sample Input:-
2
4 6
Sample Output:-
6 4, I have written this Solution Code: function altSumProduct(arr, n) {
let sum = 0;
let prod = 1;
arr.forEach((el, idx) => {
if (idx % 2 !== 0) {
sum += el
} else {
prod *= el
}
})
console.log(`${sum} ${prod}`)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N integers, your task is to print the sum of elements present at even places and print the product of elements present at the odd places.
Note:- Consider the first element to start from 1.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 50
1 <= Arr[i] <= 5Print the sum of elements present at even places and print the product of elements present at the odd places separated by a space.Sample Input:-
5
1 2 3 4 5
Sample Output:-
6 15
Explanation:-
Sum = 2 + 4
Product = 1*3*5
Sample Input:-
2
4 6
Sample Output:-
6 4, 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 Arr[] = new int[n];
for(int i=0;i<n;i++){
Arr[i] = sc.nextInt();
}
int sum=0;
int product=1;
for(int i=0;i<n;i++){
if(i%2==0){
product*=Arr[i];
}
else{
sum+=Arr[i];
}
}
System.out.print(sum+" "+product);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N integers, your task is to print the sum of elements present at even places and print the product of elements present at the odd places.
Note:- Consider the first element to start from 1.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 50
1 <= Arr[i] <= 5Print the sum of elements present at even places and print the product of elements present at the odd places separated by a space.Sample Input:-
5
1 2 3 4 5
Sample Output:-
6 15
Explanation:-
Sum = 2 + 4
Product = 1*3*5
Sample Input:-
2
4 6
Sample Output:-
6 4, I have written this Solution Code: def EvenOddSum(a, n):
even = 0
odd = 1
for i in range(0,n):
if i % 2 == 0:
odd *= a[i]
else:
even += a[i]
print (even,odd)
n = input()
n=int(n)
arr = [int(i) for i in input().split()]
EvenOddSum(arr, n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N. You need to find the root mean square (RMS) of the array i. e you first need to square all values of array and take its mean. Then you need to return the square root of mean. Print the answer with precision upto 6 decimal places.The first line contains an integer N - the size of the array
The next line contains N space-separated integers - the elements of the array.
<b>Constraints:</b>
1 <= N <= 100
1 <= Ai <= 100Print the RMS value of the array.Sample Input 1:
4
1 2 3 4
Output:
2.738613
Sample Input 2:
2
7 13
Output:
10.440307
<b>Explanation 1:</b>
Sum of squares = 1 + 4 + 9 + 16 = 30
Mean = 30 / 4 = 7.5
Taking a square root of 7.5 gives 2.738613
</b>Explanation 2:</b>
Sum of squares = 49 + 169 = 218
Mean = 218 / 2 = 109
Taking the square root of 109 gives 10.440307, I have written this Solution Code: try:
n=int(input())
a=[int(x)**2 for x in input().split()]
s=sum(a)/n
r=s**(1/2)
print('%.6f' % r)
except EOFError as e:
pass, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N. You need to find the root mean square (RMS) of the array i. e you first need to square all values of array and take its mean. Then you need to return the square root of mean. Print the answer with precision upto 6 decimal places.The first line contains an integer N - the size of the array
The next line contains N space-separated integers - the elements of the array.
<b>Constraints:</b>
1 <= N <= 100
1 <= Ai <= 100Print the RMS value of the array.Sample Input 1:
4
1 2 3 4
Output:
2.738613
Sample Input 2:
2
7 13
Output:
10.440307
<b>Explanation 1:</b>
Sum of squares = 1 + 4 + 9 + 16 = 30
Mean = 30 / 4 = 7.5
Taking a square root of 7.5 gives 2.738613
</b>Explanation 2:</b>
Sum of squares = 49 + 169 = 218
Mean = 218 / 2 = 109
Taking the square root of 109 gives 10.440307, I have written this Solution Code: /*package whatever //do not write package name here */
import java.io.*;
import java.util.Scanner;
import java.lang.Math;
class Main {
public static void main (String[] args) {
int n;
Scanner s = new Scanner(System.in);
n = s.nextInt();
double x=0;
double sum=0;
for(int i=0;i<n;i++){
x=s.nextDouble();
sum+=x*x;
}
sum/=n;
sum=Math.sqrt(sum);
System.out.printf("%.6f",sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the Nth number in the fibonacci series. Consider 0 and 1 to be the seed values.
In the fibonacci series, each number (Fibonacci number) is the sum of the two preceding numbers. The series with 0 and 1 as seed values will go like -
0, 1, 1, 2, 3, 5 and so on..<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>Fibonacci()</b> that takes the integer N as a parameter.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 30Return the Nth Fibonacci number.Sample Input
2
3
5
Sample Output
2
5
Explaination:
Test case 1-> N = 2
Seed values are 0 and 1
So, F<sub>1</sub> = 0 + 1 = 1
F<sub>2</sub> = 1 + F<sub>1</sub> = 1 + 1 = 2, I have written this Solution Code: static long Fibonacci(long n)
{
if (n == 0)
{ return 0;}
else if(n==1){
return 1;
}
return Fibonacci(n-1) + Fibonacci(n-2);
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the Nth number in the fibonacci series. Consider 0 and 1 to be the seed values.
In the fibonacci series, each number (Fibonacci number) is the sum of the two preceding numbers. The series with 0 and 1 as seed values will go like -
0, 1, 1, 2, 3, 5 and so on..<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>Fibonacci()</b> that takes the integer N as a parameter.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 30Return the Nth Fibonacci number.Sample Input
2
3
5
Sample Output
2
5
Explaination:
Test case 1-> N = 2
Seed values are 0 and 1
So, F<sub>1</sub> = 0 + 1 = 1
F<sub>2</sub> = 1 + F<sub>1</sub> = 1 + 1 = 2, I have written this Solution Code: // n is the input number
function fibonacci(n) {
// write code here
// do not console.log
// return the answer as a number
if (n == 1 || n == 0) return n;
return fibonacci(n-2) + fibonacci(n-1)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, find the value of the below equation for the given number.
Equation: -
N
∑ {(X + 1)<sup>2</sup> - (3X + 1) + X}
X = 1<b>User task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 10^5You need to return the sum of the equationSample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
5
Explanation:-
For test 2:- (1+1)^2 - (3*1+1) + (1) + (2+1)^2 - (3*2+1) +2
= 4 - 4 +1 + 9 -7 +2
= 5, I have written this Solution Code: def equationSum(N) :
re=N*(N+1)
re=re*(2*N+1)
re=re//6
return re, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, find the value of the below equation for the given number.
Equation: -
N
∑ {(X + 1)<sup>2</sup> - (3X + 1) + X}
X = 1<b>User task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 10^5You need to return the sum of the equationSample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
5
Explanation:-
For test 2:- (1+1)^2 - (3*1+1) + (1) + (2+1)^2 - (3*2+1) +2
= 4 - 4 +1 + 9 -7 +2
= 5, I have written this Solution Code: long long equationSum(long long N){
long long ans = (N*(N+1)*(2*N+1))/6;
return ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, find the value of the below equation for the given number.
Equation: -
N
∑ {(X + 1)<sup>2</sup> - (3X + 1) + X}
X = 1<b>User task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 10^5You need to return the sum of the equationSample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
5
Explanation:-
For test 2:- (1+1)^2 - (3*1+1) + (1) + (2+1)^2 - (3*2+1) +2
= 4 - 4 +1 + 9 -7 +2
= 5, I have written this Solution Code: long long int equationSum(long long N){
long long ans = (N*(N+1)*(2*N+1))/6;
return ans;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, find the value of the below equation for the given number.
Equation: -
N
∑ {(X + 1)<sup>2</sup> - (3X + 1) + X}
X = 1<b>User task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 10^5You need to return the sum of the equationSample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
5
Explanation:-
For test 2:- (1+1)^2 - (3*1+1) + (1) + (2+1)^2 - (3*2+1) +2
= 4 - 4 +1 + 9 -7 +2
= 5, I have written this Solution Code: static long equationSum(long N)
{
return (N*(N+1)*(2*N + 1))/6;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mahesh has won some money K from a lottery, he wants to distribute the money among his three sisters. His sisters already have some money with them. Let's say they have x, y, z amount of money. Now mahesh wants to distribute his money such that all the sisters have the same amount of total money left with them. Your task is to check if it is possible to distribute the money as Mahesh wants.<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>distributingMoney()</b> that takes the integers x, y, z, and K as parameters.
<b>Constraints:-</b>
0 <= x, y, z, K <= 10^7Return 1 if possible else return 0.Sample Input:-
1 2 3 3
Sample Output:-
1
Explanation:-
initial :- 1 2 3
Final :- 3 3 3
Sample Input:-
1 2 3 4
Sample Output:-
0, I have written this Solution Code:
def distributingMoney(x,y,z,k) :
# Final result of summation of divisors
result = x+y+z+k;
if result%3!=0:
return 0
result =result/3
if result<x or result<y or result<z:
return 0
return 1;
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mahesh has won some money K from a lottery, he wants to distribute the money among his three sisters. His sisters already have some money with them. Let's say they have x, y, z amount of money. Now mahesh wants to distribute his money such that all the sisters have the same amount of total money left with them. Your task is to check if it is possible to distribute the money as Mahesh wants.<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>distributingMoney()</b> that takes the integers x, y, z, and K as parameters.
<b>Constraints:-</b>
0 <= x, y, z, K <= 10^7Return 1 if possible else return 0.Sample Input:-
1 2 3 3
Sample Output:-
1
Explanation:-
initial :- 1 2 3
Final :- 3 3 3
Sample Input:-
1 2 3 4
Sample Output:-
0, I have written this Solution Code: int distributingMoney(long x, long y, long z,long k){
long long sum=x+y+z+k;
if(sum%3!=0){return 0;}
sum=sum/3;
if(x>sum || y>sum || z>sum){return 0;}
return 1;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mahesh has won some money K from a lottery, he wants to distribute the money among his three sisters. His sisters already have some money with them. Let's say they have x, y, z amount of money. Now mahesh wants to distribute his money such that all the sisters have the same amount of total money left with them. Your task is to check if it is possible to distribute the money as Mahesh wants.<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>distributingMoney()</b> that takes the integers x, y, z, and K as parameters.
<b>Constraints:-</b>
0 <= x, y, z, K <= 10^7Return 1 if possible else return 0.Sample Input:-
1 2 3 3
Sample Output:-
1
Explanation:-
initial :- 1 2 3
Final :- 3 3 3
Sample Input:-
1 2 3 4
Sample Output:-
0, I have written this Solution Code: public static int distributingMoney(long x, long y, long z, long K){
long sum=0;
sum+=x+y+z+K;
if(sum%3!=0){return 0;}
sum=sum/3;
if(x>sum || y>sum || z>sum){return 0;}
return 1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mahesh has won some money K from a lottery, he wants to distribute the money among his three sisters. His sisters already have some money with them. Let's say they have x, y, z amount of money. Now mahesh wants to distribute his money such that all the sisters have the same amount of total money left with them. Your task is to check if it is possible to distribute the money as Mahesh wants.<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>distributingMoney()</b> that takes the integers x, y, z, and K as parameters.
<b>Constraints:-</b>
0 <= x, y, z, K <= 10^7Return 1 if possible else return 0.Sample Input:-
1 2 3 3
Sample Output:-
1
Explanation:-
initial :- 1 2 3
Final :- 3 3 3
Sample Input:-
1 2 3 4
Sample Output:-
0, I have written this Solution Code: int distributingMoney(long x, long y, long z,long k){
long int sum=x+y+z+k;
if(sum%3!=0){return 0;}
sum=sum/3;
if(x>sum || y>sum || z>sum){return 0;}
return 1;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, 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;
void print(int dn, int from, int to){
cout << dn << ":" << (char)('A'+from-1) << "->" << (char)('A'+to-1) << endl;
}
void rec(int n, int src, int des, int aux){
if(n == 0)
return;
rec(n-1, src, aux, des);
print(n, src, des);
rec(n-1, aux, des, src);
}
signed main() {
IOS;
int n; cin >> n;
rec(n, 1, 3, 2);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: # Recursive Python function to solve the tower of hanoi
def TowerOfHanoi(n , source, destination, auxiliary):
if n==1:
#print ("1:",source,"->",destination)
print("1:%s->%s"%(source,destination))
return
TowerOfHanoi(n-1, source, auxiliary, destination)
#print (n,"%d:",source,"->",destination)
print("%d:%s->%s"%(n,source,destination))
TowerOfHanoi(n-1, auxiliary, destination, source)
# Driver code
n = int(input())
TowerOfHanoi(n,'A','C','B'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: // n is the number of disks
function towerOfHanoiSequence(n) {
// write code here
// console.log the seqence steps
function towerOfHanoi(n, from_rod, to_rod, aux_rod) {
if (n == 0) {
return;
}
towerOfHanoi(n - 1, from_rod, aux_rod, to_rod);
console.log(`${n}:${from_rod}->${to_rod}`)
towerOfHanoi(n - 1, aux_rod, to_rod, from_rod);
}
towerOfHanoi(n,'A','C','B')
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
{
if (n == 1)
{
System.out.println("1:" + from_rod + "->" + to_rod);
return;
}
towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
System.out.println(n + ":" + from_rod + "->" + to_rod);
towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
towerOfHanoi(n, 'A', 'C', 'B');
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the Nth number in the fibonacci series. Consider 0 and 1 to be the seed values.
In the fibonacci series, each number (Fibonacci number) is the sum of the two preceding numbers. The series with 0 and 1 as seed values will go like -
0, 1, 1, 2, 3, 5 and so on..<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>Fibonacci()</b> that takes the integer N as a parameter.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 30Return the Nth Fibonacci number.Sample Input
2
3
5
Sample Output
2
5
Explaination:
Test case 1-> N = 2
Seed values are 0 and 1
So, F<sub>1</sub> = 0 + 1 = 1
F<sub>2</sub> = 1 + F<sub>1</sub> = 1 + 1 = 2, I have written this Solution Code: static long Fibonacci(long n)
{
if (n == 0)
{ return 0;}
else if(n==1){
return 1;
}
return Fibonacci(n-1) + Fibonacci(n-2);
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the Nth number in the fibonacci series. Consider 0 and 1 to be the seed values.
In the fibonacci series, each number (Fibonacci number) is the sum of the two preceding numbers. The series with 0 and 1 as seed values will go like -
0, 1, 1, 2, 3, 5 and so on..<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>Fibonacci()</b> that takes the integer N as a parameter.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 30Return the Nth Fibonacci number.Sample Input
2
3
5
Sample Output
2
5
Explaination:
Test case 1-> N = 2
Seed values are 0 and 1
So, F<sub>1</sub> = 0 + 1 = 1
F<sub>2</sub> = 1 + F<sub>1</sub> = 1 + 1 = 2, I have written this Solution Code: // n is the input number
function fibonacci(n) {
// write code here
// do not console.log
// return the answer as a number
if (n == 1 || n == 0) return n;
return fibonacci(n-2) + fibonacci(n-1)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to print the sum and mean (floor value) of 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>SumAndMean()</b> that takes the Array and the integer N as parameters.
<b>Constraints:-</b>
1 ≤ N ≤ 100
1 ≤ A[i] ≤ 100Print the Sum and the Mean of the array separated by a space.Sample Input:
5
1 2 19 28 5
Sample Output:
55 11
Sample Input:-
4
2 8 3 4
Sample Output:-
17 4
<b>Explanation:</b>
Test case 1: For an array of 5 elements, the sum is (1 + 2 + 19 + 28 + 5) = 55, mean is (1 + 2 + 19 + 28 + 5)/5 = 11. The mean is 11.
Test case 2: For an array of 4 elements, the sum is (2 + 8 + 3 + 4) = 17, and the mean is floor((2 + 8 + 3 + 4)/4) = 4. Mean is floor(17/4) = 4, I have written this Solution Code: // arr is the array of numbers, n is the number of elements
function sumAndMean(arr, n) {
// write code here
// do not console.log
// return the an array of two element where first element is sum and other is mean
const sum = arr.reduce((a, b) => a + b, 0)
return [sum, Math.floor(sum / n)]
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to print the sum and mean (floor value) of 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>SumAndMean()</b> that takes the Array and the integer N as parameters.
<b>Constraints:-</b>
1 ≤ N ≤ 100
1 ≤ A[i] ≤ 100Print the Sum and the Mean of the array separated by a space.Sample Input:
5
1 2 19 28 5
Sample Output:
55 11
Sample Input:-
4
2 8 3 4
Sample Output:-
17 4
<b>Explanation:</b>
Test case 1: For an array of 5 elements, the sum is (1 + 2 + 19 + 28 + 5) = 55, mean is (1 + 2 + 19 + 28 + 5)/5 = 11. The mean is 11.
Test case 2: For an array of 4 elements, the sum is (2 + 8 + 3 + 4) = 17, and the mean is floor((2 + 8 + 3 + 4)/4) = 4. Mean is floor(17/4) = 4, I have written this Solution Code: class Solution {
public static void SumAndMean(int arr[],int N){
int sum=0;
for(int i=0;i<N;i++){
sum+=arr[i];
}
System.out.print(sum + " " + sum/N);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to print the sum and mean (floor value) of 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>SumAndMean()</b> that takes the Array and the integer N as parameters.
<b>Constraints:-</b>
1 ≤ N ≤ 100
1 ≤ A[i] ≤ 100Print the Sum and the Mean of the array separated by a space.Sample Input:
5
1 2 19 28 5
Sample Output:
55 11
Sample Input:-
4
2 8 3 4
Sample Output:-
17 4
<b>Explanation:</b>
Test case 1: For an array of 5 elements, the sum is (1 + 2 + 19 + 28 + 5) = 55, mean is (1 + 2 + 19 + 28 + 5)/5 = 11. The mean is 11.
Test case 2: For an array of 4 elements, the sum is (2 + 8 + 3 + 4) = 17, and the mean is floor((2 + 8 + 3 + 4)/4) = 4. Mean is floor(17/4) = 4, I have written this Solution Code: N = int(input())
inputString = input()
integerArr = inputString.split()
computedintegerArr = []
totalcomputedinteger = 0
for integer in integerArr:
computedintegerArr.append(int(integer))
for computedvalue in computedintegerArr:
totalcomputedinteger += computedvalue
print(totalcomputedinteger, totalcomputedinteger//N)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has an MCQ exam containing 100 questions this sunday but she isn't prepared. She came to know that in her exam
- >P number of Questions will have A as the correct option
- >Q number of Questions will have B as the correct option
- >R number of Questions will have C as the correct option
- >S number of Questions will have D as the correct option
Sara doesn't know the order of the questions. If Sara filled the MCQs optimally (same option for each question) using the above information what will be the maximum marks she can get.The input contains 4 integers P, Q, R, and S.
Constraints:-
0 <= P, Q, R, S <= 100
Note:- P + Q + R + S will always be 100Print the maximum marks Sara can get.Sample Input:-
8 10 20 62
Sample Output:-
62, 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().toString();
String str[] = s.split(" ");
int P = Integer.parseInt(str[0]);
int Q = Integer.parseInt(str[1]);
int R = Integer.parseInt(str[2]);
int S = Integer.parseInt(str[3]);
if(P>=Q && P>=R && P>=S)
System.out.println(P);
else if(Q>=P && Q>=R && Q>=S)
System.out.println(Q);
else if(R>=P && R>=Q && R>=S)
System.out.println(R);
else
System.out.println(S);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has an MCQ exam containing 100 questions this sunday but she isn't prepared. She came to know that in her exam
- >P number of Questions will have A as the correct option
- >Q number of Questions will have B as the correct option
- >R number of Questions will have C as the correct option
- >S number of Questions will have D as the correct option
Sara doesn't know the order of the questions. If Sara filled the MCQs optimally (same option for each question) using the above information what will be the maximum marks she can get.The input contains 4 integers P, Q, R, and S.
Constraints:-
0 <= P, Q, R, S <= 100
Note:- P + Q + R + S will always be 100Print the maximum marks Sara can get.Sample Input:-
8 10 20 62
Sample Output:-
62, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<max(a,max(b,max(c,d)));
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has an MCQ exam containing 100 questions this sunday but she isn't prepared. She came to know that in her exam
- >P number of Questions will have A as the correct option
- >Q number of Questions will have B as the correct option
- >R number of Questions will have C as the correct option
- >S number of Questions will have D as the correct option
Sara doesn't know the order of the questions. If Sara filled the MCQs optimally (same option for each question) using the above information what will be the maximum marks she can get.The input contains 4 integers P, Q, R, and S.
Constraints:-
0 <= P, Q, R, S <= 100
Note:- P + Q + R + S will always be 100Print the maximum marks Sara can get.Sample Input:-
8 10 20 62
Sample Output:-
62, I have written this Solution Code: print(max(list(map(int, input().strip().split(" "))))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of positive integers. Your task is to sort them in such a way that the first part of the array contains odd numbers sorted in descending order, rest portion contains even numbers sorted in ascending order.First line of each test case contains an integer N denoting the size of the array. The next line contains N space separated values of the array.
<b>Constraints:</b>
1 <b>≤</b> N <b>≤</b> 10<sup>5</sup>
0 <b>≤</b> A[i] <b>≤</b> 10<sup>6</sup>Print the space separated values of the modified array.Sample Input
7
1 2 3 5 4 7 10
Sample Output
7 5 3 1 2 4 10
Sample Input
7
0 4 5 3 7 2 1
Sample Output
7 5 3 1 0 2 4, I have written this Solution Code: def two_way_sort(arr, arr_len):
l, r = 0, arr_len - 1
k = 0
while(l < r):
while(arr[l] % 2 != 0):
l += 1
k += 1
while(arr[r] % 2 == 0 and l < r):
r -= 1
if(l < r):
arr[l], arr[r] = arr[r], arr[l]
odd = arr[:k]
even = arr[k:]
odd.sort(reverse = True)
even.sort()
odd.extend(even)
return odd
n = int(input())
lst = input()
arr = lst.split()
for i in range(len(arr)):
arr[i] = int(arr[i])
result = two_way_sort(arr, n)
for i in result:
print(str(i), end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of positive integers. Your task is to sort them in such a way that the first part of the array contains odd numbers sorted in descending order, rest portion contains even numbers sorted in ascending order.First line of each test case contains an integer N denoting the size of the array. The next line contains N space separated values of the array.
<b>Constraints:</b>
1 <b>≤</b> N <b>≤</b> 10<sup>5</sup>
0 <b>≤</b> A[i] <b>≤</b> 10<sup>6</sup>Print the space separated values of the modified array.Sample Input
7
1 2 3 5 4 7 10
Sample Output
7 5 3 1 2 4 10
Sample Input
7
0 4 5 3 7 2 1
Sample Output
7 5 3 1 0 2 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> odd,even;
int a;
for(int i=0;i<n;i++){
cin>>a;
if(a&1){odd.emplace_back(a);}
else{
even.emplace_back(a);
}
}
sort(odd.begin(),odd.end());
sort(even.begin(),even.end());
for(int i=odd.size()-1;i>=0;i--){
cout<<odd[i]<<" ";
}
for(int i=0;i<even.size();i++){
cout<<even[i]<<" ";
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of positive integers. Your task is to sort them in such a way that the first part of the array contains odd numbers sorted in descending order, rest portion contains even numbers sorted in ascending order.First line of each test case contains an integer N denoting the size of the array. The next line contains N space separated values of the array.
<b>Constraints:</b>
1 <b>≤</b> N <b>≤</b> 10<sup>5</sup>
0 <b>≤</b> A[i] <b>≤</b> 10<sup>6</sup>Print the space separated values of the modified array.Sample Input
7
1 2 3 5 4 7 10
Sample Output
7 5 3 1 2 4 10
Sample Input
7
0 4 5 3 7 2 1
Sample Output
7 5 3 1 0 2 4, I have written this Solution Code: function sortEvenOdd(arr, arrSize)
{
var even = [];
var odd = [];
for(let i = 0; i < arrSize; ++i)
{
if((arr[i]) % 2 === 0)
even.push(arr[i]);
else
odd.push(arr[i]);
}
even.sort((x, y) => (x - y));
odd.sort((x, y) => (x - y));
let res = [];
for(let i = odd.length - 1; i >= 0; i--)
res.push(odd[i]);
for(let i = 0; i < even.length; i++)
res.push(even[i]);
return res;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of positive integers. Your task is to sort them in such a way that the first part of the array contains odd numbers sorted in descending order, rest portion contains even numbers sorted in ascending order.First line of each test case contains an integer N denoting the size of the array. The next line contains N space separated values of the array.
<b>Constraints:</b>
1 <b>≤</b> N <b>≤</b> 10<sup>5</sup>
0 <b>≤</b> A[i] <b>≤</b> 10<sup>6</sup>Print the space separated values of the modified array.Sample Input
7
1 2 3 5 4 7 10
Sample Output
7 5 3 1 2 4 10
Sample Input
7
0 4 5 3 7 2 1
Sample Output
7 5 3 1 0 2 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int n = Integer.parseInt(br.readLine());
long[] arr = new long[n];
String[] raw = br.readLine().split("\\s+");
int eCount = 0;
for (int i = 0; i < n; i++) {
long tmp = Long.parseLong(raw[i]);
if (tmp % 2 == 0) arr[i] = tmp;
else arr[i] = -tmp;
}
Arrays.sort(arr);
int k = 0;
while (arr[k] % 2 != 0) {
arr[k] = -arr[k];
k++;
}
for (int i = 0; i < n; i++)
pw.print(arr[i] + " ");
pw.println();
pw.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, 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;
void print(int dn, int from, int to){
cout << dn << ":" << (char)('A'+from-1) << "->" << (char)('A'+to-1) << endl;
}
void rec(int n, int src, int des, int aux){
if(n == 0)
return;
rec(n-1, src, aux, des);
print(n, src, des);
rec(n-1, aux, des, src);
}
signed main() {
IOS;
int n; cin >> n;
rec(n, 1, 3, 2);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: # Recursive Python function to solve the tower of hanoi
def TowerOfHanoi(n , source, destination, auxiliary):
if n==1:
#print ("1:",source,"->",destination)
print("1:%s->%s"%(source,destination))
return
TowerOfHanoi(n-1, source, auxiliary, destination)
#print (n,"%d:",source,"->",destination)
print("%d:%s->%s"%(n,source,destination))
TowerOfHanoi(n-1, auxiliary, destination, source)
# Driver code
n = int(input())
TowerOfHanoi(n,'A','C','B'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: // n is the number of disks
function towerOfHanoiSequence(n) {
// write code here
// console.log the seqence steps
function towerOfHanoi(n, from_rod, to_rod, aux_rod) {
if (n == 0) {
return;
}
towerOfHanoi(n - 1, from_rod, aux_rod, to_rod);
console.log(`${n}:${from_rod}->${to_rod}`)
towerOfHanoi(n - 1, aux_rod, to_rod, from_rod);
}
towerOfHanoi(n,'A','C','B')
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
{
if (n == 1)
{
System.out.println("1:" + from_rod + "->" + to_rod);
return;
}
towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
System.out.println(n + ":" + from_rod + "->" + to_rod);
towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
towerOfHanoi(n, 'A', 'C', 'B');
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, add 8 to it and then divide it by 3, take the modulus of the resulting value with 5 and then finally multiply it by 5. Display the final value of NYou don't have to worry about the input, you just have to complete the function <b>stepsExecute</b>
<b>Constraints</b>
1000 <= number <= 9999Print the final resultSample Input :
2345
Sample Output :
20, I have written this Solution Code: static void stepsExecute(int N){
System.out.println(((((N+8)/3)%5)*5));
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, add 8 to it and then divide it by 3, take the modulus of the resulting value with 5 and then finally multiply it by 5. Display the final value of NYou don't have to worry about the input, you just have to complete the function <b>stepsExecute</b>
<b>Constraints</b>
1000 <= number <= 9999Print the final resultSample Input :
2345
Sample Output :
20, I have written this Solution Code: a = int(input())
print((((a+8)//3)%5)*5), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<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>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: static int Help(int N, int M){
if(N%M==0){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<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>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: function Help(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const ans = (n % m === 0) ? 1 : 0
return ans
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<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>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: def Help(N,M):
if N%M==0:
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<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>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code:
int Help(int N, int M){
return N%M==0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<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>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code:
int Help(int N, int M){
return N%M==0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to print the sum and mean (floor value) of 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>SumAndMean()</b> that takes the Array and the integer N as parameters.
<b>Constraints:-</b>
1 ≤ N ≤ 100
1 ≤ A[i] ≤ 100Print the Sum and the Mean of the array separated by a space.Sample Input:
5
1 2 19 28 5
Sample Output:
55 11
Sample Input:-
4
2 8 3 4
Sample Output:-
17 4
<b>Explanation:</b>
Test case 1: For an array of 5 elements, the sum is (1 + 2 + 19 + 28 + 5) = 55, mean is (1 + 2 + 19 + 28 + 5)/5 = 11. The mean is 11.
Test case 2: For an array of 4 elements, the sum is (2 + 8 + 3 + 4) = 17, and the mean is floor((2 + 8 + 3 + 4)/4) = 4. Mean is floor(17/4) = 4, I have written this Solution Code: // arr is the array of numbers, n is the number of elements
function sumAndMean(arr, n) {
// write code here
// do not console.log
// return the an array of two element where first element is sum and other is mean
const sum = arr.reduce((a, b) => a + b, 0)
return [sum, Math.floor(sum / n)]
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to print the sum and mean (floor value) of 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>SumAndMean()</b> that takes the Array and the integer N as parameters.
<b>Constraints:-</b>
1 ≤ N ≤ 100
1 ≤ A[i] ≤ 100Print the Sum and the Mean of the array separated by a space.Sample Input:
5
1 2 19 28 5
Sample Output:
55 11
Sample Input:-
4
2 8 3 4
Sample Output:-
17 4
<b>Explanation:</b>
Test case 1: For an array of 5 elements, the sum is (1 + 2 + 19 + 28 + 5) = 55, mean is (1 + 2 + 19 + 28 + 5)/5 = 11. The mean is 11.
Test case 2: For an array of 4 elements, the sum is (2 + 8 + 3 + 4) = 17, and the mean is floor((2 + 8 + 3 + 4)/4) = 4. Mean is floor(17/4) = 4, I have written this Solution Code: class Solution {
public static void SumAndMean(int arr[],int N){
int sum=0;
for(int i=0;i<N;i++){
sum+=arr[i];
}
System.out.print(sum + " " + sum/N);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to print the sum and mean (floor value) of 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>SumAndMean()</b> that takes the Array and the integer N as parameters.
<b>Constraints:-</b>
1 ≤ N ≤ 100
1 ≤ A[i] ≤ 100Print the Sum and the Mean of the array separated by a space.Sample Input:
5
1 2 19 28 5
Sample Output:
55 11
Sample Input:-
4
2 8 3 4
Sample Output:-
17 4
<b>Explanation:</b>
Test case 1: For an array of 5 elements, the sum is (1 + 2 + 19 + 28 + 5) = 55, mean is (1 + 2 + 19 + 28 + 5)/5 = 11. The mean is 11.
Test case 2: For an array of 4 elements, the sum is (2 + 8 + 3 + 4) = 17, and the mean is floor((2 + 8 + 3 + 4)/4) = 4. Mean is floor(17/4) = 4, I have written this Solution Code: N = int(input())
inputString = input()
integerArr = inputString.split()
computedintegerArr = []
totalcomputedinteger = 0
for integer in integerArr:
computedintegerArr.append(int(integer))
for computedvalue in computedintegerArr:
totalcomputedinteger += computedvalue
print(totalcomputedinteger, totalcomputedinteger//N)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two numbers n1 and n2. You need to find the sum of the products of their corresponding digits. So, for a number n1= 6 and n2 = 34, you'll do (6*4)+(0*3) = 24.<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>sumOfProductOfDigits()</b> that takes the integers n1 and n2 as a parameter.
To custom test the function, provide input in the following manner:
1st line will contain the number of test cases, let's say t
Then there will be t lines, each line having two numbers n1 and n2, separated by space
Constraints:
1 <= T <= 100
0 <= n1, n2 <= 10^6Return the sum of product of corresponding digits of n1 and n2.Sample Input:
2
9 0
35 6798
Sample Output:
0
67
Explanation:-
For test 2:-
(8*5) + (9*3) + (7*0) + (6*0) = 67, I have written this Solution Code: function sumOfProductOfDigits(n1, n2)
{
if(n1 < 10 && n2 < 10)
return n1*n2;
return (n1%10)*(n2%10) + sumOfProductOfDigits(parseInt(n1/10), parseInt(n2/10));
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two numbers n1 and n2. You need to find the sum of the products of their corresponding digits. So, for a number n1= 6 and n2 = 34, you'll do (6*4)+(0*3) = 24.<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>sumOfProductOfDigits()</b> that takes the integers n1 and n2 as a parameter.
To custom test the function, provide input in the following manner:
1st line will contain the number of test cases, let's say t
Then there will be t lines, each line having two numbers n1 and n2, separated by space
Constraints:
1 <= T <= 100
0 <= n1, n2 <= 10^6Return the sum of product of corresponding digits of n1 and n2.Sample Input:
2
9 0
35 6798
Sample Output:
0
67
Explanation:-
For test 2:-
(8*5) + (9*3) + (7*0) + (6*0) = 67, I have written this Solution Code: public static int sumOfProductOfDigits(int n1, int n2)
{
if(n1 < 10 && n2 < 10)
return n1*n2;
return (n1%10)*(n2%10) + sumOfProductOfDigits(n1/10, n2/10);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two numbers n1 and n2. You need to find the sum of the products of their corresponding digits. So, for a number n1= 6 and n2 = 34, you'll do (6*4)+(0*3) = 24.<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>sumOfProductOfDigits()</b> that takes the integers n1 and n2 as a parameter.
To custom test the function, provide input in the following manner:
1st line will contain the number of test cases, let's say t
Then there will be t lines, each line having two numbers n1 and n2, separated by space
Constraints:
1 <= T <= 100
0 <= n1, n2 <= 10^6Return the sum of product of corresponding digits of n1 and n2.Sample Input:
2
9 0
35 6798
Sample Output:
0
67
Explanation:-
For test 2:-
(8*5) + (9*3) + (7*0) + (6*0) = 67, I have written this Solution Code: def calc(n1,n2):
suma = 0
while n1> 0 or n2>0:
digit1 = n1% 10
digit2 = n2%10
p1=digit1*digit2
suma = suma + p1
n1 = n1 // 10
n2 = n2 // 10
return suma
t=int(input())
while t>0:
t-=1
li = list(map(int,input().strip().split()))
n1 = li[0]
n2 = li[1]
print (calc(n1,n2))
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Abhijit has an Array <b>Arr</b> which may or may not be in strictly increasing order. He wants to make this array increasing but does not wish to change the position of any element so he came with an idea that he will replace an element with any of its divisors i.e <b> he changes an element X to M if X%M=0.</b>
Your task is to tell whether the given array can be transformed to <b>strictly increasing</b> by performing the operation given above.First line of input contains the size of the array N. Next line of input contains N space- separated integers depicting the values of the array Arr.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print "YES" if the array can be transformed in the strictly increasing order else print "NO".Sample Input:-
5
1 2 16 16 16
Sample Output:-
YES
Sample Input:-
4
1 3 8 4
Sample Output:-
NO, I have written this Solution Code: // arr is the array of numbers, n is the number fo elements
function increaseArray(arr, n) {
// write code here
// do not console.log
// return "YES" or "NO"
let cnt = 2;
for (let i = 1; i < n; i++) {
while (cnt <= arr[i] && arr[i] % cnt != 0) {
cnt++;
}
if (cnt > arr[i]) { return "NO" }
cnt++;
}
return "YES"
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Abhijit has an Array <b>Arr</b> which may or may not be in strictly increasing order. He wants to make this array increasing but does not wish to change the position of any element so he came with an idea that he will replace an element with any of its divisors i.e <b> he changes an element X to M if X%M=0.</b>
Your task is to tell whether the given array can be transformed to <b>strictly increasing</b> by performing the operation given above.First line of input contains the size of the array N. Next line of input contains N space- separated integers depicting the values of the array Arr.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print "YES" if the array can be transformed in the strictly increasing order else print "NO".Sample Input:-
5
1 2 16 16 16
Sample Output:-
YES
Sample Input:-
4
1 3 8 4
Sample Output:-
NO, I have written this Solution Code: #include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];}
int cnt=2;
for(int i=1;i<n;i++){
while(cnt<=a[i] && a[i]%cnt!=0){
cnt++;}
if(cnt>a[i]){cout<<"NO";return 0;}
cnt++;
}
cout<<"YES";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Abhijit has an Array <b>Arr</b> which may or may not be in strictly increasing order. He wants to make this array increasing but does not wish to change the position of any element so he came with an idea that he will replace an element with any of its divisors i.e <b> he changes an element X to M if X%M=0.</b>
Your task is to tell whether the given array can be transformed to <b>strictly increasing</b> by performing the operation given above.First line of input contains the size of the array N. Next line of input contains N space- separated integers depicting the values of the array Arr.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print "YES" if the array can be transformed in the strictly increasing order else print "NO".Sample Input:-
5
1 2 16 16 16
Sample Output:-
YES
Sample Input:-
4
1 3 8 4
Sample Output:-
NO, I have written this Solution Code: n = int(input())
lst = list(map(int, input().split()))
count = 1
ls = []
for i in range(n):
if (lst[i]%count == 0):
lst[i] = count
ls.append(lst[i])
count += 1
change = 0
while( count > lst[i-1] and count <= lst[i]):
if (lst[i]%count == 0) :
lst[i] = count
change = 1
ls.append(lst[i])
count += 1
break
else:
count += 1
if len(ls) == n:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Abhijit has an Array <b>Arr</b> which may or may not be in strictly increasing order. He wants to make this array increasing but does not wish to change the position of any element so he came with an idea that he will replace an element with any of its divisors i.e <b> he changes an element X to M if X%M=0.</b>
Your task is to tell whether the given array can be transformed to <b>strictly increasing</b> by performing the operation given above.First line of input contains the size of the array N. Next line of input contains N space- separated integers depicting the values of the array Arr.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print "YES" if the array can be transformed in the strictly increasing order else print "NO".Sample Input:-
5
1 2 16 16 16
Sample Output:-
YES
Sample Input:-
4
1 3 8 4
Sample Output:-
NO, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String str[] = br.readLine().split(" ");
boolean flag=true;
int arr[] = new int[n];
for(int i=0;i<n;i++)
arr[i]=Integer.parseInt(str[i]);
arr[0]=1;
int j=2;
for(int i=1;i<n;i++){
if(arr[i]%j==0)
j=j+1;
else if((arr[i]%j)!=0 && (arr[i]/j)>=1){
int fight=1;
while(fight==1){
for(int x=j+1;x<=arr[i];x++){
if(arr[i]%x==0){
j=x+1;
fight=0;
break;
}
else
fight=1;
}
}
}
else
flag=false;
}
if(flag)
System.out.println("YES");
else
System.out.println("NO");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Calculators are widely used devices nowadays. It makes calculations easier and faster. A simple calculator consists of the following operators:
1. '+': adding two numbers
2. '- ': subtraction
3. '*': multiplying numbers
4. '/': division
You will be given operator '+' or '- ' or '*' or '/' followed by two operands(integers), you need to perform a mathematical operation based on a given operator.
If '/' operator is used, print the integer value after divisionUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>calculator()</b> which contains operator(any one of given in the constraints), and two operands i.e. two integers.
<b>Constraints:</b>
operators - {+, - , *, /}
1 <= integers <= 10^4You need to return the result. If '/' operator is used, return the integer value after division.Sample Input
*
10 15
Sample Output
150
Explanation:
10*15 = 150
Sample Input:
/
15 4
Sample output:
3
Explanation:
15/4 = 3.75; floor(3.75) = 3, I have written this Solution Code: function calculate(op,num1,num2) {
// write code here
// return the output using return keyword
// do not use console.log here
switch (op) {
case '+':return num1 + num2
case '-' : return num1 - num2
case '*' : return num1 * num2
case '/' : return Math.floor(num1/num2)
default:
break;
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Calculators are widely used devices nowadays. It makes calculations easier and faster. A simple calculator consists of the following operators:
1. '+': adding two numbers
2. '- ': subtraction
3. '*': multiplying numbers
4. '/': division
You will be given operator '+' or '- ' or '*' or '/' followed by two operands(integers), you need to perform a mathematical operation based on a given operator.
If '/' operator is used, print the integer value after divisionUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>calculator()</b> which contains operator(any one of given in the constraints), and two operands i.e. two integers.
<b>Constraints:</b>
operators - {+, - , *, /}
1 <= integers <= 10^4You need to return the result. If '/' operator is used, return the integer value after division.Sample Input
*
10 15
Sample Output
150
Explanation:
10*15 = 150
Sample Input:
/
15 4
Sample output:
3
Explanation:
15/4 = 3.75; floor(3.75) = 3, I have written this Solution Code: def calculator(operator,a,b):
if(operator == '/'):
print(a//b)
if(operator == '*'):
print(a*b)
if(operator == '+'):
print(a+b)
if(operator == '-'):
print(a-b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Calculators are widely used devices nowadays. It makes calculations easier and faster. A simple calculator consists of the following operators:
1. '+': adding two numbers
2. '- ': subtraction
3. '*': multiplying numbers
4. '/': division
You will be given operator '+' or '- ' or '*' or '/' followed by two operands(integers), you need to perform a mathematical operation based on a given operator.
If '/' operator is used, print the integer value after divisionUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>calculator()</b> which contains operator(any one of given in the constraints), and two operands i.e. two integers.
<b>Constraints:</b>
operators - {+, - , *, /}
1 <= integers <= 10^4You need to return the result. If '/' operator is used, return the integer value after division.Sample Input
*
10 15
Sample Output
150
Explanation:
10*15 = 150
Sample Input:
/
15 4
Sample output:
3
Explanation:
15/4 = 3.75; floor(3.75) = 3, I have written this Solution Code: static int calculator(char ch, int a, int b)
{
if(ch == '+')
return a+b;
else if(ch == '-')
return a-b;
else if(ch == '*')
return a*b;
else return a/b;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a positive integer N. Print "Yes" if N is a multiple of 3, otherwise, print "No".The input consists of a single integer N.
<b> Constraints: </b>
1 ≤ N ≤ 1000If N is a multiple of 3, print "Yes". Otherwise, print "No" (without the quotation marks). Note that the <b>output is case-sensitive</b>.Sample Input 1:
6
Sample Output 1:
Yes
Sample Input 2:
10
Sample Output 2:
No
(6 is a multiple of 3 (3*2==6) while 10 is not a multiple of 3), I have written this Solution Code: #include <bits/stdc++.h>
#define int long long
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
if (n % 3) cout << "No";
else cout << "Yes";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We need a problem on xor again. Given an array A of N integers (1- indexed), you need to find the sum of (N- i) xor A[i] for all i from 1 to N.The first line of the input contains an integer N, the number of elements of the array.
The second line of the input contains N singly spaced integers of the array A[i].
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ A[i] ≤ 10<sup>9</sup>Output a single integer, the answer to the problem.Sample Input
5
1 2 3 4 5
Sample Output
17
Explanation
(5-1)xor1 = 5, (5-2)xor2 = 1, (5-3)xor3 = 1, (5-4)xor4 = 5, (5-5)xor5 = 5.
Sample Input
5
1 1 0 4 6
Sample Output
20, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
void xorOps(int n, long[] input){
long res=0;
for(int i=0;i<n;i++){
long temp = (n-(i+1))^(input[i]);
res=res+temp;
}
System.out.print(res);
}
public static void main (String[] args)throws java.lang.Exception {
Main obj = new Main();
BufferedReader br = new BufferedReader(new InputStreamReader
(System.in));
int n = Integer.parseInt(br.readLine());
String[] raw_input= br.readLine().split(" ");
long[] input = new long[n];
for(int i=0; i<n;i++){
input[i]=Long.parseLong(raw_input[i]);
}
obj.xorOps(n,input);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We need a problem on xor again. Given an array A of N integers (1- indexed), you need to find the sum of (N- i) xor A[i] for all i from 1 to N.The first line of the input contains an integer N, the number of elements of the array.
The second line of the input contains N singly spaced integers of the array A[i].
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ A[i] ≤ 10<sup>9</sup>Output a single integer, the answer to the problem.Sample Input
5
1 2 3 4 5
Sample Output
17
Explanation
(5-1)xor1 = 5, (5-2)xor2 = 1, (5-3)xor3 = 1, (5-4)xor4 = 5, (5-5)xor5 = 5.
Sample Input
5
1 1 0 4 6
Sample Output
20, I have written this Solution Code: n=int(input())
g=map(int,input().split())
count=0
i=0
while i<n:
for j in (g):
i=i+1
t=((n-i)^j)
count=count+t
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We need a problem on xor again. Given an array A of N integers (1- indexed), you need to find the sum of (N- i) xor A[i] for all i from 1 to N.The first line of the input contains an integer N, the number of elements of the array.
The second line of the input contains N singly spaced integers of the array A[i].
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ A[i] ≤ 10<sup>9</sup>Output a single integer, the answer to the problem.Sample Input
5
1 2 3 4 5
Sample Output
17
Explanation
(5-1)xor1 = 5, (5-2)xor2 = 1, (5-3)xor3 = 1, (5-4)xor4 = 5, (5-5)xor5 = 5.
Sample Input
5
1 1 0 4 6
Sample Output
20, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
int ans = 0;
For(i, 1, n+1){
int a; cin>>a;
ans += (a^(n-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: Calculators are widely used devices nowadays. It makes calculations easier and faster. A simple calculator consists of the following operators:
1. '+': adding two numbers
2. '- ': subtraction
3. '*': multiplying numbers
4. '/': division
You will be given operator '+' or '- ' or '*' or '/' followed by two operands(integers), you need to perform a mathematical operation based on a given operator.
If '/' operator is used, print the integer value after divisionUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>calculator()</b> which contains operator(any one of given in the constraints), and two operands i.e. two integers.
<b>Constraints:</b>
operators - {+, - , *, /}
1 <= integers <= 10^4You need to return the result. If '/' operator is used, return the integer value after division.Sample Input
*
10 15
Sample Output
150
Explanation:
10*15 = 150
Sample Input:
/
15 4
Sample output:
3
Explanation:
15/4 = 3.75; floor(3.75) = 3, I have written this Solution Code: function calculate(op,num1,num2) {
// write code here
// return the output using return keyword
// do not use console.log here
switch (op) {
case '+':return num1 + num2
case '-' : return num1 - num2
case '*' : return num1 * num2
case '/' : return Math.floor(num1/num2)
default:
break;
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Calculators are widely used devices nowadays. It makes calculations easier and faster. A simple calculator consists of the following operators:
1. '+': adding two numbers
2. '- ': subtraction
3. '*': multiplying numbers
4. '/': division
You will be given operator '+' or '- ' or '*' or '/' followed by two operands(integers), you need to perform a mathematical operation based on a given operator.
If '/' operator is used, print the integer value after divisionUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>calculator()</b> which contains operator(any one of given in the constraints), and two operands i.e. two integers.
<b>Constraints:</b>
operators - {+, - , *, /}
1 <= integers <= 10^4You need to return the result. If '/' operator is used, return the integer value after division.Sample Input
*
10 15
Sample Output
150
Explanation:
10*15 = 150
Sample Input:
/
15 4
Sample output:
3
Explanation:
15/4 = 3.75; floor(3.75) = 3, I have written this Solution Code: def calculator(operator,a,b):
if(operator == '/'):
print(a//b)
if(operator == '*'):
print(a*b)
if(operator == '+'):
print(a+b)
if(operator == '-'):
print(a-b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Calculators are widely used devices nowadays. It makes calculations easier and faster. A simple calculator consists of the following operators:
1. '+': adding two numbers
2. '- ': subtraction
3. '*': multiplying numbers
4. '/': division
You will be given operator '+' or '- ' or '*' or '/' followed by two operands(integers), you need to perform a mathematical operation based on a given operator.
If '/' operator is used, print the integer value after divisionUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>calculator()</b> which contains operator(any one of given in the constraints), and two operands i.e. two integers.
<b>Constraints:</b>
operators - {+, - , *, /}
1 <= integers <= 10^4You need to return the result. If '/' operator is used, return the integer value after division.Sample Input
*
10 15
Sample Output
150
Explanation:
10*15 = 150
Sample Input:
/
15 4
Sample output:
3
Explanation:
15/4 = 3.75; floor(3.75) = 3, I have written this Solution Code: static int calculator(char ch, int a, int b)
{
if(ch == '+')
return a+b;
else if(ch == '-')
return a-b;
else if(ch == '*')
return a*b;
else return a/b;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rick's family and Jerry are playing Tic Tac Toe. Rules are simple:
<li> Game is played in pairs.
<li> If Rick plays against anyone, Rick wins.
<li> If Jerry plays against anyone, Jerry Loses.
<li> A game between any other players is a draw.
Given a pair of players, find who wins the game or if the game is draw.Input Contains two space separated characters denoting the players that will have the match.
R denotes Rick.
J denotes Jerry.
B denotes Beth.
M denotes Morty.
S denotes Summer.If the game is draw print 'D', else print the first letter of the name of the player who wins in capital.Sample Input 1
R S
Sample Output 1
R
Sample Input 2
B J
Sample Output 2
B
Sample Input 3
M S
Sample Output 3
D, 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
char p1,p2;
cin>>p1>>p2;
if(p1=='R'||p2=='R')
cout<<"R";
else{
if(p1=='J')
cout<<p2;
else{
if(p2=='J')
cout<<p1;
else
cout<<"D";
}
}
#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: Rick's family and Jerry are playing Tic Tac Toe. Rules are simple:
<li> Game is played in pairs.
<li> If Rick plays against anyone, Rick wins.
<li> If Jerry plays against anyone, Jerry Loses.
<li> A game between any other players is a draw.
Given a pair of players, find who wins the game or if the game is draw.Input Contains two space separated characters denoting the players that will have the match.
R denotes Rick.
J denotes Jerry.
B denotes Beth.
M denotes Morty.
S denotes Summer.If the game is draw print 'D', else print the first letter of the name of the player who wins in capital.Sample Input 1
R S
Sample Output 1
R
Sample Input 2
B J
Sample Output 2
B
Sample Input 3
M S
Sample Output 3
D, I have written this Solution Code: a,b=input().split()
if(a=="R" or b=="R"):
print("R")
elif(a=="J" or b=="J"):
if(a=="J"):
print(b)
else:
print(a)
else:
print("D"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rick's family and Jerry are playing Tic Tac Toe. Rules are simple:
<li> Game is played in pairs.
<li> If Rick plays against anyone, Rick wins.
<li> If Jerry plays against anyone, Jerry Loses.
<li> A game between any other players is a draw.
Given a pair of players, find who wins the game or if the game is draw.Input Contains two space separated characters denoting the players that will have the match.
R denotes Rick.
J denotes Jerry.
B denotes Beth.
M denotes Morty.
S denotes Summer.If the game is draw print 'D', else print the first letter of the name of the player who wins in capital.Sample Input 1
R S
Sample Output 1
R
Sample Input 2
B J
Sample Output 2
B
Sample Input 3
M S
Sample Output 3
D, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
String[] rowcol = rd.readLine().split(" ");
String name = rowcol[0];
String name2 = rowcol[1];
if(name.equals("R")|| name2.equals("R")){
System.out.print('R');
return;
}
else if(name.equals("J")){
System.out.print(name2);
return;
}else if(name2.equals("J")){
System.out.print(name);
return;
}
else if(!name.equals("R") && !name.equals("J")){
System.out.print('D');
return;
}
else if(!name2.equals("J") && !name2.equals("R")){
System.out.print('D');
return;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers N and K. Construct a max diversity string of length N and period K. Among all possible strings, find the lexographically minimum string.
A max diverse string is a string with maximum number of different characters.
A string with period K is a string made by a string of length K repeated multiple times.
Note: You can use only lowercase characters from 'a' to 'z'.The first and the only line of input contains two integers N and K.
Constraints:
1 <= N <= 100000
1 <= K <= min(N,100)
N is divisible by K.Print the required string.Sample Input 1
4 2
Sample Output 1
abab
Sample Input 2
4 1
Sample Output 2
aaaa, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt(), k = s.nextInt();
int a = 0, b = k;
if(k > 26){
a = k - 26;
b = 26;
}
while(n != 0){
for(int i=0 ; i<a ; i++){
System.out.print((char)(97));
n--;
}
for(int i=0 ; i<b ; i++){
System.out.print((char)(i%26+97));
n--;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers N and K. Construct a max diversity string of length N and period K. Among all possible strings, find the lexographically minimum string.
A max diverse string is a string with maximum number of different characters.
A string with period K is a string made by a string of length K repeated multiple times.
Note: You can use only lowercase characters from 'a' to 'z'.The first and the only line of input contains two integers N and K.
Constraints:
1 <= N <= 100000
1 <= K <= min(N,100)
N is divisible by K.Print the required string.Sample Input 1
4 2
Sample Output 1
abab
Sample Input 2
4 1
Sample Output 2
aaaa, I have written this Solution Code: import copy,math
x,y = input().split()
x = int(x)
y = int(y)
s = ""
if y>26:
s = ('a'*(y-26))+("".join(chr(97+i) for i in range(26)))
else:
s = "".join(chr(97+i) for i in range(y))
print(s*(x//y)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers N and K. Construct a max diversity string of length N and period K. Among all possible strings, find the lexographically minimum string.
A max diverse string is a string with maximum number of different characters.
A string with period K is a string made by a string of length K repeated multiple times.
Note: You can use only lowercase characters from 'a' to 'z'.The first and the only line of input contains two integers N and K.
Constraints:
1 <= N <= 100000
1 <= K <= min(N,100)
N is divisible by K.Print the required string.Sample Input 1
4 2
Sample Output 1
abab
Sample Input 2
4 1
Sample Output 2
aaaa, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,k;
cin>>n>>k;
string s(n,'a');
for(int i=0;i<n/k;++i){
for(int j=0;j<k;++j){
if(j<k-26)
s[i*k+j]='a';
else
s[i*k+j]='a'+j-max(0ll,(k-26));
}
}
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: Abhijit has an Array <b>Arr</b> which may or may not be in strictly increasing order. He wants to make this array increasing but does not wish to change the position of any element so he came with an idea that he will replace an element with any of its divisors i.e <b> he changes an element X to M if X%M=0.</b>
Your task is to tell whether the given array can be transformed to <b>strictly increasing</b> by performing the operation given above.First line of input contains the size of the array N. Next line of input contains N space- separated integers depicting the values of the array Arr.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print "YES" if the array can be transformed in the strictly increasing order else print "NO".Sample Input:-
5
1 2 16 16 16
Sample Output:-
YES
Sample Input:-
4
1 3 8 4
Sample Output:-
NO, I have written this Solution Code: // arr is the array of numbers, n is the number fo elements
function increaseArray(arr, n) {
// write code here
// do not console.log
// return "YES" or "NO"
let cnt = 2;
for (let i = 1; i < n; i++) {
while (cnt <= arr[i] && arr[i] % cnt != 0) {
cnt++;
}
if (cnt > arr[i]) { return "NO" }
cnt++;
}
return "YES"
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Abhijit has an Array <b>Arr</b> which may or may not be in strictly increasing order. He wants to make this array increasing but does not wish to change the position of any element so he came with an idea that he will replace an element with any of its divisors i.e <b> he changes an element X to M if X%M=0.</b>
Your task is to tell whether the given array can be transformed to <b>strictly increasing</b> by performing the operation given above.First line of input contains the size of the array N. Next line of input contains N space- separated integers depicting the values of the array Arr.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print "YES" if the array can be transformed in the strictly increasing order else print "NO".Sample Input:-
5
1 2 16 16 16
Sample Output:-
YES
Sample Input:-
4
1 3 8 4
Sample Output:-
NO, I have written this Solution Code: #include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];}
int cnt=2;
for(int i=1;i<n;i++){
while(cnt<=a[i] && a[i]%cnt!=0){
cnt++;}
if(cnt>a[i]){cout<<"NO";return 0;}
cnt++;
}
cout<<"YES";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Abhijit has an Array <b>Arr</b> which may or may not be in strictly increasing order. He wants to make this array increasing but does not wish to change the position of any element so he came with an idea that he will replace an element with any of its divisors i.e <b> he changes an element X to M if X%M=0.</b>
Your task is to tell whether the given array can be transformed to <b>strictly increasing</b> by performing the operation given above.First line of input contains the size of the array N. Next line of input contains N space- separated integers depicting the values of the array Arr.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print "YES" if the array can be transformed in the strictly increasing order else print "NO".Sample Input:-
5
1 2 16 16 16
Sample Output:-
YES
Sample Input:-
4
1 3 8 4
Sample Output:-
NO, I have written this Solution Code: n = int(input())
lst = list(map(int, input().split()))
count = 1
ls = []
for i in range(n):
if (lst[i]%count == 0):
lst[i] = count
ls.append(lst[i])
count += 1
change = 0
while( count > lst[i-1] and count <= lst[i]):
if (lst[i]%count == 0) :
lst[i] = count
change = 1
ls.append(lst[i])
count += 1
break
else:
count += 1
if len(ls) == n:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.