Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Sara is standing in a line for her turn to see the doctor. N people are standing in front of Sara, and the doctor takes exactly X minutes for each person. Sara wants to know the time after which her number comes. Since Sara is weak in maths, your task is calculating the time for her turn.You don't have to worry about the input, you just have to complete the function <b>waitingTime()</b>
<b>Constraints:-</b>
1 <= N <= 1000
1 <= X <= 1000Return the total time Sara needs to wait before her turn in minutes.Sample Input 1:-
5 3
Sample Output 1:-
15
Sample Input 2:-
3 2
Sample Output 2:-
6, I have written this Solution Code: inp = input()
inp = inp.split()
N,X = int(inp[0]), int(inp[1])
print(N*X), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: static int Help(int N, int M){
if(N%M==0){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: function Help(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const ans = (n % m === 0) ? 1 : 0
return ans
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: def Help(N,M):
if N%M==0:
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code:
int Help(int N, int M){
return N%M==0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code:
int Help(int N, int M){
return N%M==0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, your task is to check whether the given integer is even or odd.
If the integer is even print 0 else if it is odd print 1.The input contains a single integer N.
Constraint:
1 ≤ N ≤10000If the integer is even print 0 else if it is odd print 1.Sample Input:-
15
Sample Output:-
1
Sample Input:-
16
Sample Output:-
0, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
int area = EvenOrOdd(side);
System.out.println(area);
}
static int EvenOrOdd(int N){
return N%2;
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, your task is to check whether the given integer is even or odd.
If the integer is even print 0 else if it is odd print 1.The input contains a single integer N.
Constraint:
1 ≤ N ≤10000If the integer is even print 0 else if it is odd print 1.Sample Input:-
15
Sample Output:-
1
Sample Input:-
16
Sample Output:-
0, I have written this Solution Code: inp = int(input())
if inp % 2 == 0 :
print(0)
else:
print(1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has 2 brothers which initially have X and Y candies with them. Sara has also N candies with her. Sara wants to distribute her candies to his brothers such that both the brother have an equal amount of candies at last. Given the values of X, Y, and N, your task is to tell Sara whether she can distribute in such a way or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>distributeCandies()</b> that takes integers X, Y and N as arguments.
Constraints:-
0 <= N <= 1000
0 <= X <= 1000
0 <= Y <= 1000Return 1 if it is possible else return 0.Sample Input:-
N = 5, X = 3, Y = 2
Sample Output:-
1
Explanation:-
Both brothers can have 5 candies at the end. i. e Sara will give 2 candies to the first brother and 3 candies to the second.
Sample Input:-
N = 3, X = 2, Y = 2
Sample output:-
0, I have written this Solution Code: static int distributeCandies(int N, int X, int Y){
int x = N+X+Y;
if(x%2==1){return 0;}
x=x/2;
if(x<X || x<Y){
return 0;
}
return 1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has 2 brothers which initially have X and Y candies with them. Sara has also N candies with her. Sara wants to distribute her candies to his brothers such that both the brother have an equal amount of candies at last. Given the values of X, Y, and N, your task is to tell Sara whether she can distribute in such a way or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>distributeCandies()</b> that takes integers X, Y and N as arguments.
Constraints:-
0 <= N <= 1000
0 <= X <= 1000
0 <= Y <= 1000Return 1 if it is possible else return 0.Sample Input:-
N = 5, X = 3, Y = 2
Sample Output:-
1
Explanation:-
Both brothers can have 5 candies at the end. i. e Sara will give 2 candies to the first brother and 3 candies to the second.
Sample Input:-
N = 3, X = 2, Y = 2
Sample output:-
0, I have written this Solution Code: def distributeCandies(N,X,Y):
x=N+X+Y
if(x%2==1):
return 0
x=x/2
if(x< X or x < Y):
return 0
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has 2 brothers which initially have X and Y candies with them. Sara has also N candies with her. Sara wants to distribute her candies to his brothers such that both the brother have an equal amount of candies at last. Given the values of X, Y, and N, your task is to tell Sara whether she can distribute in such a way or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>distributeCandies()</b> that takes integers X, Y and N as arguments.
Constraints:-
0 <= N <= 1000
0 <= X <= 1000
0 <= Y <= 1000Return 1 if it is possible else return 0.Sample Input:-
N = 5, X = 3, Y = 2
Sample Output:-
1
Explanation:-
Both brothers can have 5 candies at the end. i. e Sara will give 2 candies to the first brother and 3 candies to the second.
Sample Input:-
N = 3, X = 2, Y = 2
Sample output:-
0, I have written this Solution Code: int distributeCandies(int N, int X, int Y){
int x = N+X+Y;
if(x%2==1){return 0;}
x=x/2;
if(x<X || x<Y){
return 0;
}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has 2 brothers which initially have X and Y candies with them. Sara has also N candies with her. Sara wants to distribute her candies to his brothers such that both the brother have an equal amount of candies at last. Given the values of X, Y, and N, your task is to tell Sara whether she can distribute in such a way or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>distributeCandies()</b> that takes integers X, Y and N as arguments.
Constraints:-
0 <= N <= 1000
0 <= X <= 1000
0 <= Y <= 1000Return 1 if it is possible else return 0.Sample Input:-
N = 5, X = 3, Y = 2
Sample Output:-
1
Explanation:-
Both brothers can have 5 candies at the end. i. e Sara will give 2 candies to the first brother and 3 candies to the second.
Sample Input:-
N = 3, X = 2, Y = 2
Sample output:-
0, I have written this Solution Code: int distributeCandies(int N, int X, int Y){
int x = N+X+Y;
if(x%2==1){return 0;}
x=x/2;
if(x<X || x<Y){
return 0;
}
return 1;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: static int Help(int N, int M){
if(N%M==0){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: function Help(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const ans = (n % m === 0) ? 1 : 0
return ans
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: def Help(N,M):
if N%M==0:
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code:
int Help(int N, int M){
return N%M==0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code:
int Help(int N, int M){
return N%M==0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to print the sum and mean (floor value) of given numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function:- <b>SumAndMean()</b> that takes the Array and the integer N as parameters.
<b>Constraints:-</b>
1 ≤ N ≤ 100
1 ≤ A[i] ≤ 100Print the Sum and the Mean of the array separated by a space.Sample Input:
5
1 2 19 28 5
Sample Output:
55 11
Sample Input:-
4
2 8 3 4
Sample Output:-
17 4
<b>Explanation:</b>
Test case 1: For an array of 5 elements, the sum is (1 + 2 + 19 + 28 + 5) = 55, mean is (1 + 2 + 19 + 28 + 5)/5 = 11. The mean is 11.
Test case 2: For an array of 4 elements, the sum is (2 + 8 + 3 + 4) = 17, and the mean is floor((2 + 8 + 3 + 4)/4) = 4. Mean is floor(17/4) = 4, I have written this Solution Code: // arr is the array of numbers, n is the number of elements
function sumAndMean(arr, n) {
// write code here
// do not console.log
// return the an array of two element where first element is sum and other is mean
const sum = arr.reduce((a, b) => a + b, 0)
return [sum, Math.floor(sum / n)]
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to print the sum and mean (floor value) of given numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function:- <b>SumAndMean()</b> that takes the Array and the integer N as parameters.
<b>Constraints:-</b>
1 ≤ N ≤ 100
1 ≤ A[i] ≤ 100Print the Sum and the Mean of the array separated by a space.Sample Input:
5
1 2 19 28 5
Sample Output:
55 11
Sample Input:-
4
2 8 3 4
Sample Output:-
17 4
<b>Explanation:</b>
Test case 1: For an array of 5 elements, the sum is (1 + 2 + 19 + 28 + 5) = 55, mean is (1 + 2 + 19 + 28 + 5)/5 = 11. The mean is 11.
Test case 2: For an array of 4 elements, the sum is (2 + 8 + 3 + 4) = 17, and the mean is floor((2 + 8 + 3 + 4)/4) = 4. Mean is floor(17/4) = 4, I have written this Solution Code: class Solution {
public static void SumAndMean(int arr[],int N){
int sum=0;
for(int i=0;i<N;i++){
sum+=arr[i];
}
System.out.print(sum + " " + sum/N);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to print the sum and mean (floor value) of given numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function:- <b>SumAndMean()</b> that takes the Array and the integer N as parameters.
<b>Constraints:-</b>
1 ≤ N ≤ 100
1 ≤ A[i] ≤ 100Print the Sum and the Mean of the array separated by a space.Sample Input:
5
1 2 19 28 5
Sample Output:
55 11
Sample Input:-
4
2 8 3 4
Sample Output:-
17 4
<b>Explanation:</b>
Test case 1: For an array of 5 elements, the sum is (1 + 2 + 19 + 28 + 5) = 55, mean is (1 + 2 + 19 + 28 + 5)/5 = 11. The mean is 11.
Test case 2: For an array of 4 elements, the sum is (2 + 8 + 3 + 4) = 17, and the mean is floor((2 + 8 + 3 + 4)/4) = 4. Mean is floor(17/4) = 4, I have written this Solution Code: N = int(input())
inputString = input()
integerArr = inputString.split()
computedintegerArr = []
totalcomputedinteger = 0
for integer in integerArr:
computedintegerArr.append(int(integer))
for computedvalue in computedintegerArr:
totalcomputedinteger += computedvalue
print(totalcomputedinteger, totalcomputedinteger//N)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
void print(int dn, int from, int to){
cout << dn << ":" << (char)('A'+from-1) << "->" << (char)('A'+to-1) << endl;
}
void rec(int n, int src, int des, int aux){
if(n == 0)
return;
rec(n-1, src, aux, des);
print(n, src, des);
rec(n-1, aux, des, src);
}
signed main() {
IOS;
int n; cin >> n;
rec(n, 1, 3, 2);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: # Recursive Python function to solve the tower of hanoi
def TowerOfHanoi(n , source, destination, auxiliary):
if n==1:
#print ("1:",source,"->",destination)
print("1:%s->%s"%(source,destination))
return
TowerOfHanoi(n-1, source, auxiliary, destination)
#print (n,"%d:",source,"->",destination)
print("%d:%s->%s"%(n,source,destination))
TowerOfHanoi(n-1, auxiliary, destination, source)
# Driver code
n = int(input())
TowerOfHanoi(n,'A','C','B'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: // n is the number of disks
function towerOfHanoiSequence(n) {
// write code here
// console.log the seqence steps
function towerOfHanoi(n, from_rod, to_rod, aux_rod) {
if (n == 0) {
return;
}
towerOfHanoi(n - 1, from_rod, aux_rod, to_rod);
console.log(`${n}:${from_rod}->${to_rod}`)
towerOfHanoi(n - 1, aux_rod, to_rod, from_rod);
}
towerOfHanoi(n,'A','C','B')
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
{
if (n == 1)
{
System.out.println("1:" + from_rod + "->" + to_rod);
return;
}
towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
System.out.println(n + ":" + from_rod + "->" + to_rod);
towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
towerOfHanoi(n, 'A', 'C', 'B');
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: // str is input
function isPalindrome(str) {
// write code here
// do not console.log
// return the 1 or 0
const ans = str.split('').reverse().join('') === str ? 1 : 0
return ans
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
int A[2000][2000];
int vis[200][200];
int dist[200][200];
int xa[8]={1,1,-1,-1,2,2,-2,-2};
int ya[8]={2,-2,2,-2,1,-1,1,-1};
int n,m;
int val,hh;
int check(int x,int y)
{
if (x>=0 && y>=0 && x<n && y<m )return 1;
else return 0;
}
#define qw1 freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define qw2 freopen("input2.txt", "r", stdin); freopen("output2.txt", "w", stdout);
#define qw3 freopen("input3.txt", "r", stdin); freopen("output3.txt", "w", stdout);
#define qw4 freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout);
#define qw5 freopen("input5.txt", "r", stdin); freopen("output5.txt", "w", stdout);
#define qw6 freopen("input6.txt", "r", stdin); freopen("output6.txt", "w", stdout);
#define qw freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
signed main()
{
string s;
cin>>s;
int n=s.size();
int ch=1;
for(int j=0;j<=n-1;j++)
{
if(s[j]!=s[n-1-j]) ch=0;
}
cout<<ch;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: num=input()
rev=num[::-1]
if rev==num:
print("1")
else:
print("0"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int len=str.length();
boolean temp=true;
int i=0,j=len-1;
for(i=0;i<len/2;i++){
if(str.charAt(i)!=str.charAt(j--)) temp=false;
}
if(temp) System.out.println(1);
else System.out.println(0);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: // str is input
function isPalindrome(str) {
// write code here
// do not console.log
// return the 1 or 0
const ans = str.split('').reverse().join('') === str ? 1 : 0
return ans
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
int A[2000][2000];
int vis[200][200];
int dist[200][200];
int xa[8]={1,1,-1,-1,2,2,-2,-2};
int ya[8]={2,-2,2,-2,1,-1,1,-1};
int n,m;
int val,hh;
int check(int x,int y)
{
if (x>=0 && y>=0 && x<n && y<m )return 1;
else return 0;
}
#define qw1 freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define qw2 freopen("input2.txt", "r", stdin); freopen("output2.txt", "w", stdout);
#define qw3 freopen("input3.txt", "r", stdin); freopen("output3.txt", "w", stdout);
#define qw4 freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout);
#define qw5 freopen("input5.txt", "r", stdin); freopen("output5.txt", "w", stdout);
#define qw6 freopen("input6.txt", "r", stdin); freopen("output6.txt", "w", stdout);
#define qw freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
signed main()
{
string s;
cin>>s;
int n=s.size();
int ch=1;
for(int j=0;j<=n-1;j++)
{
if(s[j]!=s[n-1-j]) ch=0;
}
cout<<ch;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: num=input()
rev=num[::-1]
if rev==num:
print("1")
else:
print("0"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int len=str.length();
boolean temp=true;
int i=0,j=len-1;
for(i=0;i<len/2;i++){
if(str.charAt(i)!=str.charAt(j--)) temp=false;
}
if(temp) System.out.println(1);
else System.out.println(0);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list consisting of N nodes and two integers M and K. Your task is to add element K at the Mth position from the start of the linked list<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>addElement()</b> that takes head node, M(position of element to be inserted) and K(the element to be inserted) as parameter.
Constraints:
1 <= M <=N <= 1000
1 <=K, Node.data<= 1000Return the head of the modified linked listSample Input:-
5 3 2
1 3 2 4 5
Sample Output:-
1 3 2 2 4 5
Explanation:-
here M is 3 and K is 2
so we insert 2 at the 3rd position, resulting list will be 1 3 2 2 4 5
Sample Input 2:-
5 2 6
1 2 3 4 5
Sample Output 2:-
1 6 2 3 4 5
, I have written this Solution Code: public static Node addElement(Node head,int k,int pos) {
int cnt=1;
if(pos==1){Node temp=new Node(k);
temp.next=head;return temp;}
Node temp=head;
while(cnt!=pos-1){
temp=temp.next;
cnt++;
}
Node x= new Node(k);
x.next=temp.next;
temp.next=x;
return head;}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: int Operations(int n){
int ans=0;
int cnt=0;
int p=n;
int res=n;
while(res/10>0){
cnt=0;
p=res;
n=res;
while(n/10>0){
cnt++;
n=n/10;}
int x=1;
while(cnt--){
x*=10;
}
int t=p/x;
int y=p%x;
ans+=(y/t+1);
res=res-t*(y/t+1);
}
ans++;
return ans;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: public static int Operations(int n){
int ans=0;
int cnt=0;
int p=n;
int res=n;
while(res/10>0){
cnt=0;
p=res;
n=res;
while(n/10>0){
cnt++;
n=n/10;}
int x=1;
while(cnt-->0){
x*=10;
}
int t=p/x;
int y=p%x;
ans+=(y/t+1);
res=res-t*(y/t+1);
}
ans++;
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: def Operations(N) :
ans=0
cnt=0
p=N
res=N
while(res//10>0):
cnt=0
p=res
n=res
while(n//10>0):
cnt=cnt+1
n=n/10
x=pow(10,cnt)
t=p//x
y=p%x
ans=ans+(y//t+1)
res=res-t*(y//t+1)
ans=ans+1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: int Operations(int n){
int ans=0;
int cnt=0;
int p=n;
int res=n;
while(res/10>0){
cnt=0;
p=res;
n=res;
while(n/10>0){
cnt++;
n=n/10;}
int x=1;
while(cnt--){
x*=10;
}
int t=p/x;
int y=p%x;
ans+=(y/t+1);
res=res-t*(y/t+1);
}
ans++;
return ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is standing in a line for her turn to see the doctor. N people are standing in front of Sara, and the doctor takes exactly X minutes for each person. Sara wants to know the time after which her number comes. Since Sara is weak in maths, your task is calculating the time for her turn.You don't have to worry about the input, you just have to complete the function <b>waitingTime()</b>
<b>Constraints:-</b>
1 <= N <= 1000
1 <= X <= 1000Return the total time Sara needs to wait before her turn in minutes.Sample Input 1:-
5 3
Sample Output 1:-
15
Sample Input 2:-
3 2
Sample Output 2:-
6, I have written this Solution Code: static void waitingTime(int N, int X){
System.out.println(N*X);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is standing in a line for her turn to see the doctor. N people are standing in front of Sara, and the doctor takes exactly X minutes for each person. Sara wants to know the time after which her number comes. Since Sara is weak in maths, your task is calculating the time for her turn.You don't have to worry about the input, you just have to complete the function <b>waitingTime()</b>
<b>Constraints:-</b>
1 <= N <= 1000
1 <= X <= 1000Return the total time Sara needs to wait before her turn in minutes.Sample Input 1:-
5 3
Sample Output 1:-
15
Sample Input 2:-
3 2
Sample Output 2:-
6, I have written this Solution Code: void waitingTime(int N, int X){
cout << N*X;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is standing in a line for her turn to see the doctor. N people are standing in front of Sara, and the doctor takes exactly X minutes for each person. Sara wants to know the time after which her number comes. Since Sara is weak in maths, your task is calculating the time for her turn.You don't have to worry about the input, you just have to complete the function <b>waitingTime()</b>
<b>Constraints:-</b>
1 <= N <= 1000
1 <= X <= 1000Return the total time Sara needs to wait before her turn in minutes.Sample Input 1:-
5 3
Sample Output 1:-
15
Sample Input 2:-
3 2
Sample Output 2:-
6, I have written this Solution Code: inp = input()
inp = inp.split()
N,X = int(inp[0]), int(inp[1])
print(N*X), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the Nth number in the fibonacci series. Consider 0 and 1 to be the seed values.
In the fibonacci series, each number (Fibonacci number) is the sum of the two preceding numbers. The series with 0 and 1 as seed values will go like -
0, 1, 1, 2, 3, 5 and so on..<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Fibonacci()</b> that takes the integer N as a parameter.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 30Return the Nth Fibonacci number.Sample Input
2
3
5
Sample Output
2
5
Explaination:
Test case 1-> N = 2
Seed values are 0 and 1
So, F<sub>1</sub> = 0 + 1 = 1
F<sub>2</sub> = 1 + F<sub>1</sub> = 1 + 1 = 2, I have written this Solution Code: static long Fibonacci(long n)
{
if (n == 0)
{ return 0;}
else if(n==1){
return 1;
}
return Fibonacci(n-1) + Fibonacci(n-2);
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the Nth number in the fibonacci series. Consider 0 and 1 to be the seed values.
In the fibonacci series, each number (Fibonacci number) is the sum of the two preceding numbers. The series with 0 and 1 as seed values will go like -
0, 1, 1, 2, 3, 5 and so on..<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Fibonacci()</b> that takes the integer N as a parameter.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 30Return the Nth Fibonacci number.Sample Input
2
3
5
Sample Output
2
5
Explaination:
Test case 1-> N = 2
Seed values are 0 and 1
So, F<sub>1</sub> = 0 + 1 = 1
F<sub>2</sub> = 1 + F<sub>1</sub> = 1 + 1 = 2, I have written this Solution Code: // n is the input number
function fibonacci(n) {
// write code here
// do not console.log
// return the answer as a number
if (n == 1 || n == 0) return n;
return fibonacci(n-2) + fibonacci(n-1)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Calculators are widely used devices nowadays. It makes calculations easier and faster. A simple calculator consists of the following operators:
1. '+': adding two numbers
2. '- ': subtraction
3. '*': multiplying numbers
4. '/': division
You will be given operator '+' or '- ' or '*' or '/' followed by two operands(integers), you need to perform a mathematical operation based on a given operator.
If '/' operator is used, print the integer value after divisionUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>calculator()</b> which contains operator(any one of given in the constraints), and two operands i.e. two integers.
<b>Constraints:</b>
operators - {+, - , *, /}
1 <= integers <= 10^4You need to return the result. If '/' operator is used, return the integer value after division.Sample Input
*
10 15
Sample Output
150
Explanation:
10*15 = 150
Sample Input:
/
15 4
Sample output:
3
Explanation:
15/4 = 3.75; floor(3.75) = 3, I have written this Solution Code: function calculate(op,num1,num2) {
// write code here
// return the output using return keyword
// do not use console.log here
switch (op) {
case '+':return num1 + num2
case '-' : return num1 - num2
case '*' : return num1 * num2
case '/' : return Math.floor(num1/num2)
default:
break;
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Calculators are widely used devices nowadays. It makes calculations easier and faster. A simple calculator consists of the following operators:
1. '+': adding two numbers
2. '- ': subtraction
3. '*': multiplying numbers
4. '/': division
You will be given operator '+' or '- ' or '*' or '/' followed by two operands(integers), you need to perform a mathematical operation based on a given operator.
If '/' operator is used, print the integer value after divisionUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>calculator()</b> which contains operator(any one of given in the constraints), and two operands i.e. two integers.
<b>Constraints:</b>
operators - {+, - , *, /}
1 <= integers <= 10^4You need to return the result. If '/' operator is used, return the integer value after division.Sample Input
*
10 15
Sample Output
150
Explanation:
10*15 = 150
Sample Input:
/
15 4
Sample output:
3
Explanation:
15/4 = 3.75; floor(3.75) = 3, I have written this Solution Code: def calculator(operator,a,b):
if(operator == '/'):
print(a//b)
if(operator == '*'):
print(a*b)
if(operator == '+'):
print(a+b)
if(operator == '-'):
print(a-b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Calculators are widely used devices nowadays. It makes calculations easier and faster. A simple calculator consists of the following operators:
1. '+': adding two numbers
2. '- ': subtraction
3. '*': multiplying numbers
4. '/': division
You will be given operator '+' or '- ' or '*' or '/' followed by two operands(integers), you need to perform a mathematical operation based on a given operator.
If '/' operator is used, print the integer value after divisionUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>calculator()</b> which contains operator(any one of given in the constraints), and two operands i.e. two integers.
<b>Constraints:</b>
operators - {+, - , *, /}
1 <= integers <= 10^4You need to return the result. If '/' operator is used, return the integer value after division.Sample Input
*
10 15
Sample Output
150
Explanation:
10*15 = 150
Sample Input:
/
15 4
Sample output:
3
Explanation:
15/4 = 3.75; floor(3.75) = 3, I have written this Solution Code: static int calculator(char ch, int a, int b)
{
if(ch == '+')
return a+b;
else if(ch == '-')
return a-b;
else if(ch == '*')
return a*b;
else return a/b;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has 2 brothers which initially have X and Y candies with them. Sara has also N candies with her. Sara wants to distribute her candies to his brothers such that both the brother have an equal amount of candies at last. Given the values of X, Y, and N, your task is to tell Sara whether she can distribute in such a way or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>distributeCandies()</b> that takes integers X, Y and N as arguments.
Constraints:-
0 <= N <= 1000
0 <= X <= 1000
0 <= Y <= 1000Return 1 if it is possible else return 0.Sample Input:-
N = 5, X = 3, Y = 2
Sample Output:-
1
Explanation:-
Both brothers can have 5 candies at the end. i. e Sara will give 2 candies to the first brother and 3 candies to the second.
Sample Input:-
N = 3, X = 2, Y = 2
Sample output:-
0, I have written this Solution Code: static int distributeCandies(int N, int X, int Y){
int x = N+X+Y;
if(x%2==1){return 0;}
x=x/2;
if(x<X || x<Y){
return 0;
}
return 1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has 2 brothers which initially have X and Y candies with them. Sara has also N candies with her. Sara wants to distribute her candies to his brothers such that both the brother have an equal amount of candies at last. Given the values of X, Y, and N, your task is to tell Sara whether she can distribute in such a way or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>distributeCandies()</b> that takes integers X, Y and N as arguments.
Constraints:-
0 <= N <= 1000
0 <= X <= 1000
0 <= Y <= 1000Return 1 if it is possible else return 0.Sample Input:-
N = 5, X = 3, Y = 2
Sample Output:-
1
Explanation:-
Both brothers can have 5 candies at the end. i. e Sara will give 2 candies to the first brother and 3 candies to the second.
Sample Input:-
N = 3, X = 2, Y = 2
Sample output:-
0, I have written this Solution Code: def distributeCandies(N,X,Y):
x=N+X+Y
if(x%2==1):
return 0
x=x/2
if(x< X or x < Y):
return 0
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has 2 brothers which initially have X and Y candies with them. Sara has also N candies with her. Sara wants to distribute her candies to his brothers such that both the brother have an equal amount of candies at last. Given the values of X, Y, and N, your task is to tell Sara whether she can distribute in such a way or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>distributeCandies()</b> that takes integers X, Y and N as arguments.
Constraints:-
0 <= N <= 1000
0 <= X <= 1000
0 <= Y <= 1000Return 1 if it is possible else return 0.Sample Input:-
N = 5, X = 3, Y = 2
Sample Output:-
1
Explanation:-
Both brothers can have 5 candies at the end. i. e Sara will give 2 candies to the first brother and 3 candies to the second.
Sample Input:-
N = 3, X = 2, Y = 2
Sample output:-
0, I have written this Solution Code: int distributeCandies(int N, int X, int Y){
int x = N+X+Y;
if(x%2==1){return 0;}
x=x/2;
if(x<X || x<Y){
return 0;
}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has 2 brothers which initially have X and Y candies with them. Sara has also N candies with her. Sara wants to distribute her candies to his brothers such that both the brother have an equal amount of candies at last. Given the values of X, Y, and N, your task is to tell Sara whether she can distribute in such a way or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>distributeCandies()</b> that takes integers X, Y and N as arguments.
Constraints:-
0 <= N <= 1000
0 <= X <= 1000
0 <= Y <= 1000Return 1 if it is possible else return 0.Sample Input:-
N = 5, X = 3, Y = 2
Sample Output:-
1
Explanation:-
Both brothers can have 5 candies at the end. i. e Sara will give 2 candies to the first brother and 3 candies to the second.
Sample Input:-
N = 3, X = 2, Y = 2
Sample output:-
0, I have written this Solution Code: int distributeCandies(int N, int X, int Y){
int x = N+X+Y;
if(x%2==1){return 0;}
x=x/2;
if(x<X || x<Y){
return 0;
}
return 1;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A magic number is a natural number that contains both the digits 7 and 9 in it. For eg:- 79, 879, 53729 etc.
Given a number N, your task is to find the closest Magic number from the given number N.
Note:- If more than one answer exists return the minimum one<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>MagicNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return a magic number closest to the given number N.Sample Input:-
8
Sample Output:-
79
Sample Input:-
900
Sample Output:-
897, I have written this Solution Code: def check(N):
if(N<0):
return 1
a=0
b=0
while(N):
if(N%10==7):
a=1
if(N%10==9):
b=1
N=N//10
if( a==1 and b==1):
return 0
return 1
def MagicNumber(N):
i=0
while(check(N-i)==1 and check(N+i)==1):
i=i+1
if(check(N-i)==0):
return N-i
return N+i
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A magic number is a natural number that contains both the digits 7 and 9 in it. For eg:- 79, 879, 53729 etc.
Given a number N, your task is to find the closest Magic number from the given number N.
Note:- If more than one answer exists return the minimum one<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>MagicNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return a magic number closest to the given number N.Sample Input:-
8
Sample Output:-
79
Sample Input:-
900
Sample Output:-
897, I have written this Solution Code: int check(int n){
int s=0;
int p=0;
while(n){
if(n%10==7){s=1;}
if(n%10==9){p=1;}
n/=10;
}
if(s && p){return 0;}
return 1;
}
int MagicNumber(int n){
int i=0;
while(check(n-i) && check(n+i)){
i++;
}
if(check(n-i)==0){return n-i;}
else{
return n+i;}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A magic number is a natural number that contains both the digits 7 and 9 in it. For eg:- 79, 879, 53729 etc.
Given a number N, your task is to find the closest Magic number from the given number N.
Note:- If more than one answer exists return the minimum one<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>MagicNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return a magic number closest to the given number N.Sample Input:-
8
Sample Output:-
79
Sample Input:-
900
Sample Output:-
897, I have written this Solution Code: int check(int n){
int s=0;
int p=0;
while(n){
if(n%10==7){s=1;}
if(n%10==9){p=1;}
n/=10;
}
if(s && p){return 0;}
return 1;
}
int MagicNumber(int n){
int i=0;
while(check(n-i) && check(n+i)){
i++;
}
if(check(n-i)==0){return n-i;}
else{
return n+i;}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A magic number is a natural number that contains both the digits 7 and 9 in it. For eg:- 79, 879, 53729 etc.
Given a number N, your task is to find the closest Magic number from the given number N.
Note:- If more than one answer exists return the minimum one<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>MagicNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return a magic number closest to the given number N.Sample Input:-
8
Sample Output:-
79
Sample Input:-
900
Sample Output:-
897, I have written this Solution Code: static boolean check(int n){
boolean s=false;
boolean p=false;
while(n>0){
if(n%10==7){s=true;}
if(n%10==9){p=true;}
n/=10;
}
if(s && p){return false;}
return true;
}
static int MagicNumber(int n){
int i=0;
while(check(n-i)==true && check(n+i)==true){
i++;
}
if(check(n-i)==false){return n-i;}
else{
return n+i;}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N trees in Terry's front yard. He is supposed to measures the height of each tree and find the average height of trees in his yard. What is the average height of a tree in Terry's front yard?
Note:- Print your answer as floor value (average height)The first line contains N: numbers of tree.
Then follows N lines represents the height of each tree.
Constraint:-
1 <= n <= 100000
1 <= a[i] <= 100000Print the average height of all the trees in the yardInput
5
6
8
34
9
3
Output
12
Explanation:-
Sum of heights =60
Average of heights =60/5
Sample Input:
3
1
2
3
, I have written this Solution Code: function averageMe(sizeOfArray, array) {
// write code here
// do no console.log the answer
// return the output using return keyword
const sum = array.reduce((a,b)=> a+b,0)
return Math.floor(sum/sizeOfArray)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N trees in Terry's front yard. He is supposed to measures the height of each tree and find the average height of trees in his yard. What is the average height of a tree in Terry's front yard?
Note:- Print your answer as floor value (average height)The first line contains N: numbers of tree.
Then follows N lines represents the height of each tree.
Constraint:-
1 <= n <= 100000
1 <= a[i] <= 100000Print the average height of all the trees in the yardInput
5
6
8
34
9
3
Output
12
Explanation:-
Sum of heights =60
Average of heights =60/5
Sample Input:
3
1
2
3
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
long long n,k;
cin>>n;
int a[n];
long long sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
sum+=a[i];
}
cout<<sum/n;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N trees in Terry's front yard. He is supposed to measures the height of each tree and find the average height of trees in his yard. What is the average height of a tree in Terry's front yard?
Note:- Print your answer as floor value (average height)The first line contains N: numbers of tree.
Then follows N lines represents the height of each tree.
Constraint:-
1 <= n <= 100000
1 <= a[i] <= 100000Print the average height of all the trees in the yardInput
5
6
8
34
9
3
Output
12
Explanation:-
Sum of heights =60
Average of heights =60/5
Sample Input:
3
1
2
3
, 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();
long A[] = new long[n];
for(int i=0;i<n;i++){
A[i]=sc.nextLong();
}
long sum=0;
for(int i=0;i<n;i++){
sum+=A[i];
}
long average = sum/n;
System.out.print(average);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N trees in Terry's front yard. He is supposed to measures the height of each tree and find the average height of trees in his yard. What is the average height of a tree in Terry's front yard?
Note:- Print your answer as floor value (average height)The first line contains N: numbers of tree.
Then follows N lines represents the height of each tree.
Constraint:-
1 <= n <= 100000
1 <= a[i] <= 100000Print the average height of all the trees in the yardInput
5
6
8
34
9
3
Output
12
Explanation:-
Sum of heights =60
Average of heights =60/5
Sample Input:
3
1
2
3
, I have written this Solution Code: n = int(input())
total_sum = 0
for i in range (n):
num =int(input())
total_sum +=(num)
avg = total_sum / n
print(int(avg)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find all possible pairs of A, and B such that A + B = N and A and B both are natural numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Allpair()</b> that takes integer N as a parameter.
Constraints:-
1 ≤ N ≤ 10<sup>8</sup>Return the number of possible pairs of A and B.Sample Input:-
5
Sample Output:-
4
Explanation:-
(1, 4), (2, 3), (3, 2), (4, 1) are the only possible pairs.
Sample Input:-
2
Sample Output:-
1, I have written this Solution Code: int AllPair(int N){
return N-1;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find all possible pairs of A, and B such that A + B = N and A and B both are natural numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Allpair()</b> that takes integer N as a parameter.
Constraints:-
1 ≤ N ≤ 10<sup>8</sup>Return the number of possible pairs of A and B.Sample Input:-
5
Sample Output:-
4
Explanation:-
(1, 4), (2, 3), (3, 2), (4, 1) are the only possible pairs.
Sample Input:-
2
Sample Output:-
1, I have written this Solution Code: static int AllPair(int N){
return N-1;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find all possible pairs of A, and B such that A + B = N and A and B both are natural numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Allpair()</b> that takes integer N as a parameter.
Constraints:-
1 ≤ N ≤ 10<sup>8</sup>Return the number of possible pairs of A and B.Sample Input:-
5
Sample Output:-
4
Explanation:-
(1, 4), (2, 3), (3, 2), (4, 1) are the only possible pairs.
Sample Input:-
2
Sample Output:-
1, I have written this Solution Code: def AllPair(N):
return N-1;, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find all possible pairs of A, and B such that A + B = N and A and B both are natural numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Allpair()</b> that takes integer N as a parameter.
Constraints:-
1 ≤ N ≤ 10<sup>8</sup>Return the number of possible pairs of A and B.Sample Input:-
5
Sample Output:-
4
Explanation:-
(1, 4), (2, 3), (3, 2), (4, 1) are the only possible pairs.
Sample Input:-
2
Sample Output:-
1, I have written this Solution Code: int AllPair(int N){
return N-1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
void print(int dn, int from, int to){
cout << dn << ":" << (char)('A'+from-1) << "->" << (char)('A'+to-1) << endl;
}
void rec(int n, int src, int des, int aux){
if(n == 0)
return;
rec(n-1, src, aux, des);
print(n, src, des);
rec(n-1, aux, des, src);
}
signed main() {
IOS;
int n; cin >> n;
rec(n, 1, 3, 2);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: # Recursive Python function to solve the tower of hanoi
def TowerOfHanoi(n , source, destination, auxiliary):
if n==1:
#print ("1:",source,"->",destination)
print("1:%s->%s"%(source,destination))
return
TowerOfHanoi(n-1, source, auxiliary, destination)
#print (n,"%d:",source,"->",destination)
print("%d:%s->%s"%(n,source,destination))
TowerOfHanoi(n-1, auxiliary, destination, source)
# Driver code
n = int(input())
TowerOfHanoi(n,'A','C','B'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: // n is the number of disks
function towerOfHanoiSequence(n) {
// write code here
// console.log the seqence steps
function towerOfHanoi(n, from_rod, to_rod, aux_rod) {
if (n == 0) {
return;
}
towerOfHanoi(n - 1, from_rod, aux_rod, to_rod);
console.log(`${n}:${from_rod}->${to_rod}`)
towerOfHanoi(n - 1, aux_rod, to_rod, from_rod);
}
towerOfHanoi(n,'A','C','B')
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: From wiki-
The Tower of Hanoi is a mathematical puzzle where we have 3 rods and N disks. The puzzle starts with all the disks in ascending order of size on the first row. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
3. No larger disk may be placed on top of a smaller disk.
-----x--x--x------
Let the rods have names A, B and C. Given N number of disks, numbered 1 to N from top to bottom, display all the moves required to move the disks from rod A to C in minimum number of steps.The only line of input contains an integer N denoting the number of disks
Constraints:
1 ≤ N ≤ 16Print sequence of moving disks, where each move is shown in the following format-
{DiskNumber}:{FromRod}->{ToRod}
Each move in the sequence is separated by a new lineInput
2
Output
1:A->B
2:A->C
1:B->C, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
{
if (n == 1)
{
System.out.println("1:" + from_rod + "->" + to_rod);
return;
}
towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
System.out.println(n + ":" + from_rod + "->" + to_rod);
towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
towerOfHanoi(n, 'A', 'C', 'B');
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers N and K. Construct a max diversity string of length N and period K. Among all possible strings, find the lexographically minimum string.
A max diverse string is a string with maximum number of different characters.
A string with period K is a string made by a string of length K repeated multiple times.
Note: You can use only lowercase characters from 'a' to 'z'.The first and the only line of input contains two integers N and K.
Constraints:
1 <= N <= 100000
1 <= K <= min(N,100)
N is divisible by K.Print the required string.Sample Input 1
4 2
Sample Output 1
abab
Sample Input 2
4 1
Sample Output 2
aaaa, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt(), k = s.nextInt();
int a = 0, b = k;
if(k > 26){
a = k - 26;
b = 26;
}
while(n != 0){
for(int i=0 ; i<a ; i++){
System.out.print((char)(97));
n--;
}
for(int i=0 ; i<b ; i++){
System.out.print((char)(i%26+97));
n--;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers N and K. Construct a max diversity string of length N and period K. Among all possible strings, find the lexographically minimum string.
A max diverse string is a string with maximum number of different characters.
A string with period K is a string made by a string of length K repeated multiple times.
Note: You can use only lowercase characters from 'a' to 'z'.The first and the only line of input contains two integers N and K.
Constraints:
1 <= N <= 100000
1 <= K <= min(N,100)
N is divisible by K.Print the required string.Sample Input 1
4 2
Sample Output 1
abab
Sample Input 2
4 1
Sample Output 2
aaaa, I have written this Solution Code: import copy,math
x,y = input().split()
x = int(x)
y = int(y)
s = ""
if y>26:
s = ('a'*(y-26))+("".join(chr(97+i) for i in range(26)))
else:
s = "".join(chr(97+i) for i in range(y))
print(s*(x//y)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers N and K. Construct a max diversity string of length N and period K. Among all possible strings, find the lexographically minimum string.
A max diverse string is a string with maximum number of different characters.
A string with period K is a string made by a string of length K repeated multiple times.
Note: You can use only lowercase characters from 'a' to 'z'.The first and the only line of input contains two integers N and K.
Constraints:
1 <= N <= 100000
1 <= K <= min(N,100)
N is divisible by K.Print the required string.Sample Input 1
4 2
Sample Output 1
abab
Sample Input 2
4 1
Sample Output 2
aaaa, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,k;
cin>>n>>k;
string s(n,'a');
for(int i=0;i<n/k;++i){
for(int j=0;j<k;++j){
if(j<k-26)
s[i*k+j]='a';
else
s[i*k+j]='a'+j-max(0ll,(k-26));
}
}
cout<<s;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is standing in a line for her turn to see the doctor. N people are standing in front of Sara, and the doctor takes exactly X minutes for each person. Sara wants to know the time after which her number comes. Since Sara is weak in maths, your task is calculating the time for her turn.You don't have to worry about the input, you just have to complete the function <b>waitingTime()</b>
<b>Constraints:-</b>
1 <= N <= 1000
1 <= X <= 1000Return the total time Sara needs to wait before her turn in minutes.Sample Input 1:-
5 3
Sample Output 1:-
15
Sample Input 2:-
3 2
Sample Output 2:-
6, I have written this Solution Code: static void waitingTime(int N, int X){
System.out.println(N*X);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is standing in a line for her turn to see the doctor. N people are standing in front of Sara, and the doctor takes exactly X minutes for each person. Sara wants to know the time after which her number comes. Since Sara is weak in maths, your task is calculating the time for her turn.You don't have to worry about the input, you just have to complete the function <b>waitingTime()</b>
<b>Constraints:-</b>
1 <= N <= 1000
1 <= X <= 1000Return the total time Sara needs to wait before her turn in minutes.Sample Input 1:-
5 3
Sample Output 1:-
15
Sample Input 2:-
3 2
Sample Output 2:-
6, I have written this Solution Code: void waitingTime(int N, int X){
cout << N*X;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is standing in a line for her turn to see the doctor. N people are standing in front of Sara, and the doctor takes exactly X minutes for each person. Sara wants to know the time after which her number comes. Since Sara is weak in maths, your task is calculating the time for her turn.You don't have to worry about the input, you just have to complete the function <b>waitingTime()</b>
<b>Constraints:-</b>
1 <= N <= 1000
1 <= X <= 1000Return the total time Sara needs to wait before her turn in minutes.Sample Input 1:-
5 3
Sample Output 1:-
15
Sample Input 2:-
3 2
Sample Output 2:-
6, I have written this Solution Code: inp = input()
inp = inp.split()
N,X = int(inp[0]), int(inp[1])
print(N*X), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: int Operations(int n){
int ans=0;
int cnt=0;
int p=n;
int res=n;
while(res/10>0){
cnt=0;
p=res;
n=res;
while(n/10>0){
cnt++;
n=n/10;}
int x=1;
while(cnt--){
x*=10;
}
int t=p/x;
int y=p%x;
ans+=(y/t+1);
res=res-t*(y/t+1);
}
ans++;
return ans;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: public static int Operations(int n){
int ans=0;
int cnt=0;
int p=n;
int res=n;
while(res/10>0){
cnt=0;
p=res;
n=res;
while(n/10>0){
cnt++;
n=n/10;}
int x=1;
while(cnt-->0){
x*=10;
}
int t=p/x;
int y=p%x;
ans+=(y/t+1);
res=res-t*(y/t+1);
}
ans++;
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: def Operations(N) :
ans=0
cnt=0
p=N
res=N
while(res//10>0):
cnt=0
p=res
n=res
while(n//10>0):
cnt=cnt+1
n=n/10
x=pow(10,cnt)
t=p//x
y=p%x
ans=ans+(y//t+1)
res=res-t*(y//t+1)
ans=ans+1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: int Operations(int n){
int ans=0;
int cnt=0;
int p=n;
int res=n;
while(res/10>0){
cnt=0;
p=res;
n=res;
while(n/10>0){
cnt++;
n=n/10;}
int x=1;
while(cnt--){
x*=10;
}
int t=p/x;
int y=p%x;
ans+=(y/t+1);
res=res-t*(y/t+1);
}
ans++;
return ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: static int Help(int N, int M){
if(N%M==0){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: function Help(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const ans = (n % m === 0) ? 1 : 0
return ans
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code: def Help(N,M):
if N%M==0:
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code:
int Help(int N, int M){
return N%M==0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sherlock is a great detective but he is weak in maths. On one day Sherlock wants to divide N apples into M people but he is not sure whether he can divide them equally or not. Your task is to help Sherlock to solve the problem.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Help()</b> that takes integers N and M as arguments.
Constraints:-
1 <= N M <= 1000Return 1 if it is possible to divide N apple among M people else return 0.Sample Input:-
6 2
Sample Output:-
1
Explanation:-
both people will get 3 apples each.
Sample Input:-
3 4
Sample Output:-
0, I have written this Solution Code:
int Help(int N, int M){
return N%M==0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a positive integer N. Print "Yes" if N is a multiple of 3, otherwise, print "No".The input consists of a single integer N.
<b> Constraints: </b>
1 ≤ N ≤ 1000If N is a multiple of 3, print "Yes". Otherwise, print "No" (without the quotation marks). Note that the <b>output is case-sensitive</b>.Sample Input 1:
6
Sample Output 1:
Yes
Sample Input 2:
10
Sample Output 2:
No
(6 is a multiple of 3 (3*2==6) while 10 is not a multiple of 3), I have written this Solution Code: #include <bits/stdc++.h>
#define int long long
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
if (n % 3) cout << "No";
else cout << "Yes";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alexa is a very kind girl. She has 'x' red gems and 'y' blue gems. She wants to distribute them among her two friends (Alice and Julia).
But she will only distribute them if she can give equal number of each colour of gems to Alice and Julia. Further, she must distribute all available gems in this way. So, can you help her make a decision?First line contains two space- separated integers 'x' and 'y' (0 <= x,y <= 100) i. e. number of red and blue gems.In the first line, output "YES" is she can distribute gems else "NO" (without double quotes).Sample Input:
2 3
Sample Output:
NO
Explanation:
Alexa has 3 blue gems, so she can not distribute blue gems., I have written this Solution Code: import java.io.*;import java.util.*;
class Main{
static InputReader fr = new InputReader(System.in);
public static void main(String[] args) throws IOException {
PrintWriter w = new PrintWriter(System.out);
int tt=1;
while(tt-->0) {
int x=fr.ni();
int y=fr.ni();
if(x%2==0 && y%2==0) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
w.close();
}
static void opil(List<Integer> al) {StringBuilder sb= new StringBuilder();for(int x:al)sb.append(x+" ");System.out.println(sb.toString());}
static void opll(List<Long> al) {StringBuilder sb= new StringBuilder();for(long x:al)sb.append(x+" ");System.out.println(sb.toString());}
static int[] iarr(int n) {int a[]=new int[n];for(int i=0;i<n;i++)a[i]=fr.ni();return a;}
static long[] larr(int n) {long a[]=new long[n];for(int i=0;i<n;i++)a[i]=fr.nl();return a;}
static void op(int a[]) {StringBuilder sb= new StringBuilder();for(int x:a)sb.append(x+" ");System.out.println(sb.toString());}
static void op(long a[]) {StringBuilder sb= new StringBuilder();for(long x:a)sb.append(x+" ");System.out.println(sb.toString());}
static void sort(int[] a) {ArrayList<Integer>l=new ArrayList<>();for(int i:a) l.add(i);Collections.sort(l);for (int i=0; i<a.length; i++) a[i]=l.get(i);}
static void sort(long[] a) {ArrayList<Long>l=new ArrayList<>();for(long i:a) l.add(i);Collections.sort(l);for (int i=0; i<a.length; i++) a[i]=l.get(i);}
static int gcd(int a,int b) {if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);}
static String rev(String s) {StringBuilder sb= new StringBuilder();sb.append(s);return sb.reverse().toString();}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int snext() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int ni() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nl() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
public String readString() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alexa is a very kind girl. She has 'x' red gems and 'y' blue gems. She wants to distribute them among her two friends (Alice and Julia).
But she will only distribute them if she can give equal number of each colour of gems to Alice and Julia. Further, she must distribute all available gems in this way. So, can you help her make a decision?First line contains two space- separated integers 'x' and 'y' (0 <= x,y <= 100) i. e. number of red and blue gems.In the first line, output "YES" is she can distribute gems else "NO" (without double quotes).Sample Input:
2 3
Sample Output:
NO
Explanation:
Alexa has 3 blue gems, so she can not distribute blue gems., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef unsigned long long int ull;
const long double PI = acos(-1);
const ll mod=1e9+7;
const ll mod1=998244353;
const int inf = 1e9;
const ll INF=1e18;
void precompute(){
}
void TEST_CASE(){
int x1,x2;
cin >> x1 >> x2;
if((x1&1) || (x2&1)){
cout << "NO\n";
}else{
cout << "YES\n";
}
}
signed main(){
fast;
//freopen ("INPUT.txt","r",stdin);
//freopen ("OUTPUT.txt","w",stdout);
int test=1,TEST=1;
precompute();
// cin >> test;
while(test--){
TEST_CASE();
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alexa is a very kind girl. She has 'x' red gems and 'y' blue gems. She wants to distribute them among her two friends (Alice and Julia).
But she will only distribute them if she can give equal number of each colour of gems to Alice and Julia. Further, she must distribute all available gems in this way. So, can you help her make a decision?First line contains two space- separated integers 'x' and 'y' (0 <= x,y <= 100) i. e. number of red and blue gems.In the first line, output "YES" is she can distribute gems else "NO" (without double quotes).Sample Input:
2 3
Sample Output:
NO
Explanation:
Alexa has 3 blue gems, so she can not distribute blue gems., I have written this Solution Code: x,y=map(int,input().split(" "))
if x%2==0 and y%2==0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: // str is input
function isPalindrome(str) {
// write code here
// do not console.log
// return the 1 or 0
const ans = str.split('').reverse().join('') === str ? 1 : 0
return ans
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
int A[2000][2000];
int vis[200][200];
int dist[200][200];
int xa[8]={1,1,-1,-1,2,2,-2,-2};
int ya[8]={2,-2,2,-2,1,-1,1,-1};
int n,m;
int val,hh;
int check(int x,int y)
{
if (x>=0 && y>=0 && x<n && y<m )return 1;
else return 0;
}
#define qw1 freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define qw2 freopen("input2.txt", "r", stdin); freopen("output2.txt", "w", stdout);
#define qw3 freopen("input3.txt", "r", stdin); freopen("output3.txt", "w", stdout);
#define qw4 freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout);
#define qw5 freopen("input5.txt", "r", stdin); freopen("output5.txt", "w", stdout);
#define qw6 freopen("input6.txt", "r", stdin); freopen("output6.txt", "w", stdout);
#define qw freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
signed main()
{
string s;
cin>>s;
int n=s.size();
int ch=1;
for(int j=0;j<=n-1;j++)
{
if(s[j]!=s[n-1-j]) ch=0;
}
cout<<ch;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: num=input()
rev=num[::-1]
if rev==num:
print("1")
else:
print("0"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Check if the given string is a palindrome or not?
Palindromes are a numbers, phrases or words that reads same both the ways, backward as well as forward. For example, 1331 is a palindrome because on reversing the digits the number remains the same. But 123 is not a palindrome, as on reversing the digits it becomes 321. So given a number n you have to output whether the number is a palindrome or not.
Print 1 if True and 0 if false.input contains a single string s.
Constraints:-
1<=|s|<=100000
Note:- String will only contains characters from '0' to '9'.1 or 0. where 1 means the number is palindrome and zero indicates it's not.Sample Input-1
1235321
Sample Output-1
1
Sample Input-2
6547
Sample Output-2
0
Sample Input-3
3443
Sample Output-3
1
Sample Input-4
3434
Sample Output-4
0
Explanation:-
Testcase1:-
On reversing the string it becomes 1235321 which is same as original string hence It is a palindrome, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int len=str.length();
boolean temp=true;
int i=0,j=len-1;
for(i=0;i<len/2;i++){
if(str.charAt(i)!=str.charAt(j--)) temp=false;
}
if(temp) System.out.println(1);
else System.out.println(0);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is standing in a line for her turn to see the doctor. N people are standing in front of Sara, and the doctor takes exactly X minutes for each person. Sara wants to know the time after which her number comes. Since Sara is weak in maths, your task is calculating the time for her turn.You don't have to worry about the input, you just have to complete the function <b>waitingTime()</b>
<b>Constraints:-</b>
1 <= N <= 1000
1 <= X <= 1000Return the total time Sara needs to wait before her turn in minutes.Sample Input 1:-
5 3
Sample Output 1:-
15
Sample Input 2:-
3 2
Sample Output 2:-
6, I have written this Solution Code: static void waitingTime(int N, int X){
System.out.println(N*X);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is standing in a line for her turn to see the doctor. N people are standing in front of Sara, and the doctor takes exactly X minutes for each person. Sara wants to know the time after which her number comes. Since Sara is weak in maths, your task is calculating the time for her turn.You don't have to worry about the input, you just have to complete the function <b>waitingTime()</b>
<b>Constraints:-</b>
1 <= N <= 1000
1 <= X <= 1000Return the total time Sara needs to wait before her turn in minutes.Sample Input 1:-
5 3
Sample Output 1:-
15
Sample Input 2:-
3 2
Sample Output 2:-
6, I have written this Solution Code: void waitingTime(int N, int X){
cout << N*X;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is standing in a line for her turn to see the doctor. N people are standing in front of Sara, and the doctor takes exactly X minutes for each person. Sara wants to know the time after which her number comes. Since Sara is weak in maths, your task is calculating the time for her turn.You don't have to worry about the input, you just have to complete the function <b>waitingTime()</b>
<b>Constraints:-</b>
1 <= N <= 1000
1 <= X <= 1000Return the total time Sara needs to wait before her turn in minutes.Sample Input 1:-
5 3
Sample Output 1:-
15
Sample Input 2:-
3 2
Sample Output 2:-
6, I have written this Solution Code: inp = input()
inp = inp.split()
N,X = int(inp[0]), int(inp[1])
print(N*X), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, find the value of the below equation for the given number.
Equation: -
N
∑ {(X + 1)<sup>2</sup> - (3X + 1) + X}
X = 1<b>User task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 10^5You need to return the sum of the equationSample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
5
Explanation:-
For test 2:- (1+1)^2 - (3*1+1) + (1) + (2+1)^2 - (3*2+1) +2
= 4 - 4 +1 + 9 -7 +2
= 5, I have written this Solution Code: def equationSum(N) :
re=N*(N+1)
re=re*(2*N+1)
re=re//6
return re, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, find the value of the below equation for the given number.
Equation: -
N
∑ {(X + 1)<sup>2</sup> - (3X + 1) + X}
X = 1<b>User task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 10^5You need to return the sum of the equationSample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
5
Explanation:-
For test 2:- (1+1)^2 - (3*1+1) + (1) + (2+1)^2 - (3*2+1) +2
= 4 - 4 +1 + 9 -7 +2
= 5, I have written this Solution Code: long long equationSum(long long N){
long long ans = (N*(N+1)*(2*N+1))/6;
return ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, find the value of the below equation for the given number.
Equation: -
N
∑ {(X + 1)<sup>2</sup> - (3X + 1) + X}
X = 1<b>User task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 10^5You need to return the sum of the equationSample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
5
Explanation:-
For test 2:- (1+1)^2 - (3*1+1) + (1) + (2+1)^2 - (3*2+1) +2
= 4 - 4 +1 + 9 -7 +2
= 5, I have written this Solution Code: long long int equationSum(long long N){
long long ans = (N*(N+1)*(2*N+1))/6;
return ans;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, find the value of the below equation for the given number.
Equation: -
N
∑ {(X + 1)<sup>2</sup> - (3X + 1) + X}
X = 1<b>User task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 10^5You need to return the sum of the equationSample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
5
Explanation:-
For test 2:- (1+1)^2 - (3*1+1) + (1) + (2+1)^2 - (3*2+1) +2
= 4 - 4 +1 + 9 -7 +2
= 5, I have written this Solution Code: static long equationSum(long N)
{
return (N*(N+1)*(2*N + 1))/6;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: int Operations(int n){
int ans=0;
int cnt=0;
int p=n;
int res=n;
while(res/10>0){
cnt=0;
p=res;
n=res;
while(n/10>0){
cnt++;
n=n/10;}
int x=1;
while(cnt--){
x*=10;
}
int t=p/x;
int y=p%x;
ans+=(y/t+1);
res=res-t*(y/t+1);
}
ans++;
return ans;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: public static int Operations(int n){
int ans=0;
int cnt=0;
int p=n;
int res=n;
while(res/10>0){
cnt=0;
p=res;
n=res;
while(n/10>0){
cnt++;
n=n/10;}
int x=1;
while(cnt-->0){
x*=10;
}
int t=p/x;
int y=p%x;
ans+=(y/t+1);
res=res-t*(y/t+1);
}
ans++;
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: def Operations(N) :
ans=0
cnt=0
p=N
res=N
while(res//10>0):
cnt=0
p=res
n=res
while(n//10>0):
cnt=cnt+1
n=n/10
x=pow(10,cnt)
t=p//x
y=p%x
ans=ans+(y//t+1)
res=res-t*(y//t+1)
ans=ans+1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, subtract the first digit of the number N from it i. e if n is 245 then subtract 2 from it making it 245-2 = 243. Keep on doing this operation until the number becomes 0.
Your task is to calculate the number of operation required to make this number N zero.<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>Operations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 1000000000Return the number of operationsSample Input:-
21
Sample Output:-
12
Explanation:-
21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: int Operations(int n){
int ans=0;
int cnt=0;
int p=n;
int res=n;
while(res/10>0){
cnt=0;
p=res;
n=res;
while(n/10>0){
cnt++;
n=n/10;}
int x=1;
while(cnt--){
x*=10;
}
int t=p/x;
int y=p%x;
ans+=(y/t+1);
res=res-t*(y/t+1);
}
ans++;
return ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We need a problem on xor again. Given an array A of N integers (1- indexed), you need to find the sum of (N- i) xor A[i] for all i from 1 to N.The first line of the input contains an integer N, the number of elements of the array.
The second line of the input contains N singly spaced integers of the array A[i].
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ A[i] ≤ 10<sup>9</sup>Output a single integer, the answer to the problem.Sample Input
5
1 2 3 4 5
Sample Output
17
Explanation
(5-1)xor1 = 5, (5-2)xor2 = 1, (5-3)xor3 = 1, (5-4)xor4 = 5, (5-5)xor5 = 5.
Sample Input
5
1 1 0 4 6
Sample Output
20, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
void xorOps(int n, long[] input){
long res=0;
for(int i=0;i<n;i++){
long temp = (n-(i+1))^(input[i]);
res=res+temp;
}
System.out.print(res);
}
public static void main (String[] args)throws java.lang.Exception {
Main obj = new Main();
BufferedReader br = new BufferedReader(new InputStreamReader
(System.in));
int n = Integer.parseInt(br.readLine());
String[] raw_input= br.readLine().split(" ");
long[] input = new long[n];
for(int i=0; i<n;i++){
input[i]=Long.parseLong(raw_input[i]);
}
obj.xorOps(n,input);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.