Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments.
Constraints:-
0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:-
4 2 0
Sample Output:-
12
Sample Input:-
1 1 1
Sample Output:-
1, I have written this Solution Code: def Marks(P,Q,R):
return 4*P-2*Q-R
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments.
Constraints:-
0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:-
4 2 0
Sample Output:-
12
Sample Input:-
1 1 1
Sample Output:-
1, I have written this Solution Code: static int Marks(int P, int Q, int R){
return 4*P - 2*Q - R;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number (n) is represented in Linked List such that each digit corresponds to a node in linked list. Add 1 to it.
<b>Note:-</b> Linked list representation of a number is from left to right i.e if the number is 123 than in linked list it is represented as 3->2->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>addOne()</b> that takes head node of the linked list as parameter.
Constraints:
1 <=length of n<= 1000Return the head of the modified linked list.Input 1:
456
Output 1:
457
Input 2:
999
Output 2:
1000, I have written this Solution Code:
static Node addOne(Node head)
{
Node res = head;
Node temp = null, prev = null;
int carry = 1, sum;
while (head != null) //while both lists exist
{
sum = carry + head.data;
carry = (sum >= 10)? 1 : 0;
sum = sum % 10;
head.data = sum;
temp = head;
head = head.next;
}
if (carry > 0) {
Node x=new Node(carry);
temp.next=x;}
return res;
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code:
char Race(int A, int B, int C){
if(abs(C-A)==abs(C-B)){return 'D';}
if(abs(C-A)>abs(C-B)){return 'S';}
else{
return 'N';}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code: def Race(A,B,C):
if abs(C-A) ==abs(C-B):
return 'D'
if abs(C-A)>abs(C-B):
return 'S'
return 'N'
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code:
char Race(int A, int B, int C){
if(abs(C-A)==abs(C-B)){return 'D';}
if(abs(C-A)>abs(C-B)){return 'S';}
else{
return 'N';}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code: static char Race(int A,int B,int C){
if(Math.abs(C-A)==Math.abs(C-B)){return 'D';}
if(Math.abs(C-A)>Math.abs(C-B)){return 'S';}
else{
return 'N';}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer <b>N</b>, you need to typecast this integer to String. If the typecasting is done successfully then we will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".User task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>checkConvertion()</b>, which contains N as a parameter.You need to return the typecasted string value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".Sample Input:
5
Sample Output:
Nice Job
Sample Input:
6
Sample Output:
Nice Job, I have written this Solution Code: def checkConevrtion(a):
return str(a)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer <b>N</b>, you need to typecast this integer to String. If the typecasting is done successfully then we will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".User task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>checkConvertion()</b>, which contains N as a parameter.You need to return the typecasted string value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".Sample Input:
5
Sample Output:
Nice Job
Sample Input:
6
Sample Output:
Nice Job, I have written this Solution Code: static String checkConevrtion(int a)
{
return String.valueOf(a);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a class with the name SumCalculator. The class needs two fields (public variables) with names num1 and num2 both of type int.
Write the following methods (instance methods):
<b>*Method named sum without any parameters, it needs to return the value of num1 + num2.</b>
<b>*Method named sum2 with two parameters a, b, it needs to return the value of a + b.</b>
<b>*Method named fromObject with two parameters of type sumCalculator object named obj1 and obj2, and you have to call sum function for respective object and return sum of both</b>
NOTE: All methods should be defined as public, NOT public static.
NOTE: In total, you have to write 3 methods.
NOTE: Do not add the main method to the solution code.You don't have to take any input, You only have to write class <b>SumCalculator</b>.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Input:
1
Sample Output:
Correct, I have written this Solution Code: class SumCalculator():
def __init__(self,a,b):
self.a=a
self.b=b
def sum(self):
return self.a+self.b
def sum2(self,a,b):
return a+b
def fromObject(self,ob1,ob2):
return ob1.sum+ob2.sum, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a class with the name SumCalculator. The class needs two fields (public variables) with names num1 and num2 both of type int.
Write the following methods (instance methods):
<b>*Method named sum without any parameters, it needs to return the value of num1 + num2.</b>
<b>*Method named sum2 with two parameters a, b, it needs to return the value of a + b.</b>
<b>*Method named fromObject with two parameters of type sumCalculator object named obj1 and obj2, and you have to call sum function for respective object and return sum of both</b>
NOTE: All methods should be defined as public, NOT public static.
NOTE: In total, you have to write 3 methods.
NOTE: Do not add the main method to the solution code.You don't have to take any input, You only have to write class <b>SumCalculator</b>.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Input:
1
Sample Output:
Correct, I have written this Solution Code: class SumCalculator{
public int num1,num2;
SumCalculator(int _num1,int _num2){
num1=_num1;
num2=_num2;
}
public int sum() {
return num1+num2;
}
public int sum2(int a,int b){
return a+b;
}
public int fromObject(SumCalculator obj1,SumCalculator obj2){
return obj1.sum() + obj2.sum();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the function isArray which takes an input which can be any data type and returns true
if it's an array else false.Could be any datatype string number object or an arraytrue or falseSample Input:-
1
[2, 3]
Sample Output
false
true, 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);
String str= s.next();
if(str.charAt(0)== '['){
System.out.println("true");
}
else{
System.out.println("false");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the function isArray which takes an input which can be any data type and returns true
if it's an array else false.Could be any datatype string number object or an arraytrue or falseSample Input:-
1
[2, 3]
Sample Output
false
true, I have written this Solution Code: function isArray(input){
if(Array.isArray(input)) {
console.log(true)
}else{
console.log(false)
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You need to make an order counter to keep track of the total number of orders received.
Complete the function <code> generateOrder() </code> which returns a <code>function func()</code>. This function <code>func</code> should maintain a <code> count (initially 0)</code>. Every time <code>func</code> is called, <code> count</code> must be incremented by 1 and the string <code>"Total orders = " + count</code> must be returned.
<b>Note:</b> The function generateOrder() will be called internally. You do not need to call it yourself. The generateOrder() takes no argument. It is called internally.The generateOrder() function returns a function that returns the string <code>"Total orders = " + count</code>, where <code>count</code> is the number of times the function is called.
const initC = generateOrder(starting);
console.log(initC()) //prints "Total orders = 1"
console.log(initC()) //prints "Total orders = 2"
console.log(initC()) //prints "Total orders = 3"
, I have written this Solution Code: let generateOrder = function() {
let prefix = "Total orders = ";
let count = 0;
let totalOrders = function(){
count++
return prefix + count;
}
return totalOrders;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N balloons numbered from 1 to N. Every balloon has an another integer value Arr[i] assigned to it where i varies from 1 to N, and i represents the number of balloon.
A balloon at an odd position (i = 1, 3, 5. ) is happy if Arr[i] is odd.
A balloon at an even position (i = 2, 4, 6. ) is happy if Arr[i] is even.
Find the number of happy balloons.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, Arr[1], Arr[2], Arr[3],. , Arr[N].
Constrains
1 <= N <= 200000
1 <= Arr[i] <= 1000000Output a single integer, the number of happy balloons.Sample Input
5
1 3 4 6 7
Sample Output
3
Explanation
Happy balloons are balloons numbered 1, 4, 5.
Sample Input
5
1 2 3 4 5
Sample Output
5, 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));
br.readLine();
String[] line = br.readLine().split(" ");
int happyBalloons = 0;
for(int i=1;i<=line.length;++i){
int num = Integer.parseInt(line[i-1]);
if(num%2 == i%2 ){
happyBalloons++;
}
}
System.out.println(happyBalloons);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N balloons numbered from 1 to N. Every balloon has an another integer value Arr[i] assigned to it where i varies from 1 to N, and i represents the number of balloon.
A balloon at an odd position (i = 1, 3, 5. ) is happy if Arr[i] is odd.
A balloon at an even position (i = 2, 4, 6. ) is happy if Arr[i] is even.
Find the number of happy balloons.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, Arr[1], Arr[2], Arr[3],. , Arr[N].
Constrains
1 <= N <= 200000
1 <= Arr[i] <= 1000000Output a single integer, the number of happy balloons.Sample Input
5
1 3 4 6 7
Sample Output
3
Explanation
Happy balloons are balloons numbered 1, 4, 5.
Sample Input
5
1 2 3 4 5
Sample Output
5, I have written this Solution Code: x=int(input())
arr=input().split()
for i in range(0,x):
arr[i]=int(arr[i])
count=0
for i in range(0,x):
if(arr[i]%2==0 and (i+1)%2==0):
count+=1
elif (arr[i]%2!=0 and (i+1)%2!=0):
count+=1
print (count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N balloons numbered from 1 to N. Every balloon has an another integer value Arr[i] assigned to it where i varies from 1 to N, and i represents the number of balloon.
A balloon at an odd position (i = 1, 3, 5. ) is happy if Arr[i] is odd.
A balloon at an even position (i = 2, 4, 6. ) is happy if Arr[i] is even.
Find the number of happy balloons.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, Arr[1], Arr[2], Arr[3],. , Arr[N].
Constrains
1 <= N <= 200000
1 <= Arr[i] <= 1000000Output a single integer, the number of happy balloons.Sample Input
5
1 3 4 6 7
Sample Output
3
Explanation
Happy balloons are balloons numbered 1, 4, 5.
Sample Input
5
1 2 3 4 5
Sample Output
5, 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;
if(i%2 == a%2)
ans++;
}
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 an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String [] str=br.readLine().trim().split(" ");
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=Integer.parseInt(str[i]);
}
Arrays.sort(a);
int size=a[n-1]+1;
int c[]=new int[size];
for(int i=0;i<size;i++) c[i]=0;
for(int i=0;i<n;i++) c[a[i]]++;
int max=0,freq=c[1];
for(int i=2;i<size;i++){
if(freq<=c[i]){
freq=c[i];
max=i;
}
}
System.out.println(max);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: n = int(input())
a = [int(x) for x in input().split()]
freq = {}
for x in a:
if x not in freq:
freq[x] = 1
else:
freq[x] += 1
mx = max(freq.values())
rf = sorted(freq)
for i in range(len(rf) - 1, -1, -1):
if freq[rf[i]] == mx:
print(rf[i])
break, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int n; cin >> n;
for(int i = 1; i <= n; i++){
int p; cin >> p;
a[p]++;
}
int mx = 0, id = -1;
for(int i = 1; i <= 100; i++){
if(a[i] >= mx)
mx = a[i], id = i;
}
cout << id;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice has Q queries for you. If you can solve all her queries, she will invite you to participate in a fireworks display with her.
In each query, she gives you a positive integer N, and you have to find the number of positive integers M such that M × d(M) = N.
Here, d(M) refers to the sum of all digits of M. For example, d(1023) = 6.The first line consists of a single integer Q – the number of queries.
Then Q lines follow, each line containing a single integer N denoting a query.
<b> Constraints: </b>
1 ≤ Q ≤ 1000
1 ≤ N ≤ 10<sup>18</sup>Print Q lines, the i<sup>th</sup> line containing the answer to the i<sup>th</sup> query.Sample Input 1:
3
1
6
36
Sample Output 1:
1
0
2
Sample Explanation 1:
For the first query, the only possibility is 1.
For the third query, the only possibilities are 6 and 12., I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
private static final int START_TEST_CASE = 1;
public static void solveCase(FastIO io, int testCase) {
final long N = io.nextLong();
int count = 0;
for (int i = 1; i <= 200; ++i) {
if (N % i == 0) {
long j = N / i;
if (digitSum(j) == i) {
++count;
}
}
}
io.println(count);
}
private static long digitSum(long x) {
long s = 0;
while (x > 0) {
s += x % 10;
x /= 10;
}
return s;
}
public static void solve(FastIO io) {
final int T = io.nextInt();
for (int t = 0; t < T; ++t) {
solveCase(io, START_TEST_CASE + t);
}
}
public static class FastIO {
private InputStream reader;
private PrintWriter writer;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastIO(InputStream r, OutputStream w) {
reader = r;
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = reader.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
return Double.parseDouble(nextString());
}
public int[] nextIntArray(int n) {
return nextIntArray(n, 0);
}
public int[] nextIntArray(int n, int off) {
int[] arr = new int[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
return nextLongArray(n, 0);
}
public long[] nextLongArray(int n, int off) {
long[] arr = new long[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printlnArray(int[] arr) {
printArray(arr);
writer.println();
}
public void printlnArray(long[] arr) {
printArray(arr);
writer.println();
}
public void printf(String format, Object... args) {
print(String.format(format, args));
}
public void flush() {
writer.flush();
}
}
private static class Solution implements Runnable {
@Override
public void run() {
FastIO io = new FastIO(System.in, System.out);
solve(io);
io.flush();
}
}
public static void main(String[] args) throws InterruptedException {
Thread t = new Thread(null, new Solution(), "Solution", 1 << 30);
t.start();
t.join();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice has Q queries for you. If you can solve all her queries, she will invite you to participate in a fireworks display with her.
In each query, she gives you a positive integer N, and you have to find the number of positive integers M such that M × d(M) = N.
Here, d(M) refers to the sum of all digits of M. For example, d(1023) = 6.The first line consists of a single integer Q – the number of queries.
Then Q lines follow, each line containing a single integer N denoting a query.
<b> Constraints: </b>
1 ≤ Q ≤ 1000
1 ≤ N ≤ 10<sup>18</sup>Print Q lines, the i<sup>th</sup> line containing the answer to the i<sup>th</sup> query.Sample Input 1:
3
1
6
36
Sample Output 1:
1
0
2
Sample Explanation 1:
For the first query, the only possibility is 1.
For the third query, the only possibilities are 6 and 12., I have written this Solution Code:
q = int(input())
for _ in range(q):
n = int(input())
count = 0
for i in range(1,9*len(str(n))):
if not n % i:
dig = n//i
if sum(map(int,str(dig))) == i:
count += 1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice has Q queries for you. If you can solve all her queries, she will invite you to participate in a fireworks display with her.
In each query, she gives you a positive integer N, and you have to find the number of positive integers M such that M × d(M) = N.
Here, d(M) refers to the sum of all digits of M. For example, d(1023) = 6.The first line consists of a single integer Q – the number of queries.
Then Q lines follow, each line containing a single integer N denoting a query.
<b> Constraints: </b>
1 ≤ Q ≤ 1000
1 ≤ N ≤ 10<sup>18</sup>Print Q lines, the i<sup>th</sup> line containing the answer to the i<sup>th</sup> query.Sample Input 1:
3
1
6
36
Sample Output 1:
1
0
2
Sample Explanation 1:
For the first query, the only possibility is 1.
For the third query, the only possibilities are 6 and 12., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
// #pragma gcc optimize("ofast")
// #pragma gcc target("avx,avx2,fma")
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
#define fi first
#define se second
// const int mod = 1e9 + 7;
const int mod=998'244'353;
const long long INF = 2e18 + 10;
// const int INF=4e9+10;
#define readv(x, n) \
vector<int> x(n); \
for (auto &i : x) \
cin >> i;
template <typename t>
using v = vector<t>;
template <typename t>
using vv = vector<vector<t>>;
template <typename t>
using vvv = vector<vector<vector<t>>>;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<vector<int>>>> vvvvi;
typedef vector<vector<double>> vvd;
typedef pair<int, int> pii;
int multiply(int a, int b, int in_mod) { return (int)(1ll * a * b % in_mod); }
int mult_identity(int a) { return 1; }
const double pi = acosl(-1);
vector<vector<int> > multiply(vector<vector<int>> a, vector<vector<int>> b, int in_mod)
{
int n = a.size();
int l = b.size();
int m = b[0].size();
vector<vector<int> > result(n,vector<int>(n));
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
for(int k=0;k<l;k++)
{
result[i][j] = (result[i][j] + a[i][k]*b[k][j])%in_mod;
}
}
}
return result;
}
vector<vector<int>> operator%(vector<vector<int>> a, int in_mod)
{
for(auto &i:a)
for(auto &j:i)
j%=in_mod;
return a;
}
vector<vector<int>> mult_identity(vector<vector<int>> a)
{
int n=a.size();
vector<vector<int>> output(n, vector<int> (n));
for(int i=0;i<n;i++)
output[i][i]=1;
return output;
}
vector<int> mat_vector_product(vector<vector<int>> a, vector<int> b, int in_mod)
{
int n =a.size();
vector<int> output(n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
output[i]+=a[i][j]*b[j];
output[i]%=in_mod;
}
}
return output;
}
auto power(auto a, auto b, const int in_mod)
{
auto prod = mult_identity(a);
auto mult = a % in_mod;
while (b != 0)
{
if (b % 2)
{
prod = multiply(prod, mult, in_mod);
}
if(b/2)
mult = multiply(mult, mult, in_mod);
b /= 2;
}
return prod;
}
auto mod_inv(auto q, const int in_mod)
{
return power(q, in_mod - 2, in_mod);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define stp cout << fixed << setprecision(20);
int digit_sum(int x){
int sm = 0;
while(x){
sm += x%10;
x/= 10;
}
return sm;
}
void solv(){
int n;
cin>>n;
int cnt = 0;
for(int sm = 1;sm<= 200;sm++){
if(n %sm == 0){
if( digit_sum(n/sm) == sm){
cnt++;
}
}
}
cout<<cnt<<endl;
}
void solve()
{
int t = 1;
cin>>t;
for(int T=1;T<=t;T++)
{
// cout<<"Case #"<<T<<": ";
solv();
}
}
signed main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
auto clk = clock();
// -------------------------------------Code starts here---------------------------------------------------------------------
signed t = 1;
// cin >> t;
for (signed test = 1; test <= t; test++)
{
// cout<<"Case #"<<test<<": ";
solve();
}
// -------------------------------------Code ends here------------------------------------------------------------------
clk = clock() - clk;
#ifndef ONLINE_JUDGE
cerr << fixed << setprecision(6) << "\nTime: " << ((float)clk) / CLOCKS_PER_SEC << "\n";
#endif
return 0;
}
/*
000100
1000100
1 0 -1 -2 -1 -2 -3
*/
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b>
There will be two functions:
<ul>
<li>verticalFive(): Print stars in vertical order</li>
<li>horizontalFive(): Print stars in horizontal order</l>
</ul><b>User Task:</b>
Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>.
Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function.
<b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input:
Sample Output:
*
*
*
*
*
* * * * *, I have written this Solution Code: static void verticalFive(){
System.out.println("*");
System.out.println("*");
System.out.println("*");
System.out.println("*");
System.out.println("*");
}
static void horizontalFive(){
System.out.print("* * * * *");
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b>
There will be two functions:
<ul>
<li>verticalFive(): Print stars in vertical order</li>
<li>horizontalFive(): Print stars in horizontal order</l>
</ul><b>User Task:</b>
Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>.
Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function.
<b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input:
Sample Output:
*
*
*
*
*
* * * * *, I have written this Solution Code: def vertical5():
for i in range(0,5):
print("*",end="\n")
#print()
def horizontal5():
for i in range(0,5):
print("*",end=" ")
vertical5()
print(end="\n")
horizontal5(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a <b>BST</b> and some keys, the task is to insert the keys in the given BST. Duplicates are not inserted. (If a test case contains duplicate keys, you need to consider the first occurrence and ignore duplicates).<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>insertInBST()</b> that takes "root" node and value to be inserted as parameter. The printing is done by the driver code.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^3
1 <= node values <= 10^4
<b>Sum of "N" over all testcases does not exceed 10^5</b>Return the node of BST after insertion.Input:
2
3
2 1 3
4
8
2 1 3 N N N 6 4
1
Output:
1 2 3 4
1 2 3 4 6
Explanation:
Testcase 1: After inserting the node 4 the tree will be
2
/ \
1 3
\
4
Inorder traversal will be 1 2 3 4.
Testcase 2: After inserting the node 1 the tree will be
2
/ \
1 3
/ \ / \
N N N 6
/
4
Inorder traversal of the above tree will be 1 2 3 4 6., I have written this Solution Code:
static Node insertInBST(Node root,int key)
{
if(root == null) return new Node(key);
if(key < root.data)
root.left = insertInBST(root.left,key);
else if(key > root.data)
root.right = insertInBST(root.right,key);
return root;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length, breadth, and height of a cuboid. Your task is to calculate its Perimeter.
Note:- Formula for the perimeter of the cuboid is 4(Length + Breadth + height)<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>Perimeter()</b> that takes integers L, B, and H as parameters.
Constraints:-
1 <= L, B, H <= 100Return the length of the Cuboid.Sample Input:-
L = 3, B = 5, H = 1
Sample Output:-
36
Sample Input:-
L = 1, B = 1, H = 1
Sample Output:-
12, I have written this Solution Code:
L,B,H=input().split()
a=4*(int(L)+int(B)+int(H))
print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length, breadth, and height of a cuboid. Your task is to calculate its Perimeter.
Note:- Formula for the perimeter of the cuboid is 4(Length + Breadth + height)<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>Perimeter()</b> that takes integers L, B, and H as parameters.
Constraints:-
1 <= L, B, H <= 100Return the length of the Cuboid.Sample Input:-
L = 3, B = 5, H = 1
Sample Output:-
36
Sample Input:-
L = 1, B = 1, H = 1
Sample Output:-
12, I have written this Solution Code: static int Perimeter(int L, int B, int H){
return 4*(L+B+H);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: How would you add your own method to the Array object so
the following code would work?
const arr = [1, 2, 3]
console. log(arr.average())
// 2input will be an array, run like this
const anyArray = [5,6...]
anyArray.average should return average of the arraysAverage of the given arrayconst myArray = [1,2,3,4,5]
console.log(myArray.average())
// 3, I have written this Solution Code: Array.prototype.average = function() {
// calculate sum
var sum = this.reduce(function(prev, cur) { return prev + cur; });
// return sum divided by number of elements
return sum / this.length;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: To enter Todo's amusement park, there are M counters. Total N people want to enter the amusement park, each of whom will line up in front of one of the counters. Any counter worker gets angry if the number of people lining up in front of him is at least 2 more than the number of people lining up in front of any of its neighbouring counters. The worker at the K-th counter works the fastest.
Find the maximum number of people that can line up in front of the K-th counter such that each counter gets at least one person and no counter worker is angry.Input contains three integers M, N and K.
Constraints:
1 <= N <= 1000000000
1 <= M <= N
1 <= K <= MPrint the maximum number of people that can line up in front of the Kth counter such that each counter gets at least one person and no counter worker is angry.Sample Input 1
3 3 1
Sample Output 1
1
Explanation: Optimal Arrangement is 1 1 1.
Sample Input 2
3 6 1
Sample Output
3
Explanation: Optimal Arrangement is 3 2 1., I have written this Solution Code: import java.io.*;
class Main {
public static void main (String[] args) throws NumberFormatException, IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] s = in.readLine().split(" ");
in.close();
int M = Integer.parseInt(s[0]);
int N = Integer.parseInt(s[1]);
int K = Integer.parseInt(s[2]);
if(M>=N)
System.out.println(1);
else if(M == 1)
System.out.println(N);
else
System.out.println(countersAndLines(M, N, K));
}
static int countersAndLines (int m, int n, int k){
int start = n/m, end = (n/2)+1;
while(start<=end){
int mid = start+(end-start)/2;
long minPeople = option(mid, k) + option(mid, m-k+1) - mid;
if(minPeople == n)
return mid;
else if(minPeople < n)
start = mid+1;
else
end = mid-1;
}
return end;
}
static long sum (int m, int k, int i){
long sum = i;
int temp = --i;
for(int j = k-1; j>=1; j--){
if(i <= 1)
sum += 1;
else{
sum += i;
i--;
}
}
for(int j = k+1; j<=m; j++){
if(temp <= 1)
sum += 1;
else{
sum += temp;
temp--;
}
}
return sum;
}
static long option(int i, int k){
long x = k;
if(x > i)
x = i;
k -= x;
long y = k + x * (2 * i - x + 1) / 2;
return y;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: To enter Todo's amusement park, there are M counters. Total N people want to enter the amusement park, each of whom will line up in front of one of the counters. Any counter worker gets angry if the number of people lining up in front of him is at least 2 more than the number of people lining up in front of any of its neighbouring counters. The worker at the K-th counter works the fastest.
Find the maximum number of people that can line up in front of the K-th counter such that each counter gets at least one person and no counter worker is angry.Input contains three integers M, N and K.
Constraints:
1 <= N <= 1000000000
1 <= M <= N
1 <= K <= MPrint the maximum number of people that can line up in front of the Kth counter such that each counter gets at least one person and no counter worker is angry.Sample Input 1
3 3 1
Sample Output 1
1
Explanation: Optimal Arrangement is 1 1 1.
Sample Input 2
3 6 1
Sample Output
3
Explanation: Optimal Arrangement is 3 2 1., I have written this Solution Code: def get(ed, cnt):
d=cnt
if d>ed:
d=ed
cnt -=d
return cnt+d*(2*ed-d+1)/2
n,p,k = map(int,input().split())
l=1
r=10**9+10
while l+1<r:
m = (l+r)//2
if get(m,k) + get(m,n-k+1)-m>p:
r=m
else:
l=m
print(l), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: To enter Todo's amusement park, there are M counters. Total N people want to enter the amusement park, each of whom will line up in front of one of the counters. Any counter worker gets angry if the number of people lining up in front of him is at least 2 more than the number of people lining up in front of any of its neighbouring counters. The worker at the K-th counter works the fastest.
Find the maximum number of people that can line up in front of the K-th counter such that each counter gets at least one person and no counter worker is angry.Input contains three integers M, N and K.
Constraints:
1 <= N <= 1000000000
1 <= M <= N
1 <= K <= MPrint the maximum number of people that can line up in front of the Kth counter such that each counter gets at least one person and no counter worker is angry.Sample Input 1
3 3 1
Sample Output 1
1
Explanation: Optimal Arrangement is 1 1 1.
Sample Input 2
3 6 1
Sample Output
3
Explanation: Optimal Arrangement is 3 2 1., 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();
//////////////
typedef unsigned long long ull;
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
ll get(ll ed, ll cnt){
ll d = cnt;
if (d > ed) d = ed;
cnt -= d;
return cnt + d * (2 * ed - d + 1) / 2;
}
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
ll n, p, k; cin >> n >> p >> k;
ll l = 1, r = 1e9 + 10;
while(l + 1 < r){
ll m = (l + r) / 2;
if ( ull(get(m, k)) + get(m, n - k + 1) - m > p)
r = m;
else l = m;
}
cout << l << endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a Deque and Q queries. The task is to perform some operation on Deque according to the queries as described in input:
Note:-if deque is empty than pop operation will do nothing, and -1 will be printed as a front and rear element of queue if it is empty.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>push_front_pf()</b>:- that takes the deque and the integer to be added as a parameter.
<b>push_bac_pb()</b>:- that takes the deque and the integer to be added as a parameter.
<b>pop_back_ppb()</b>:- that takes the deque as parameter.
<b>front_dq()</b>:- that takes the deque as parameter.
Constraints:
1 <= N(Number of queries) <= 10<sup>3</sup>
<b>Custom Input: </b>
First line of input should contain the number of queries Q. Next, Q lines should contain any of the given operations:-
For <b>push_front</b> use <b> pf x</b> where x is the element to be added
For <b>push_rear</b> use <b> pb x</b> where x is the element to be added
For <b>pop_back</b> use <b> pp_b</b>
For <b>Display Front</b> use <b>f</b>
Moreover driver code will print
Front element of deque in each push_front opertion
Last element of deque in each push_back operation
Size of deque in each pop_back operation The front_dq() function will return the element at front of your deque in a new line, if the deque is empty you just need to return -1 in the function.Sample Input:
6
push_front 2
push_front 3
push_rear 5
display_front
pop_rear
display_front
Sample Output:
3
3, I have written this Solution Code:
static void push_back_pb(Deque<Integer> dq, int x)
{
dq.add(x);
}
static void push_front_pf(Deque<Integer> dq, int x)
{
dq.addFirst(x);
}
static void pop_back_ppb(Deque<Integer> dq)
{
if(!dq.isEmpty())
dq.pollLast();
else return;
}
static int front_dq(Deque<Integer> dq)
{
if(!dq.isEmpty())
return dq.peek();
else return -1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: This is a time of conflict in Westeros as Viserys Targaryen, the king of all seven kingdoms, rejected the hand of Lady Laena Velaryon. So, the Velaryon soldiers are not deemed trustworthy anymore. The Targaryen soldiers have to keep an eye on them.
You are given a sequential order of N soldiers standing in a line. The order is provided as a binary string, with 0 representing Velaryon soldiers, and 1 representing the Targaryen soldiers. Viserys wants each contiguous segment of N/2 soldiers to contain an even number of Targaryen soldiers.
Formally you are given a binary string of length N, where N is an even natural number. Each character of the string is either '0' or '1'. You want to rearrange the elements of the string in such a way that the final string contains an even number of 1s in each contiguous subsegment of length N/2.
Your task is to find out whether there exists a rearrangement of the soldiers that satisfies the above conditions.The first line contains an integer T, the number of test cases. Then, T test cases follow.
The first line of each test case contains an even positive integer N, the length of the line.
The second line of each test case contains a binary string of length N, representing the current arrangement of soldiers.
<b> Constraints: </b>
1 ≤ T ≤ 10
2 ≤ N ≤ 10<sup>4</sup>
N is evenPrint a single character in a new line for each test case. Print '1' (without quotes) if a required rearrangement exists, and '0' (without quotes) otherwise.Sample Input:
3
2
10
2
00
4
0011
Sample Output:
0
1
0
(In the last case, no matter how you rearrange the string, there will always be a single one in at least one subsegment of length 2 of the string), I have written this Solution Code: import java.io.*;
import java.util.*;
class Main{
public static void main(String[] args)throws IOException
{
StringBuilder out=new StringBuilder();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int test=Integer.parseInt(br.readLine());
while(test-->0)
{
int n=Integer.parseInt(br.readLine());
String s=br.readLine();
int c1=0;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='1') c1++;
}
if(c1%4==0) out.append("1\n");
else if(c1==s.length() && (c1/2)%2==0) out.append("1\n");
else
out.append("0\n");
}
System.out.print(out);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: This is a time of conflict in Westeros as Viserys Targaryen, the king of all seven kingdoms, rejected the hand of Lady Laena Velaryon. So, the Velaryon soldiers are not deemed trustworthy anymore. The Targaryen soldiers have to keep an eye on them.
You are given a sequential order of N soldiers standing in a line. The order is provided as a binary string, with 0 representing Velaryon soldiers, and 1 representing the Targaryen soldiers. Viserys wants each contiguous segment of N/2 soldiers to contain an even number of Targaryen soldiers.
Formally you are given a binary string of length N, where N is an even natural number. Each character of the string is either '0' or '1'. You want to rearrange the elements of the string in such a way that the final string contains an even number of 1s in each contiguous subsegment of length N/2.
Your task is to find out whether there exists a rearrangement of the soldiers that satisfies the above conditions.The first line contains an integer T, the number of test cases. Then, T test cases follow.
The first line of each test case contains an even positive integer N, the length of the line.
The second line of each test case contains a binary string of length N, representing the current arrangement of soldiers.
<b> Constraints: </b>
1 ≤ T ≤ 10
2 ≤ N ≤ 10<sup>4</sup>
N is evenPrint a single character in a new line for each test case. Print '1' (without quotes) if a required rearrangement exists, and '0' (without quotes) otherwise.Sample Input:
3
2
10
2
00
4
0011
Sample Output:
0
1
0
(In the last case, no matter how you rearrange the string, there will always be a single one in at least one subsegment of length 2 of the string), I have written this Solution Code: T=int(input())
for i in range(T):
n=int(input())
a=input()
count_1=0
for i in a:
if i=='1':
count_1+=1
if count_1%2==0 and ((count_1)//2)%2==0:
print('1')
else:
print('0'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: This is a time of conflict in Westeros as Viserys Targaryen, the king of all seven kingdoms, rejected the hand of Lady Laena Velaryon. So, the Velaryon soldiers are not deemed trustworthy anymore. The Targaryen soldiers have to keep an eye on them.
You are given a sequential order of N soldiers standing in a line. The order is provided as a binary string, with 0 representing Velaryon soldiers, and 1 representing the Targaryen soldiers. Viserys wants each contiguous segment of N/2 soldiers to contain an even number of Targaryen soldiers.
Formally you are given a binary string of length N, where N is an even natural number. Each character of the string is either '0' or '1'. You want to rearrange the elements of the string in such a way that the final string contains an even number of 1s in each contiguous subsegment of length N/2.
Your task is to find out whether there exists a rearrangement of the soldiers that satisfies the above conditions.The first line contains an integer T, the number of test cases. Then, T test cases follow.
The first line of each test case contains an even positive integer N, the length of the line.
The second line of each test case contains a binary string of length N, representing the current arrangement of soldiers.
<b> Constraints: </b>
1 ≤ T ≤ 10
2 ≤ N ≤ 10<sup>4</sup>
N is evenPrint a single character in a new line for each test case. Print '1' (without quotes) if a required rearrangement exists, and '0' (without quotes) otherwise.Sample Input:
3
2
10
2
00
4
0011
Sample Output:
0
1
0
(In the last case, no matter how you rearrange the string, there will always be a single one in at least one subsegment of length 2 of the string), I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
signed main() {
int t;
cin >> t;
for(int i=0; i<t; i++) {
int n;
cin >> n;
string s;
cin >> s;
int cnt = 0;
for(int j=0; j<n; j++) {
if(s[j] == '1') cnt++;
}
if(cnt % 4 == 0) cout << 1 << "\n";
else cout << 0 << "\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Insertion is a basic but frequently used operation. Arrays in most languages cannnot be dynamically shrinked or expanded. Here, we will work with such arrays and try to insert an element at the end of array.
You are given an array arr. The size of the array is N. You need to insert an element at its end and print this newly modified array.The first line of input contains T denoting the number of testcases.
T testcases follow. Each testcase contains two lines of input.
The first line contains size of the array denoted by N and element to be inserted.
The third line contains N elements separated by spaces.
Constraints:
1 <= T <= 20
2 <= N <= 10000
0 <= element, arri <= 10^6For each testcase, in a new line, print the modified array.Input:
2
5 90
1 2 3 4 5
3 50
1 2 3
Output:
1 2 3 4 5 90
1 2 3 50
Explanation:
Testcase 1: After inserting 90 at end, we have array elements as 1 2 3 4 5 90.
Testcase 2: After inserting 50 at end, we have array elements as 1 2 3 50., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--) {
long int n, el;
cin>>n>>el;
long int arr[n+1];
for(long int i=0; i<n; i++) {
cin>>arr[i];
}
arr[n] = el;
for(long int i=0; i<=n; i++) {
cout<<arr[i];
if (i != n) {
cout<<" ";
}
else if(t != 0) {
cout<<endl;
}
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Insertion is a basic but frequently used operation. Arrays in most languages cannnot be dynamically shrinked or expanded. Here, we will work with such arrays and try to insert an element at the end of array.
You are given an array arr. The size of the array is N. You need to insert an element at its end and print this newly modified array.The first line of input contains T denoting the number of testcases.
T testcases follow. Each testcase contains two lines of input.
The first line contains size of the array denoted by N and element to be inserted.
The third line contains N elements separated by spaces.
Constraints:
1 <= T <= 20
2 <= N <= 10000
0 <= element, arri <= 10^6For each testcase, in a new line, print the modified array.Input:
2
5 90
1 2 3 4 5
3 50
1 2 3
Output:
1 2 3 4 5 90
1 2 3 50
Explanation:
Testcase 1: After inserting 90 at end, we have array elements as 1 2 3 4 5 90.
Testcase 2: After inserting 50 at end, we have array elements as 1 2 3 50., I have written this Solution Code: t=int(input())
while t>0:
t-=1
li = list(map(int,input().strip().split()))
n=li[0]
num=li[1]
a= list(map(int,input().strip().split()))
a.insert(len(a),num)
for i in a:
print(i,end=" ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Insertion is a basic but frequently used operation. Arrays in most languages cannnot be dynamically shrinked or expanded. Here, we will work with such arrays and try to insert an element at the end of array.
You are given an array arr. The size of the array is N. You need to insert an element at its end and print this newly modified array.The first line of input contains T denoting the number of testcases.
T testcases follow. Each testcase contains two lines of input.
The first line contains size of the array denoted by N and element to be inserted.
The third line contains N elements separated by spaces.
Constraints:
1 <= T <= 20
2 <= N <= 10000
0 <= element, arri <= 10^6For each testcase, in a new line, print the modified array.Input:
2
5 90
1 2 3 4 5
3 50
1 2 3
Output:
1 2 3 4 5 90
1 2 3 50
Explanation:
Testcase 1: After inserting 90 at end, we have array elements as 1 2 3 4 5 90.
Testcase 2: After inserting 50 at end, we have array elements as 1 2 3 50., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n =Integer.parseInt(br.readLine().trim());
while(n-->0){
String str[]=br.readLine().trim().split(" ");
String newel =br.readLine().trim()+" "+str[1];
System.out.println(newel);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given four integers a, b, c, and d. Find the value of a<sup>(b<sup>(c<sup>d</sup>)</sup>)</sup> modulo 1000000007.
(Fact: 0<sup>0</sup> = 1)The first and the only line of input contains 4 integers a, b, c, and d.
Constraints
1 <= a, b, c, d <= 12Output a single integer, the answer modulo 1000000007.Sample Input
2 2 2 2
Sample Output
65536
Explanation
2^(2^(2^2)) = 2^(2^4) = 2^16 = 65536.
Sample Input
0 7 11 1
Sample Output
0, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.math.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader sc= new BufferedReader(new InputStreamReader(System.in));
int a=0, b=0, c=0, d=0;
long z=0;
String[] str;
str = sc.readLine().split(" ");
a= Integer.parseInt(str[0]);
b= Integer.parseInt(str[1]);
c= Integer.parseInt(str[2]);
d= Integer.parseInt(str[3]);
BigInteger m = new BigInteger("1000000007");
BigInteger n = new BigInteger("1000000006");
BigInteger zero = new BigInteger("0");
BigInteger ans, y;
if(d==0){
z =1;
}else{
z = (long)Math.pow(c, d);
}
if(b==0){
y= zero;
}else{
y = (BigInteger.valueOf(b)).modPow((BigInteger.valueOf(z)), n);
}
if(y == zero){
System.out.println("1");
}else if(a==0){
System.out.println("0");
}else{
ans = (BigInteger.valueOf(a)).modPow(y, m);
System.out.println(ans);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given four integers a, b, c, and d. Find the value of a<sup>(b<sup>(c<sup>d</sup>)</sup>)</sup> modulo 1000000007.
(Fact: 0<sup>0</sup> = 1)The first and the only line of input contains 4 integers a, b, c, and d.
Constraints
1 <= a, b, c, d <= 12Output a single integer, the answer modulo 1000000007.Sample Input
2 2 2 2
Sample Output
65536
Explanation
2^(2^(2^2)) = 2^(2^4) = 2^16 = 65536.
Sample Input
0 7 11 1
Sample Output
0, I have written this Solution Code: nan, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given four integers a, b, c, and d. Find the value of a<sup>(b<sup>(c<sup>d</sup>)</sup>)</sup> modulo 1000000007.
(Fact: 0<sup>0</sup> = 1)The first and the only line of input contains 4 integers a, b, c, and d.
Constraints
1 <= a, b, c, d <= 12Output a single integer, the answer modulo 1000000007.Sample Input
2 2 2 2
Sample Output
65536
Explanation
2^(2^(2^2)) = 2^(2^4) = 2^16 = 65536.
Sample Input
0 7 11 1
Sample Output
0, 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
int powmod(int a, int b, int c = MOD){
int ans = 1;
while(b){
if(b&1){
ans = (ans*a)%c;
}
a = (a*a)%c;
b >>= 1;
}
return ans;
}
void solve(){
int a, b, c, d; cin>>a>>b>>c>>d;
int x = pow(c, d);
int y = powmod(b, x, MOD-1);
int ans = powmod(a, y, MOD);
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 an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A.
In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers.
Constraints
1 <= N <= 100
1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1
4
1 2 6 4
output-1
3 10
input-2
10
1 2 3 4 5 6 0 7 8 9
output-2
3 7 11 7 17
Explanation(might now be the optimal solution):
Testcase 1:
Follow the below steps:-
Step 1: [1 2 6 4]
Step 2: (1 2) and (6 4)
Step 3: 3 10, I have written this Solution Code: n = int(input())
all_no = input().split(' ')
i = 0
joined_str = ''
while(i < n-1):
if(i == 0):
joined_str = str(int(all_no[i]) + int(all_no[i+1]))
else:
joined_str = joined_str + ' ' + str(int(all_no[i]) + int(all_no[i+1]))
i = i + 2
print(joined_str), 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 (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A.
In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers.
Constraints
1 <= N <= 100
1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1
4
1 2 6 4
output-1
3 10
input-2
10
1 2 3 4 5 6 0 7 8 9
output-2
3 7 11 7 17
Explanation(might now be the optimal solution):
Testcase 1:
Follow the below steps:-
Step 1: [1 2 6 4]
Step 2: (1 2) and (6 4)
Step 3: 3 10, 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 a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int t;
for(int i=0;i<n;i+=2){
System.out.print(a[i]+a[i+1]+" ");
}
}
}, 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 (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A.
In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers.
Constraints
1 <= N <= 100
1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1
4
1 2 6 4
output-1
3 10
input-2
10
1 2 3 4 5 6 0 7 8 9
output-2
3 7 11 7 17
Explanation(might now be the optimal solution):
Testcase 1:
Follow the below steps:-
Step 1: [1 2 6 4]
Step 2: (1 2) and (6 4)
Step 3: 3 10, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i+=2){
cout<<a[i]+a[i+1]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Initialize two variables <code>name</code> and <code>age</code> with values of data types <code>string</code> and <code>number</code> respectively.
Create another variable <code>greet</code> with the value of "My name is <code>name</code> and I am <code>age</code> years old" and print the value of <code>greet</code> in the console.
Note: Generate Expected Output section will not work for this question
DO NOT CONSOLE.LOG the variables, just declare them.There is no input required for this questionThere is no output required for this questionIf value of <code>name</code> is Raj and value of <code>age</code> is 18, then <code>greet</code> should be storing "My name is Raj and I am 18 years old", I have written this Solution Code: const name = "John Doe";
const age = 30;
const greet = `My name is ${name} and I am ${age} years old`;
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program print total number of days in a month using switch case.First line of the input contains Month Number
<b>Constraints</b>
1 <= Month <= 12Print total number of days in a month (in general).Sample Input :
3
Sample Output :
31, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int month=sc.nextInt();
switch(month)
{
case 1:
System.out.println("31");
break;
case 2:
System.out.println("28");
break;
case 3:
System.out.println("31");
break;
case 4:
System.out.println("30");
break;
case 5:
System.out.println("31");
break;
case 6:
System.out.println("30");
break;
case 7:
System.out.println("31");
break;
case 8:
System.out.println("31");
break;
case 9:
System.out.println("30");
break;
case 10:
System.out.println("31");
break;
case 11:
System.out.println("30");
break;
case 12:
System.out.println("31");
break;
default:
System.out.println("invalid month");
break;
} }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program print total number of days in a month using switch case.First line of the input contains Month Number
<b>Constraints</b>
1 <= Month <= 12Print total number of days in a month (in general).Sample Input :
3
Sample Output :
31, I have written this Solution Code: def MonthDays(N):
if N==1 or N==3 or N==5 or N==7 or N==8 or N==10 or N==12:
print(31)
elif N==4 or N==6 or N==9 or N==11:
print(30)
elif N==2:
print(28)
else:
print("Months out of range")
N = int(input())
MonthDays(N), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program print total number of days in a month using switch case.First line of the input contains Month Number
<b>Constraints</b>
1 <= Month <= 12Print total number of days in a month (in general).Sample Input :
3
Sample Output :
31, I have written this Solution Code: #include <stdio.h>
int main()
{
int month;
scanf("%d", &month);
switch(month)
{
case 1:
printf("31");
break;
case 2:
printf("28");
break;
case 3:
printf("31");
break;
case 4:
printf("30");
break;
case 5:
printf("31");
break;
case 6:
printf("30");
break;
case 7:
printf("31");
break;
case 8:
printf("31");
break;
case 9:
printf("30");
break;
case 10:
printf("31");
break;
case 11:
printf("30");
break;
case 12:
printf("31");
break;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S you have to remove all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, remove them as well. Repeat this untill no adjacent letter in the string is same.
Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.The input data consists of a single string S.
Constraints:
1 <= |S| <= 100000
S contains lowercase english letters only.Print the given string after it is processed. It is guaranteed that the result will contain at least one character.Sample Input
hhoowaaaareyyoouu
Sample Output
wre
Explanation:
First we remove "hh" then "oo" then "aa" then "yy" then "oo" then "uu" and we are left with "wre".
Now we cannot remove anything.
Sample Input:-
abcde
Sample Output:-
abcde
Sample Input:-
abcddcb
Sample Output:-
a, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
StringBuilder s = new StringBuilder();
String text=null;
while ((text = in.readLine ()) != null)
{
s.append(text);
}
int len=s.length();
for(int i=0;i<len-1;i++){
if(s.charAt(i)==s.charAt(i+1)){
int flag=0;
s.delete(i,i+2);
int left=i-1;
len=len-2;
i=i-2;
if(i<0){
i=-1;
}
}
}
System.out.println(s);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S you have to remove all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, remove them as well. Repeat this untill no adjacent letter in the string is same.
Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.The input data consists of a single string S.
Constraints:
1 <= |S| <= 100000
S contains lowercase english letters only.Print the given string after it is processed. It is guaranteed that the result will contain at least one character.Sample Input
hhoowaaaareyyoouu
Sample Output
wre
Explanation:
First we remove "hh" then "oo" then "aa" then "yy" then "oo" then "uu" and we are left with "wre".
Now we cannot remove anything.
Sample Input:-
abcde
Sample Output:-
abcde
Sample Input:-
abcddcb
Sample Output:-
a, I have written this Solution Code: s=input()
l=["aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk","ll","mm","nn","oo","pp","qq","rr","ss","tt","uu","vv","ww","xx","yy","zz"]
while True:
do=False
for i in range(len(l)):
if l[i] in s:
do=True
while l[i] in s:
s=s.replace(l[i],"")
if do==False:
break
print(s), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S you have to remove all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, remove them as well. Repeat this untill no adjacent letter in the string is same.
Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.The input data consists of a single string S.
Constraints:
1 <= |S| <= 100000
S contains lowercase english letters only.Print the given string after it is processed. It is guaranteed that the result will contain at least one character.Sample Input
hhoowaaaareyyoouu
Sample Output
wre
Explanation:
First we remove "hh" then "oo" then "aa" then "yy" then "oo" then "uu" and we are left with "wre".
Now we cannot remove anything.
Sample Input:-
abcde
Sample Output:-
abcde
Sample Input:-
abcddcb
Sample Output:-
a, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main(){
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
string s;
cin>>s;
int len=s.length();
char stk[410000];
int k = 0;
for (int i = 0; i < len; i++)
{
stk[k++] = s[i];
while (k > 1 && stk[k - 1] == stk[k - 2])
k -= 2;
}
for (int i = 0; i < k; i++)
cout << stk[i];
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string s, find the first non-repeating character in the string and return its index. If it does not exist, return -1.First line of the input contains the string s.
<b>Constraints</b>
1<= s. length <= 100000Print the index of the first non- repeating character in a stringInput
s = "newtonschool"
Output
1
Explanation
"e" is the first non- repeating character in a string, 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();
System.out.print(nonRepeatChar(s));
}
static int nonRepeatChar(String s){
char count[] = new char[256];
for(int i=0; i< s.length(); i++){
count[s.charAt(i)]++;
}
for (int i=0; i<s.length(); i++) {
if (count[s.charAt(i)]==1){
return i;
}
}
return -1;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string s, find the first non-repeating character in the string and return its index. If it does not exist, return -1.First line of the input contains the string s.
<b>Constraints</b>
1<= s. length <= 100000Print the index of the first non- repeating character in a stringInput
s = "newtonschool"
Output
1
Explanation
"e" is the first non- repeating character in a string, I have written this Solution Code: from collections import defaultdict
s=input()
d=defaultdict(int)
for i in s:
d[i]+=1
ans=-1
for i in range(len(s)):
if(d[s[i]]==1):
ans=i
break
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string s, find the first non-repeating character in the string and return its index. If it does not exist, return -1.First line of the input contains the string s.
<b>Constraints</b>
1<= s. length <= 100000Print the index of the first non- repeating character in a stringInput
s = "newtonschool"
Output
1
Explanation
"e" is the first non- repeating character in a string, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-10 12:51:16
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int firstUniqChar(string s) {
map<char, int> charCount;
int len = s.length();
for (int i = 0; i < len; i++) {
charCount[s[i]]++;
}
for (int i = 0; i < len; i++) {
if (charCount[s[i]] == 1)
return i;
}
return -1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string str;
cin>>str;
cout<<firstUniqChar(str)<<"\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code:
char Race(int A, int B, int C){
if(abs(C-A)==abs(C-B)){return 'D';}
if(abs(C-A)>abs(C-B)){return 'S';}
else{
return 'N';}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code: def Race(A,B,C):
if abs(C-A) ==abs(C-B):
return 'D'
if abs(C-A)>abs(C-B):
return 'S'
return 'N'
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code:
char Race(int A, int B, int C){
if(abs(C-A)==abs(C-B)){return 'D';}
if(abs(C-A)>abs(C-B)){return 'S';}
else{
return 'N';}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code: static char Race(int A,int B,int C){
if(Math.abs(C-A)==Math.abs(C-B)){return 'D';}
if(Math.abs(C-A)>Math.abs(C-B)){return 'S';}
else{
return 'N';}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The coolness of the subarray of an array is the sum of elements in the subarray. The coolest subarray is the subarray having the maximum coolness, while the hottest subarray is the one having minimum coolness (obviously it can be negative). The coolest and the hottest subarrays are always <b>non-empty</b>.
Tono believes that cool and hot are happy together. The happiness of the array is the absolute difference between the coolness of its coolest and its hottest subarray.
Given an array A consisting of N elements, find its happiness.The first line of the input contains an integer N.
The next line contains N singly spaced integers A[1], A[2],...A[N]
Constraints
1 <= N <= 200000
-1000000000 <= A[i] <= 1000000000Output a single integer, the happiness of the array.
(The output may not fit into 32 bit integer datatype, use long long integer datatype instead).Sample Input
5
-1 2 -3 1 -5
Sample Output
9
Explanation: Coolest subarray of the array is [2], while the hottest subarray of the array is [-3, 1, -5]. The happiness of the array is 2-(-7)=9., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static long KadanesAlgoMax(int[] a,int n)
{
long maxSum=Integer.MIN_VALUE;
long currSum=0;
for(int i=0;i<n;i++)
{
currSum+=a[i];
if(currSum>maxSum)maxSum=currSum;
if(currSum<0)currSum=0;
}
return maxSum;
}
public static long KadanesAlgoMin(int[] a,int n)
{
long minSum=Integer.MAX_VALUE;
long currSum=0;
for(int i=0;i<n;i++)
{
currSum+=a[i];
if(currSum<minSum)minSum=currSum;
if(currSum>0)currSum=0;
}
return minSum;
}
public static void main (String[] args)throws IOException {
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(rd.readLine());
String[] s=rd.readLine().split(" ");
int[] a=new int[n];
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(s[i]);
}
System.out.print((long)Math.abs(KadanesAlgoMax(a,n)-KadanesAlgoMin(a,n)));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The coolness of the subarray of an array is the sum of elements in the subarray. The coolest subarray is the subarray having the maximum coolness, while the hottest subarray is the one having minimum coolness (obviously it can be negative). The coolest and the hottest subarrays are always <b>non-empty</b>.
Tono believes that cool and hot are happy together. The happiness of the array is the absolute difference between the coolness of its coolest and its hottest subarray.
Given an array A consisting of N elements, find its happiness.The first line of the input contains an integer N.
The next line contains N singly spaced integers A[1], A[2],...A[N]
Constraints
1 <= N <= 200000
-1000000000 <= A[i] <= 1000000000Output a single integer, the happiness of the array.
(The output may not fit into 32 bit integer datatype, use long long integer datatype instead).Sample Input
5
-1 2 -3 1 -5
Sample Output
9
Explanation: Coolest subarray of the array is [2], while the hottest subarray of the array is [-3, 1, -5]. The happiness of the array is 2-(-7)=9., I have written this Solution Code: l = int(input())
arr = list(map(int,input().split()))
maxSum = arr[0]
currSum =0
maxSumB = arr[0]
currSumB = 0
for j in range(0,l):
currSum = currSum + arr[j]
if(maxSum>currSum):
maxSum = currSum
if(currSum>0):
currSum = 0
currSumB = currSumB + arr[j]
if(maxSumB<currSumB):
maxSumB = currSumB
if(currSumB<0):
currSumB = 0
print(abs(maxSumB-maxSum)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The coolness of the subarray of an array is the sum of elements in the subarray. The coolest subarray is the subarray having the maximum coolness, while the hottest subarray is the one having minimum coolness (obviously it can be negative). The coolest and the hottest subarrays are always <b>non-empty</b>.
Tono believes that cool and hot are happy together. The happiness of the array is the absolute difference between the coolness of its coolest and its hottest subarray.
Given an array A consisting of N elements, find its happiness.The first line of the input contains an integer N.
The next line contains N singly spaced integers A[1], A[2],...A[N]
Constraints
1 <= N <= 200000
-1000000000 <= A[i] <= 1000000000Output a single integer, the happiness of the array.
(The output may not fit into 32 bit integer datatype, use long long integer datatype instead).Sample Input
5
-1 2 -3 1 -5
Sample Output
9
Explanation: Coolest subarray of the array is [2], while the hottest subarray of the array is [-3, 1, -5]. The happiness of the array is 2-(-7)=9., 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 int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 200005;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
int arr[N];
int n;
int kadane(){
int sum = 0;
int mx = 0;
For(i, 0, n){
sum += arr[i];
if(sum < 0){
sum = 0;
}
mx = max(sum, mx);
}
if(mx > 0)
return mx;
// all elements negative
mx = -10000000000LL;
For(i, 0, n){
mx = max(mx, arr[i]);
}
return mx;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
cin>>n;
For(i, 0, n){
cin>>arr[i];
}
int v1 = kadane();
For(i, 0, n){
arr[i]=-1*arr[i];
}
int v2 = kadane();
cout<<v1+v2;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b>
There will be two functions:
<ul>
<li>verticalFive(): Print stars in vertical order</li>
<li>horizontalFive(): Print stars in horizontal order</l>
</ul><b>User Task:</b>
Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>.
Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function.
<b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input:
Sample Output:
*
*
*
*
*
* * * * *, I have written this Solution Code: static void verticalFive(){
System.out.println("*");
System.out.println("*");
System.out.println("*");
System.out.println("*");
System.out.println("*");
}
static void horizontalFive(){
System.out.print("* * * * *");
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b>
There will be two functions:
<ul>
<li>verticalFive(): Print stars in vertical order</li>
<li>horizontalFive(): Print stars in horizontal order</l>
</ul><b>User Task:</b>
Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>.
Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function.
<b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input:
Sample Output:
*
*
*
*
*
* * * * *, I have written this Solution Code: def vertical5():
for i in range(0,5):
print("*",end="\n")
#print()
def horizontal5():
for i in range(0,5):
print("*",end=" ")
vertical5()
print(end="\n")
horizontal5(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You need to make an order counter to keep track of the total number of orders received.
Complete the function <code> generateOrder() </code> which returns a <code>function func()</code>. This function <code>func</code> should maintain a <code> count (initially 0)</code>. Every time <code>func</code> is called, <code> count</code> must be incremented by 1 and the string <code>"Total orders = " + count</code> must be returned.
<b>Note:</b> The function generateOrder() will be called internally. You do not need to call it yourself. The generateOrder() takes no argument. It is called internally.The generateOrder() function returns a function that returns the string <code>"Total orders = " + count</code>, where <code>count</code> is the number of times the function is called.
const initC = generateOrder(starting);
console.log(initC()) //prints "Total orders = 1"
console.log(initC()) //prints "Total orders = 2"
console.log(initC()) //prints "Total orders = 3"
, I have written this Solution Code: let generateOrder = function() {
let prefix = "Total orders = ";
let count = 0;
let totalOrders = function(){
count++
return prefix + count;
}
return totalOrders;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find the number of prime numbers before N (Including that number too).The first line of the input contains the number of test cases T.
Next T lines contain the value N.
<b>Constraints</b>
1 <= T <= 1e5
1 <= N <= 1e5Print the number of primes number before that number.Sample Input 1:
2
3
11
Sample Output 1:
2
5, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
class Main
{
static int [] booleanArray(int num)
{
boolean [] bool = new boolean[num+1];
int [] count = new int [num+1];
bool[0] = true;
bool[1] = true;
for(int i=2; i*i<=num; i++)
{
if(bool[i]==false)
{
for(int j=i*i; j<=num; j+=i)
bool[j] = true;
}
}
int counter = 0;
for(int i=1; i<=num; i++)
{
if(bool[i]==false)
{
counter = counter+1;
count[i] = counter;
}
else
{
count[i] = counter;
}
}
return count;
}
public static void main (String[] args) throws IOException {
InputStreamReader ak = new InputStreamReader(System.in);
BufferedReader hk = new BufferedReader(ak);
int[] v = booleanArray(100000);
int t = Integer.parseInt(hk.readLine());
for (int i = 1; i <= t; i++) {
int a = Integer.parseInt(hk.readLine());
System.out.println(v[a]);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find the number of prime numbers before N (Including that number too).The first line of the input contains the number of test cases T.
Next T lines contain the value N.
<b>Constraints</b>
1 <= T <= 1e5
1 <= N <= 1e5Print the number of primes number before that number.Sample Input 1:
2
3
11
Sample Output 1:
2
5, I have written this Solution Code: m=100001
prime=[True for i in range(m)]
p=2
while(p*p<=m):
if prime[p]:
for i in range(p*p,m,p):
prime[i]=False
p+=1
c=[0 for i in range(m)]
c[2]=1
for i in range(3,m):
if prime[i]:
c[i]=c[i-1]+1
else:
c[i]=c[i-1]
t=int(input())
while t>0:
n=int(input())
print(c[n])
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find the number of prime numbers before N (Including that number too).The first line of the input contains the number of test cases T.
Next T lines contain the value N.
<b>Constraints</b>
1 <= T <= 1e5
1 <= N <= 1e5Print the number of primes number before that number.Sample Input 1:
2
3
11
Sample Output 1:
2
5, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
vector<bool> sieve(int n) {
vector<bool> is_prime(n + 1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (is_prime[i]) {
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
return is_prime;
}
int main() {
vector<bool> prime = sieve(1e5 + 1);
vector<int> prefix(1e5 + 1, 0);
for (int i = 1; i <= 1e5; i++) {
if (prime[i]) {
prefix[i] = prefix[i - 1] + 1;
} else {
prefix[i] = prefix[i - 1];
}
}
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
cout << prefix[n] << "\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] with N elements, your task is to sort it using counting sort algorithm.The first line of the input contains the number of test cases T. For each test case, the first line contains the number of elements N in the array A and the next line will contain the N elements (space separated) of A[].
Constraints:
1 <= T <= 12
1 <= N <= 100
1 <= A[] <= 100000
For each test case in a new line, you need to print the sorted array using counting sort.Sample Input:
3
4
8 1 3 7
3
1 3 7
6
6 1 3 7 4 9
Sample Output:
1 3 8 7
1 3 7
1 3 4 6 7 9, I have written this Solution Code: t = int(input())
for _ in range(t):
n = int(input())
print(*(sorted(list(map(int,input().split()))))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] with N elements, your task is to sort it using counting sort algorithm.The first line of the input contains the number of test cases T. For each test case, the first line contains the number of elements N in the array A and the next line will contain the N elements (space separated) of A[].
Constraints:
1 <= T <= 12
1 <= N <= 100
1 <= A[] <= 100000
For each test case in a new line, you need to print the sorted array using counting sort.Sample Input:
3
4
8 1 3 7
3
1 3 7
6
6 1 3 7 4 9
Sample Output:
1 3 8 7
1 3 7
1 3 4 6 7 9, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
for(int i=0;i<t;i++){
int n=Integer.parseInt(br.readLine());
int[] ar=new int[n];
String[] i1=br.readLine().split(" ");
for(int j=0;j<n;j++){
ar[j]=Integer.parseInt(i1[j]);
}
Arrays.sort(ar);
for(int y:ar){
System.out.print(y+" ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] with N elements, your task is to sort it using counting sort algorithm.The first line of the input contains the number of test cases T. For each test case, the first line contains the number of elements N in the array A and the next line will contain the N elements (space separated) of A[].
Constraints:
1 <= T <= 12
1 <= N <= 100
1 <= A[] <= 100000
For each test case in a new line, you need to print the sorted array using counting sort.Sample Input:
3
4
8 1 3 7
3
1 3 7
6
6 1 3 7 4 9
Sample Output:
1 3 8 7
1 3 7
1 3 4 6 7 9, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];}
sort(a,a+n);
for(int i=0;i<n;i++){
cout<<a[i]<<" ";}
cout<<endl;}}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of integers called nums. Find the even number with the highest frequency in the array. If there are multiple even numbers with the same highest frequency, return the smallest one. If there are no even numbers in the array, return -1.The first line contains an integer denoting the length of the array "nums".
The following line contains the space- separated integers of the array "nums".
<b>Constraints:</b>
1 ≤ nums. length ≤ 2000
0 ≤ nums[i] ≤ 10<sup>5</sup>Return the most frequent even element. If there are multiple even numbers with the same highest frequency, return the smallest one.Sample Input:
7
0 1 2 2 4 4 1
Sample output:
2
<b>Explanation</b>
The even elements are 0, 2, and 4. Of these, 2 and 4 appear the most.
We return the smallest one, which is 2., I have written this Solution Code: import java.util.*;
class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = sc.nextInt();
}
int result = mostFrequentEven(nums);
System.out.println(result);
}
public static int mostFrequentEven(int[] nums) {
HashMap<Integer, Integer> hap = new HashMap<>();
int n = nums.length;
for (int i = 0; i < n; i++) {
if (nums[i] % 2 == 0)
hap.put(nums[i], hap.getOrDefault(nums[i], 0) + 1);
}
int maxVal = -1;
int maxFreq = -1;
for (int j = 0; j < n; j++) {
if (nums[j] % 2 == 0) {
if (hap.get(nums[j]) > maxFreq) {
maxVal = nums[j];
maxFreq = hap.get(nums[j]);
} else if (hap.get(nums[j]) == maxFreq) {
maxVal = Math.min(maxVal, nums[j]);
}
}
}
return maxVal;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int t; cin >> t;
while(t--){
vector<int> v;
int n, x; cin >> n >> x;
for(int i = 1; i <= n; i++){
int p; cin >> p;
if(p == x)
v.push_back(i-1);
}
if(v.size() == 0)
cout << "Not found\n";
else{
for(auto i: v)
cout << i << " ";
cout << endl;
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, I have written this Solution Code: def position(n,arr,x):
res = []
cnt = 0
for i in arr:
if(i == x):
res.append(cnt)
cnt += 1
return res
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main (String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t =Integer.parseInt(read.readLine());
while(t-- > 0)
{
String str[] = read.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
int x = Integer.parseInt(str[1]);
int arr[] = new int[n];
str = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
findPositions(arr, n, x);
}
}
static void findPositions(int arr[], int n, int x)
{
boolean flag = false;
StringBuffer sb = new StringBuffer();
for(int i = 0; i < n; i++)
{
if(arr[i] == x)
{
sb.append(i + " ");
flag = true;
}
}
if(flag ==true)
System.out.println(sb.toString());
else System.out.println("Not found");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John and Olivia once start fighting when Olivia sees John talking with another girl. So, you tell them to play the game of love in which you give them an array A of size N. Now, the game will play in turns in which a player must decrease the value at the smallest index (with a non-zero value) in A by x (x > 0). The player who cannot make a move will lose the game.
You being a loyal friend of Olivia, wants her to win. So, tell Olivia whether she should move first or second to win this game.
Assume both players will play optimally at every step of the game.The first line contains a single integer T (1 ≤ T ≤ 1000) — the number of test cases.
The first line of each test case contains a single integer N (1 ≤ N ≤ 100) — the size of the array A on which the game is to be played.
.
The second line contains n integers A<sub>1</sub>, A<sub>2</sub>, …, A<sub>N</sub> (1 ≤ A<sub>i</sub> ≤ 10<sup>9</sup>).For each test case, print on a new line whether Olivia should move "first" or "second" (without quotes) to win the game.Sample Input:
2
3
2 1 3
2
1 1
Sample Output:
first
second
Sample Explanation:
For the first test case, Olivia will remove 2 from the 1st index, then John has to remove 1 from the 2nd index, and finally, Olivia will remove 3 from the 3rd index.
For the second test case, John has to remove 1 from the 1st index, then Olivia removes 1 from the 2nd index., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<int> v(n);
bool ok=1;
for(auto &i:v) cin >> i;
int ans=1;
for(auto i:v){
if(i!=1) ok=0;
if(i==1) ans^=1;
else break;
}
if(!ok){
if(ans){
cout << "first\n";
}else{
cout << "second\n";
}
}else{
if(n&1){
cout << "first\n";
}else{
cout << "second\n";
}
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton has a sequence of N words. He wants to make sure that all the words after the first word follow a specific pattern i. e. they should start with letter same as the previous word ending letter and they should not have occurred before.
You are given all the words, tell whether they follow the pattern set by Newton or not. Print "Yes" if they follow, otherwise print "No"The first line of the input consists of an integer N
Each of the next N lines contains a string S<sub>i</sub>
<b>Constraints</b>:
2 <= N <= 10<sup>5</sup>
1 <= |Si| <= 100Output the answer.Sample Input 1:
3
newton
school
discord
Sample Output 1:
No
Explanation:
2nd and 3rd word doesn't start with the previous word ending letter
Sample Input 2:
3
newton
newton
newton
Sample Output 2:
No
Explanation:
Same word "newton" occurring multiple times
Sample Input 3:
3
yash
hsay
yay
Sample Output 3:
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<String> li = new ArrayList<>();
for (int i = 0; i < n; i++) {
li.add(sc.next());
}
System.out.println((validWord(li, n)) ? "Yes" : "No");
}
public static boolean validWord(ArrayList<String> li, int n) {
for (int i = 0; i < n - 1; i++) {
String strFirst = li.get(i);
String strSecond = li.get(i + 1);
if ((li.lastIndexOf(strFirst) != i) || (strFirst.charAt(strFirst.length() - 1) != strSecond.charAt(0)))
return false;
}
return true;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton has a sequence of N words. He wants to make sure that all the words after the first word follow a specific pattern i. e. they should start with letter same as the previous word ending letter and they should not have occurred before.
You are given all the words, tell whether they follow the pattern set by Newton or not. Print "Yes" if they follow, otherwise print "No"The first line of the input consists of an integer N
Each of the next N lines contains a string S<sub>i</sub>
<b>Constraints</b>:
2 <= N <= 10<sup>5</sup>
1 <= |Si| <= 100Output the answer.Sample Input 1:
3
newton
school
discord
Sample Output 1:
No
Explanation:
2nd and 3rd word doesn't start with the previous word ending letter
Sample Input 2:
3
newton
newton
newton
Sample Output 2:
No
Explanation:
Same word "newton" occurring multiple times
Sample Input 3:
3
yash
hsay
yay
Sample Output 3:
Yes, I have written this Solution Code: x=int(input())
l=[]
s=set()
for i in range(x):
y=input()
l.append(y)
s.add(y)
if len(s)==x:
n=len(l)
for i in range(n-1):
if l[i][-1]==l[i+1][0]:
if i==n-2:
print("Yes")
else:
print("No")
break
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton has a sequence of N words. He wants to make sure that all the words after the first word follow a specific pattern i. e. they should start with letter same as the previous word ending letter and they should not have occurred before.
You are given all the words, tell whether they follow the pattern set by Newton or not. Print "Yes" if they follow, otherwise print "No"The first line of the input consists of an integer N
Each of the next N lines contains a string S<sub>i</sub>
<b>Constraints</b>:
2 <= N <= 10<sup>5</sup>
1 <= |Si| <= 100Output the answer.Sample Input 1:
3
newton
school
discord
Sample Output 1:
No
Explanation:
2nd and 3rd word doesn't start with the previous word ending letter
Sample Input 2:
3
newton
newton
newton
Sample Output 2:
No
Explanation:
Same word "newton" occurring multiple times
Sample Input 3:
3
yash
hsay
yay
Sample Output 3:
Yes, I have written this Solution Code: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(){
int n, i, j;
vector<string> str;
string moji;
char sta, fin;
cin >> n;
for(i = 0; i < n; i++){
cin >> moji;
str.push_back(moji);
}
for(i = 1; i < n; i++){
for(j = 0; j < i; j++){
if(str[i] == str[j]){
cout << "No";
return 0;
}
}
}
for(i = 1; i < n; i++){
sta = str[i][0];
fin = str[i - 1][str[i - 1].size() - 1];
if(sta != fin){
cout << "No";
return 0;
}
}
cout << "Yes" << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to calculate the sum of bit difference in all pairs which can be formed.The first line of input contains a single integer N, the second line of input contains N space separated integers depicting values of the array.
Constraints:-
1 <= N <= 100000
0 <= Arr[i] <= 1000000000Print the sum of bit difference of all possible pairs.
Note:- Since the answer can be quite large print your answer modulo 10<sup>9</sup> + 7Sample Input:-
2
1 3
Sample Output:-
2
Explanation:-
(1, 1) = 0
(1, 3) = 1
(3, 1) = 1
(3, 3) = 0
Sample Input:-
2
1 2
Sample Output:-
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));
int n=Integer.parseInt(br.readLine());
String str[]=br.readLine().split(" ");
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=Integer.parseInt(str[i]);
}
long res=0;
for (int i=0;i<32;i++){
long cnt=0;
for (int j=0;j<n;j++)
if ((a[j] & (1 << i)) == 0)
cnt++;
res=(res+(cnt*(n-cnt)*2))%1000000007;
}
System.out.println(res%1000000007);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to calculate the sum of bit difference in all pairs which can be formed.The first line of input contains a single integer N, the second line of input contains N space separated integers depicting values of the array.
Constraints:-
1 <= N <= 100000
0 <= Arr[i] <= 1000000000Print the sum of bit difference of all possible pairs.
Note:- Since the answer can be quite large print your answer modulo 10<sup>9</sup> + 7Sample Input:-
2
1 3
Sample Output:-
2
Explanation:-
(1, 1) = 0
(1, 3) = 1
(3, 1) = 1
(3, 3) = 0
Sample Input:-
2
1 2
Sample Output:-
4, I have written this Solution Code: def suBD(arr, n):
ans = 0 # Initialize result
for i in range(0, 64):
count = 0
for j in range(0, n):
if ( (arr[j] & (1 << i)) ):
count+= 1
ans += (count * (n - count)) * 2;
return (ans)%(10**9+7)
n=int(input())
arr = map(int,input().split())
arr=list(arr)
print(suBD(arr, n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to calculate the sum of bit difference in all pairs which can be formed.The first line of input contains a single integer N, the second line of input contains N space separated integers depicting values of the array.
Constraints:-
1 <= N <= 100000
0 <= Arr[i] <= 1000000000Print the sum of bit difference of all possible pairs.
Note:- Since the answer can be quite large print your answer modulo 10<sup>9</sup> + 7Sample Input:-
2
1 3
Sample Output:-
2
Explanation:-
(1, 1) = 0
(1, 3) = 1
(3, 1) = 1
(3, 3) = 0
Sample Input:-
2
1 2
Sample Output:-
4, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 101
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}signed main(){
int N;
cin>>N;
int a[55];
int A[N];
FOR(i,N){
cin>>A[i];}
for(int i=0;i<55;i++){
a[i]=0;
}
int ans=1,p=2;
for(int i=0;i<55;i++){
for(int j=0;j<N;j++){
if(ans&A[j]){a[i]++;}
}
ans*=p;
// out(ans);
}
ans=0;
for(int i=0;i<55;i++){
ans+=(a[i]*(N-a[i])*2);
ans%=MOD;
}
out(ans);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given one element K your task is to print the maximum element from the array which is less than or equal to the given element(Floor), and the minimum element from the array which is greater than or equal to the given element(Ceil).<b>In case of Java only</b>
<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>floorAndCeil()</b> that takes the array a[], integer N and integer k as arguments.
<b>Custom Input</b>
The first line of input contains a single integer N. The Second line of input contains N space-separated integers depicting the values of the array. The third line of input contains a single integer Q. The next Q line of input contains a single integer the value of K.
Constraints:-
1 <= N <= 100000
1 <= K, Arr[i] <= 1000000000000
1 <= Q <= 10000In a new line Print two space-separated integers depicting the values of Floor and Ceil of the given number. If the floor or ceil of the element does not exist print -1.Sample Input:-
5
2 5 6 11 15
5
2
4
8
1
16
Sample Output:-
2 2
2 5
6 11
-1 2
15 -1, I have written this Solution Code: n = int(input())
arr = list(map(int,input().split()))
t = int(input())
def findFloor(arr, l, h, x, res):
if(l<=h):
m = l+(h-l)//2
if(arr[m] == x):
return m
if(arr[m] > x):
return findFloor(arr, l, m-1, x, res)
if(arr[m] < x):
res = m
return findFloor(arr, m+1, h, x, res)
else:
return res
def findCeil(arr, l, h, x, res):
if(l<=h):
m = l+(h-l)//2
if(arr[m] == x):
return m
if(arr[m] < x):
return findCeil(arr, m+1, h, x, res)
res = m
return findCeil(arr, l, m-1, x, res)
else:
return res
for _ in range(t):
x = int(input())
f = findFloor(arr, 0, n-1, x, -1)
c = findCeil(arr, 0, n-1, x, -1)
floor = -1
ceil = -1
if(f!=-1):
floor = arr[f]
if(c!=-1):
ceil = arr[c]
print(floor,ceil), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given one element K your task is to print the maximum element from the array which is less than or equal to the given element(Floor), and the minimum element from the array which is greater than or equal to the given element(Ceil).<b>In case of Java only</b>
<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>floorAndCeil()</b> that takes the array a[], integer N and integer k as arguments.
<b>Custom Input</b>
The first line of input contains a single integer N. The Second line of input contains N space-separated integers depicting the values of the array. The third line of input contains a single integer Q. The next Q line of input contains a single integer the value of K.
Constraints:-
1 <= N <= 100000
1 <= K, Arr[i] <= 1000000000000
1 <= Q <= 10000In a new line Print two space-separated integers depicting the values of Floor and Ceil of the given number. If the floor or ceil of the element does not exist print -1.Sample Input:-
5
2 5 6 11 15
5
2
4
8
1
16
Sample Output:-
2 2
2 5
6 11
-1 2
15 -1, I have written this Solution Code: static void floorAndCeil(int a[], int n, int x){
int it = lower(a,n,x);
if(it==0){
if(a[it]==x){
System.out.println(x+" "+x);
}
else{
System.out.println("-1 "+a[it]);
}
}
else if (it==n){
it--;
System.out.println(a[it]+" -1");
}
else{
if(a[it]==x){
System.out.println(x+" "+x);
}
else{
it--;
System.out.println(a[it]+" "+a[it+1]);
}
}
}
static int lower(int a[], int n,int k){
int l=0;
int h=n-1;
int m;
int ans=n;
while(l<=h){
m=l+h;
m/=2;
if(a[m]<k){
l=m+1;
}
else{
h=m-1;
ans=m;
}
}
return ans;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given one element K your task is to print the maximum element from the array which is less than or equal to the given element(Floor), and the minimum element from the array which is greater than or equal to the given element(Ceil).<b>In case of Java only</b>
<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>floorAndCeil()</b> that takes the array a[], integer N and integer k as arguments.
<b>Custom Input</b>
The first line of input contains a single integer N. The Second line of input contains N space-separated integers depicting the values of the array. The third line of input contains a single integer Q. The next Q line of input contains a single integer the value of K.
Constraints:-
1 <= N <= 100000
1 <= K, Arr[i] <= 1000000000000
1 <= Q <= 10000In a new line Print two space-separated integers depicting the values of Floor and Ceil of the given number. If the floor or ceil of the element does not exist print -1.Sample Input:-
5
2 5 6 11 15
5
2
4
8
1
16
Sample Output:-
2 2
2 5
6 11
-1 2
15 -1, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int n;
cin>>n;
vector<int> v;
int x;
FOR(i,n){
cin>>x;
v.EB(x);}
int q;
cin>>q;
while(q--){
cin>>x;
auto it = lower_bound(v.begin(),v.end(),x);
if(it==v.begin()){
if(*it==x){
cout<<x<<" "<<x;
}
else{
cout<<-1<<" "<<*it;
}
}
else if (it==v.end()){
it--;
cout<<*it<<" -1";
}
else{
if(*it==x){
cout<<x<<" "<<x;
}
else{
it--;
cout<<*it<<" ";
it++;
cout<<*it;}
}
END;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet.
Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number.
Constraints
2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1
2
Sample Output 1
21
Sample Input 2
4
Sample Output
1008
Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
long n = Long.parseLong(rdr.readLine());
if(n==0 || n==1){
return ;
}
if(n==2){
System.out.println(21);
}
else{
StringBuilder str= new StringBuilder();
str.append("1");
for(long i=0;i<n-3;i++){
str.append("0");
}
if(n%6==0){
str.append("02");
System.out.println(str.toString());
}
else if(n%6==1){
str.append("20");
System.out.println(str.toString());
}
else if(n%6==2){
str.append("11");
System.out.println(str.toString());
}
else if(n%6==3){
str.append("05");
System.out.println(str.toString());
}
if(n%6==4){
str.append("08");
System.out.println(str.toString());
return;
}
else if(n%6==5){
str.append("17");
System.out.println(str.toString());
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet.
Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number.
Constraints
2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1
2
Sample Output 1
21
Sample Input 2
4
Sample Output
1008
Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: n = input()
n=int(n)
n1=10**(n-1)
n2=10**(n)
while(n1<n2):
if((n1%3==0) and (n1%7==0)):
print(n1)
break
n1 = n1+1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet.
Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number.
Constraints
2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1
2
Sample Output 1
21
Sample Input 2
4
Sample Output
1008
Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(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 int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 100005;
// 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
signed main()
{
fast
int n; cin>>n;
if(n==2){
cout<<"21";
return 0;
}
int mod=1;
for(int i=2; i<=n; i++){
mod = (mod*10)%7;
}
int av = 2;
mod = (mod+2)%7;
while(mod != 0){
av += 3;
mod = (mod+3)%7;
}
string sav = to_string(av);
if(sz(sav)==1){
sav.insert(sav.begin(), '0');
}
string ans = "1";
for(int i=0; i<n-3; i++){
ans += '0';
}
ans += sav;
cout<<ans;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a query to delete a user with id = 38 from users table ;
<schema> [{'name': 'users', 'columns': [{ 'name': 'id', 'type': 'int' },{ 'name': 'username', 'type': 'varchar' },{ 'name': 'email', 'type': 'varchar' },{ 'name': 'remember_token', 'type': 'varchar' },{ 'name': 'created_at', 'type': 'datetime' },{ 'name': 'updated_at', 'type': 'datetime' },{ 'name': 'password_digest', 'type': 'varchar' }]},{'name': 'tweets', 'columns': [{ 'name': 'id', 'type': 'int' },{ 'name': 'content', 'type': 'varchar' },{ 'name': 'created_at', 'type': 'datetime' },{ 'name': 'updated_at', 'type': 'datetime' }]},{'name': 'UserTweetRelation', 'columns': [{ 'name': 'id', 'type': 'int' },{ 'name': 'created_at', 'type': 'datetime' },{ 'name': 'retweet', 'type': 'boolean' },{ 'name': 'user_id', 'type': 'varchar' },{ 'name': 'tweet_id', 'type': 'varchar' }]},{'name': 'relationships', 'columns': [{ 'name': 'id', 'type': 'int' },{ 'name': 'created_at', 'type': 'datetime' },{ 'name': 'updated_at', 'type': 'datetime' },{ 'name': 'follower_id', 'type': 'int' },{ 'name': 'followed_id', 'type': 'int' }]}]</schema>nannannan, I have written this Solution Code: delete from users where id = 3 ; , In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr with N distinct integers from 1 to N. If you are currently at index i then in a single jump you move to the index Arr[i]. You start at standing at index 1. Find the index you will be after K jumps.First line of input contains two integers N and K.
Second line of input contains N integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= K <= 1000000000000
1 <= Arr[i] <= NPrint the index you will be on after K jumps.Sample Input 1
5 3
3 4 2 5 1
Sample Output 1
4
Explanation:
You start at index 1
After first jump you reach index 3
After second jump you reach index 2
After third jump you reach index 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer str = new StringTokenizer(read.readLine());
int N = Integer.parseInt(str.nextToken());
long K = Long.parseLong(str.nextToken());
int[] arr = new int[N];
StringTokenizer newStr = new StringTokenizer(read.readLine());
for(int i=0; i<N; i++) {
arr[i] = Integer.parseInt(newStr.nextToken());
}
long count = 0;
int ele = 1;
long copyOfK = K;
while(K > 0) {
ele = arr[ele - 1];
count++;
K--;
if(ele == 1) {
K = copyOfK % count;
}
}
System.out.print(ele);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr with N distinct integers from 1 to N. If you are currently at index i then in a single jump you move to the index Arr[i]. You start at standing at index 1. Find the index you will be after K jumps.First line of input contains two integers N and K.
Second line of input contains N integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= K <= 1000000000000
1 <= Arr[i] <= NPrint the index you will be on after K jumps.Sample Input 1
5 3
3 4 2 5 1
Sample Output 1
4
Explanation:
You start at index 1
After first jump you reach index 3
After second jump you reach index 2
After third jump you reach index 4, I have written this Solution Code: n,k = map(int,input().split())
arr = list(map(int,input().split()))
visitedElements = {}
i = 0
curr = 0
for i in range(k):
currentIndex = arr[curr]
visitedElements[currentIndex] = visitedElements.get(currentIndex,0)+1
if visitedElements[currentIndex]>1:
break
curr = currentIndex -1
print(list(visitedElements.keys())[(k-1)%len(list(visitedElements.keys()))])
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr with N distinct integers from 1 to N. If you are currently at index i then in a single jump you move to the index Arr[i]. You start at standing at index 1. Find the index you will be after K jumps.First line of input contains two integers N and K.
Second line of input contains N integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= K <= 1000000000000
1 <= Arr[i] <= NPrint the index you will be on after K jumps.Sample Input 1
5 3
3 4 2 5 1
Sample Output 1
4
Explanation:
You start at index 1
After first jump you reach index 3
After second jump you reach index 2
After third jump you reach index 4, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n+1];
int k;
cin>>k;
for(int i=1;i<=n;++i)
cin>>a[i];
int vis[n+1]={};
int x=1;
int c=0;
while(vis[x]==0){
vis[x]=1;
++c;
x=a[x];
}
k=k%c;
x=1;
while(k){
--k;
x=a[x];
}
cout<<x;
#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: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: function easySorting(arr)
{
for(let i = 1; i < 5; i++)
{
let str = arr[i];
let j = i-1;
while(j >= 0 && (arr[j].toString().localeCompare(str)) > 0 )
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = str;
}
return arr;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
map<string,int> m;
string s;
for(int i=0;i<5;i++){
cin>>s;
m[s]++;
}
for(auto it=m.begin();it!=m.end();it++){
while(it->second>0){
cout<<it->first<<" ";
it->second--;}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: inp = input("").split(" ")
print(" ".join(sorted(inp))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static void printArray(String str[])
{
for (String string : str)
System.out.print(string + " ");
}
public static void main (String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
int len = 5;
String[] str = new String[len];
str = br.readLine().split(" ");
Arrays.sort(str, String.CASE_INSENSITIVE_ORDER);
printArray(str);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>nums</b> of N integers where each element is in between 1 to N. Your task is to print all the integers from 1 to N which are not present in the given array.First line contains n the length of input
Second line of input contains the array of integers in range from (1 to n)
<b> Constraints </b>
1 <= n <= 100000
1 <= arr[i] <= nPrint all the integers in range [1, n] that dose not appear in array.Sample Input :
5
1 2 3 4 4
Sample Output :
5
Sample Input:
7
4 1 3 2 5 5 4
Sample Output:
6 7
Explaination:
In the first test, only 5 is the integer from 1 to n, which is missing from the array.
In the second test, both 6 and 7 are missing., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
List<Integer> ans=missing(arr);
for(int i=0;i<ans.size();i++){
System.out.print(ans.get(i)+" ");
}
System.out.println();
}
static List<Integer> missing(int[] arr){
int i=0;
while (i< arr.length){
int correct=arr[i]-1;
if (arr[i]!=arr[correct]){
swap(arr,i,correct);
}else {
i++;
}
}
List<Integer> ans=new ArrayList<>();
for (int j = 0; j < arr.length; j++) {
if (arr[j] != j+1) {
ans.add(j + 1);
}
}
return ans;
}
static void swap(int[] arr,int first,int second){
int temp=arr[first];
arr[first]=arr[second];
arr[second]=temp;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>nums</b> of N integers where each element is in between 1 to N. Your task is to print all the integers from 1 to N which are not present in the given array.First line contains n the length of input
Second line of input contains the array of integers in range from (1 to n)
<b> Constraints </b>
1 <= n <= 100000
1 <= arr[i] <= nPrint all the integers in range [1, n] that dose not appear in array.Sample Input :
5
1 2 3 4 4
Sample Output :
5
Sample Input:
7
4 1 3 2 5 5 4
Sample Output:
6 7
Explaination:
In the first test, only 5 is the integer from 1 to n, which is missing from the array.
In the second test, both 6 and 7 are missing., I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-08 12:34:09
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
vector<int> findDisappearedNumbers(vector<int>& nums) {
int i = 0, size = nums.size();
while (i < size) {
if (nums[i] != i + 1 && nums[nums[i] - 1] != nums[i])
swap(nums[i], nums[nums[i] - 1]);
else
i++;
}
vector<int> ans;
for (i = 0; i < size; i++)
if (nums[i] != i + 1) ans.push_back(i + 1);
return ans;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> x = findDisappearedNumbers(a);
for (auto& it : x) {
cout << it << " ";
}
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 number N, find the value of the below Equation for the given number.
Equation: -
N
∑ {(X - 1)<sup>3</sup> + 3(X + 1)<sup>2</sup> + 2}
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 <= 100Return the sum of equation.Sample Input:-
1
Sample Output:-
14
Sample Input:-
2
Sample Output:-
44, I have written this Solution Code: static int equationSum(int n)
{
int sum=n*(n+1);
sum=sum/2;
sum=sum*sum;
sum+=9*((n*(n+1))/2);
sum+=4*(n);
return sum;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, find the value of the below Equation for the given number.
Equation: -
N
∑ {(X - 1)<sup>3</sup> + 3(X + 1)<sup>2</sup> + 2}
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 <= 100Return the sum of equation.Sample Input:-
1
Sample Output:-
14
Sample Input:-
2
Sample Output:-
44, I have written this Solution Code: def equationSum(N) :
re=(N*(N+1))//2
re=re*re
re=re+9*((N*(N+1))//2)
re=re+4*N
return re
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.