Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given a string s, find the length of the longest substring without repeating characters.
<b>Note</b> : String contains spaces also.First Line contains the input of the string.
<b> Constraints </b>
1 <= string.length <= 50000
s consists of English letters, digits, symbols, and spaces.Print the length of the longest substring without repeating characters.Sample Input:
abcabcbb
Sample Output:
3
Explanation: The answer is "abc", with a length of 3., I have written this Solution Code: def lengthOfLongestSubstring(s):
ans = 0
sub = ''
for char in s:
if char not in sub:
sub += char
ans = max(ans, len(sub))
else:
cut = sub.index(char)
sub = sub[cut+1:] + char
return ans
s = input()
print(lengthOfLongestSubstring(s)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string s, find the length of the longest substring without repeating characters.
<b>Note</b> : String contains spaces also.First Line contains the input of the string.
<b> Constraints </b>
1 <= string.length <= 50000
s consists of English letters, digits, symbols, and spaces.Print the length of the longest substring without repeating characters.Sample Input:
abcabcbb
Sample Output:
3
Explanation: The answer is "abc", with a length of 3., I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-08 12:34:09
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int main() {
string s;
getline(cin, s);
unordered_map<char, size_t> last_occurrence;
size_t starting_idx = 0, ans = 0;
for (size_t i = 0; i < s.size(); ++i) {
auto it(last_occurrence.find(s[i]));
if (it == last_occurrence.cend()) {
last_occurrence.emplace_hint(it, s[i], i);
} else {
if (it->second >= starting_idx) {
ans = max(ans, i - starting_idx);
starting_idx = it->second + 1;
}
it->second = i;
}
}
ans = max(ans, s.size() - starting_idx);
cout << ans << "\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some messages. Here, we will start with the famous <b>"Hello World"</b> message. Now, here you are given a function to complete. <i>Don't worry about the ins and outs of functions, <b>just add the printing command to print "Hello World", </b></i>.your task is to just print "Hello World", without the quotes.Hello WorldHello World must be printed., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
System.out.print("Hello World");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some messages. Here, we will start with the famous <b>"Hello World"</b> message. Now, here you are given a function to complete. <i>Don't worry about the ins and outs of functions, <b>just add the printing command to print "Hello World", </b></i>.your task is to just print "Hello World", without the quotes.Hello WorldHello World must be printed., I have written this Solution Code: def print_fun():
print ("Hello World")
def main():
print_fun()
if __name__ == '__main__':
main(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: def DivisorProblem(N):
ans=0
while N>1:
cnt=2
while N%cnt!=0:
cnt=cnt+1
N = N//cnt
ans=ans+1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: static int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: def QueenAttack(X, Y, P, Q):
if X==P or Y==Q or abs(X-P)==abs(Y-Q):
return 1
return 0, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: static int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || Math.abs(X-P)==Math.abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid.
<b>Constraints:-</b>
1 <= n <= 100000
0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:-
10
1 2 3 2 4 3 6 6 7 6
Sample Output 1:-
0 0 0 1 0 1 0 0 0 1
43
Sample Input 2:-
7
10 20 30 40 30 20 10
Sample Output 2:-
0 0 0 0 10 20 30
220, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int n = Integer.parseInt(in.readLine());
int []donationList = new int[n];
int[] defaulterList = new int[n];
long totalDonations = 0L;
StringTokenizer st = new StringTokenizer(in.readLine());
for(int i=0 ; i<n ; i++){
donationList[i] = Integer.parseInt(st.nextToken());
}
int max = Integer.MIN_VALUE;
for(int i=0; i<n; i++){
totalDonations += donationList[i];
max = Math.max(max,donationList[i]);
if(i>0){
if(donationList[i] >= max)
defaulterList[i] = 0;
else
defaulterList[i] = max - donationList[i];
}
totalDonations += defaulterList[i];
}
for(int i=0; i<n ;i++){
System.out.print(defaulterList[i]+" ");
}
System.out.println();
System.out.print(totalDonations);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid.
<b>Constraints:-</b>
1 <= n <= 100000
0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:-
10
1 2 3 2 4 3 6 6 7 6
Sample Output 1:-
0 0 0 1 0 1 0 0 0 1
43
Sample Input 2:-
7
10 20 30 40 30 20 10
Sample Output 2:-
0 0 0 0 10 20 30
220, I have written this Solution Code: n = int(input())
a = input().split()
b = int(a[0])
sum = 0
for i in a:
if int(i)<b:
print(b-int(i),end=' ')
else:
b = int(i)
print(0,end=' ')
sum = sum+b
print()
print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid.
<b>Constraints:-</b>
1 <= n <= 100000
0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:-
10
1 2 3 2 4 3 6 6 7 6
Sample Output 1:-
0 0 0 1 0 1 0 0 0 1
43
Sample Input 2:-
7
10 20 30 40 30 20 10
Sample Output 2:-
0 0 0 0 10 20 30
220, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int n;
cin>>n;
int a[n];
int ma=0;
int cnt=0;
//map<int,int> m;
for(int i=0;i<n;i++){
cin>>a[i];
ma=max(ma,a[i]);
cout<<ma-a[i]<<" ";
cnt+=ma-a[i];
cnt+=a[i];
//m[a[i]]++;
}
cout<<endl;
cout<<cnt<<endl;
}
signed main(){
int t;
t=1;
while(t--){
solve();}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to become rich so he came up with an idea, So, he buys some gadgets from the future at a price of C and sells them at a price of S to his friends. Now Nobita wants to know how much he gains by selling all gadget. As we all know Nobita is weak in maths help him to find the profit he getsYou don't have to worry about the input, you just have to complete the function <b>Profit()</b>
<b>Constraints:-</b>
1 <= C <= S <= 1000Print the profit Nobita gets from selling one gadget.Sample Input:-
3 5
Sample Output:-
2
Sample Input:-
9 16
Sample Output:-
7, I have written this Solution Code: def profit(C, S):
print(S - C), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to become rich so he came up with an idea, So, he buys some gadgets from the future at a price of C and sells them at a price of S to his friends. Now Nobita wants to know how much he gains by selling all gadget. As we all know Nobita is weak in maths help him to find the profit he getsYou don't have to worry about the input, you just have to complete the function <b>Profit()</b>
<b>Constraints:-</b>
1 <= C <= S <= 1000Print the profit Nobita gets from selling one gadget.Sample Input:-
3 5
Sample Output:-
2
Sample Input:-
9 16
Sample Output:-
7, I have written this Solution Code: static void Profit(int C, int S){
System.out.println(S-C);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T — the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, — the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=0;i<T;i++)
{
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
if(a>b && a>c)
{
System.out.println("Alice");
}
else if(b>a && b>c)
{
System.out.println("Bob");
}
else if(c>a && c>b)
{
System.out.println("Charlie");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T — the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, — the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: #include <bits/stdc++.h>
int main() {
int T = 0;
std::cin >> T;
while (T--) {
int A = 0, B = 0, C = 0;
std::cin >> A >> B >> C;
assert(A != B && B != C && C != A);
if (A > B && A > C) {
std::cout << "Alice" << '\n';
} else if (B > A && B > C) {
std::cout << "Bob" << '\n';
} else {
std::cout << "Charlie" << '\n';
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T — the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, — the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: T = int(input())
for i in range(T):
A,B,C = list(map(int,input().split()))
if A>B and A>C:
print("Alice")
elif B>A and B>C:
print("Bob")
else:
print("Charlie"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Take an integer as input and print it.The first line contains integer as input.
<b>Constraints</b>
1 <= N <= 10Print the input integer in a single lineSample Input:-
2
Sample Output:-
2
Sample Input:-
4
Sample Output:-
4, I have written this Solution Code: /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void printVariable(int variable){
System.out.println(variable);
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
printVariable(num);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble 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>candies()</b> that takes integers X, and Y as arguments.
Constraints:-
1 <= X <= 1000
1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:-
X = 3, Y = 5
Sample Output:-
1
Explanation:-
Total people in Sara's home = 5, no. of people allowed = 3
Sample Input:-
X = 4, Y = 2
Sample Output:-
0, I have written this Solution Code: static int candies(int X, int Y){
if(X<=Y){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble 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>candies()</b> that takes integers X, and Y as arguments.
Constraints:-
1 <= X <= 1000
1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:-
X = 3, Y = 5
Sample Output:-
1
Explanation:-
Total people in Sara's home = 5, no. of people allowed = 3
Sample Input:-
X = 4, Y = 2
Sample Output:-
0, I have written this Solution Code: int candies(int X, int Y){
if(X<=Y){return 1;}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble 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>candies()</b> that takes integers X, and Y as arguments.
Constraints:-
1 <= X <= 1000
1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:-
X = 3, Y = 5
Sample Output:-
1
Explanation:-
Total people in Sara's home = 5, no. of people allowed = 3
Sample Input:-
X = 4, Y = 2
Sample Output:-
0, I have written this Solution Code: def candies(X,Y):
if(X<=Y):
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: According to the latest government guidelines, the mass gathering of more than or equal to X people are not allowed but Sara organizes a party in her home and invited Y of her friends. As per the government guidelines your task is to tell Sara if she is in trouble 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>candies()</b> that takes integers X, and Y as arguments.
Constraints:-
1 <= X <= 1000
1 <= Y <= 1000Return 1 if Sara is in trouble else return 0.Sample Input:-
X = 3, Y = 5
Sample Output:-
1
Explanation:-
Total people in Sara's home = 5, no. of people allowed = 3
Sample Input:-
X = 4, Y = 2
Sample Output:-
0, I have written this Solution Code: int candies(int X, int Y){
if(X<=Y){return 1;}
return 0;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string s of length n. Find all the repeating characters and count their occurrence. A character is a repeating character if it occurs more than once.First line contains n.
Next line contains the string s.
<b>Constraints</b>
1 ≤ n ≤ 10<sup>5</sup>
s contains only lowercase English letters.Print all the repeating characters and their frequency. Print in order from 'a' to 'z'.Input:
6
banana
Output:
a 3
n 2
Explanation :
b occurs only once., I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
int n=Integer.parseInt(in.next());
String s=in.next();
int a[] = new int[26];
Arrays.fill(a,0);
for(int i=0;i<n;i++)
{
int j=s.charAt(i) - 'a';
a[j]++;
}
for(int i=0;i<26;i++){
if(a[i] > 1){
out.println((char)('a' + i) + " " + a[i]);
}
}
out.close();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void println(int i) {
writer.println(i);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</b>".<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 ≤ n ≤ 100Print even or odd for each i, separated by white spaces.Sample Input:
5
Sample Output:
odd even odd even odd
Sample Input:
2
Sample Output:
odd even, I have written this Solution Code: public static void For_Loop(int n){
for(int i=1;i<=n;i++){
if(i%2==1){System.out.print("odd ");}
else{
System.out.print("even ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</b>".<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 ≤ n ≤ 100Print even or odd for each i, separated by white spaces.Sample Input:
5
Sample Output:
odd even odd even odd
Sample Input:
2
Sample Output:
odd even, I have written this Solution Code: n = int(input())
for i in range(1, n+1):
if(i%2)==0:
print("even ",end="")
else:
print("odd ",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: static void pattern(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j + " ");
}
System.out.println();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: function pattern(n) {
// write code herenum
for(let i = 1;i<=n;i++){
let str = ''
for(let k = 1; k <= i;k++){
if(k === 1) {
str += `${k}`
}else{
str += ` ${k}`
}
}
console.log(str)
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: def patternPrinting(n):
for i in range(1,n+1):
for j in range (1,i+1):
print(j,end=' ')
print()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the Armstrong numbers which are present between 1 to N.
<b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N.
Constraints:-
1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:-
2
Sample Output:-
1
Sample input:-
4
Sample Output:
1, I have written this Solution Code: import math
n= int(input())
for i in range (1,n+1):
arm=i
summ=0
while(arm!=0):
rem=math.pow(arm%10,3)
summ=summ+rem
arm=math.floor(arm/10)
if summ == i :
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the Armstrong numbers which are present between 1 to N.
<b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N.
Constraints:-
1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:-
2
Sample Output:-
1
Sample input:-
4
Sample Output:
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
bool checkArmstrong(int n)
{
int temp = n, sum = 0;
while(n > 0)
{
int d = n%10;
sum = sum + d*d*d;
n = n/10;
}
if(sum == temp)
return true;
return false;
}
int main()
{
int n;
cin>>n;
for(int i = 1; i <= n; i++)
{
if(checkArmstrong(i) == true)
cout << i << " ";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the Armstrong numbers which are present between 1 to N.
<b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N.
Constraints:-
1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:-
2
Sample Output:-
1
Sample input:-
4
Sample Output:
1, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int digitsum,num,digit;
for(int i=1;i<=n;i++){
digitsum=0;
num=i;
while(num>0){
digit=num%10;
digitsum+=digit*digit*digit;
num/=10;
}
if(digitsum==i){System.out.print(i+" ");}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S.
Constraints:
1 <= T <= 100
1 <= |S| <= 1000
Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input:
2
Bawdsjogflickquartzvenymph
sdfs
Output:
0
0
Explanation :
Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0.
Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: def ispangram(str):
alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in alphabet:
if char not in str.lower():
return False
return True
N = int(input())
arr = []
for i in range(N):
arr.append(input())
for i in range(N):
if(ispangram(arr[i]) == True):
print(1)
else:
print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S.
Constraints:
1 <= T <= 100
1 <= |S| <= 1000
Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input:
2
Bawdsjogflickquartzvenymph
sdfs
Output:
0
0
Explanation :
Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0.
Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: function pangrams(s) {
// write code here
// do not console.log it
// return 1 or 0
let alphabet = "abcdefghijklmnopqrstuvwxyz";
let regex = /\s/g;
let lowercase = s.toLowerCase().replace(regex, "");
for(let i = 0; i < alphabet.length; i++){
if(lowercase.indexOf(alphabet[i]) === -1){
return 0;
}
}
return 1;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S.
Constraints:
1 <= T <= 100
1 <= |S| <= 1000
Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input:
2
Bawdsjogflickquartzvenymph
sdfs
Output:
0
0
Explanation :
Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0.
Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
String s = sc.next();
int check = 1;
int p =0;
for(char ch = 'a';ch<='z';ch++){
p=0;
for(int i = 0;i<s.length();i++){
if(s.charAt(i)==ch){p=1;}
}
if(p==0){check=0;}
}
System.out.println(check);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S.
Constraints:
1 <= T <= 100
1 <= |S| <= 1000
Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input:
2
Bawdsjogflickquartzvenymph
sdfs
Output:
0
0
Explanation :
Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0.
Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., 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[26],B[26];
signed main()
{
int t;
cin>>t;
string p;
getline(cin,p);
while(t>0)
{
t--;
string s;
getline(cin,s);
int n=s.size();
memset(A,0,sizeof(A));
int ch=1;
for(int i=0;i<n;i++)
{
int x=s[i]-'a';
if(x>=0 && x<26)
{
A[x]++;
}
x=s[i]-'A';
if(x>=0 && x<26)
{
A[x]++;
}
}
for(int i=0;i<26;i++)
{
if(A[i]==0) ch=0;
}
cout<<ch<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid.
<b>Constraints:-</b>
1 <= n <= 100000
0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:-
10
1 2 3 2 4 3 6 6 7 6
Sample Output 1:-
0 0 0 1 0 1 0 0 0 1
43
Sample Input 2:-
7
10 20 30 40 30 20 10
Sample Output 2:-
0 0 0 0 10 20 30
220, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int n = Integer.parseInt(in.readLine());
int []donationList = new int[n];
int[] defaulterList = new int[n];
long totalDonations = 0L;
StringTokenizer st = new StringTokenizer(in.readLine());
for(int i=0 ; i<n ; i++){
donationList[i] = Integer.parseInt(st.nextToken());
}
int max = Integer.MIN_VALUE;
for(int i=0; i<n; i++){
totalDonations += donationList[i];
max = Math.max(max,donationList[i]);
if(i>0){
if(donationList[i] >= max)
defaulterList[i] = 0;
else
defaulterList[i] = max - donationList[i];
}
totalDonations += defaulterList[i];
}
for(int i=0; i<n ;i++){
System.out.print(defaulterList[i]+" ");
}
System.out.println();
System.out.print(totalDonations);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid.
<b>Constraints:-</b>
1 <= n <= 100000
0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:-
10
1 2 3 2 4 3 6 6 7 6
Sample Output 1:-
0 0 0 1 0 1 0 0 0 1
43
Sample Input 2:-
7
10 20 30 40 30 20 10
Sample Output 2:-
0 0 0 0 10 20 30
220, I have written this Solution Code: n = int(input())
a = input().split()
b = int(a[0])
sum = 0
for i in a:
if int(i)<b:
print(b-int(i),end=' ')
else:
b = int(i)
print(0,end=' ')
sum = sum+b
print()
print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid.
<b>Constraints:-</b>
1 <= n <= 100000
0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:-
10
1 2 3 2 4 3 6 6 7 6
Sample Output 1:-
0 0 0 1 0 1 0 0 0 1
43
Sample Input 2:-
7
10 20 30 40 30 20 10
Sample Output 2:-
0 0 0 0 10 20 30
220, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int n;
cin>>n;
int a[n];
int ma=0;
int cnt=0;
//map<int,int> m;
for(int i=0;i<n;i++){
cin>>a[i];
ma=max(ma,a[i]);
cout<<ma-a[i]<<" ";
cnt+=ma-a[i];
cnt+=a[i];
//m[a[i]]++;
}
cout<<endl;
cout<<cnt<<endl;
}
signed main(){
int t;
t=1;
while(t--){
solve();}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Aunt May receives a letter from Peter’s school that his grades are going down. So she decides to confiscate his phone. One day when Aunt May has gone shopping, Peter decides to get his phone back. He tries unlocking the phone but soon realizes that it is locked. So he puts on his detective cap and analyses the fingerprints of his Aunt on most keypads. He soon dials down the most used number. Help Peter make a list of all possible passwords using N digits.
Given a keypad as shown in diagram, and an N digit number. List all words which are possible by pressing these numbers.
By pressing a digit you can access any of its mentioned characters.The first line of input contains a single integer T denoting the number of test cases. The first line of each test case contains the number of digits N. The next line contains N space-separated integers depicting the digits.
Constraints:
1 <= T <= 100
1 <= N <= 9
2 <= D[i] <= 9Print all possible words in lexicographical order.Sample Input:
2
3
2 3 4
3
3 4 5
Sample Output:
adg adh adi aeg aeh aei afg afh afi bdg bdh bdi beg beh bei bfg bfh bfi cdg cdh cdi ceg ceh cei cfg cfh cfi
dgj dgk dgl dhj dhk dhl dij dik dil egj egk egl ehj ehk ehl eij eik eil fgj fgk fgl fhj fhk fhl fij fik fil
Explanation:
Testcase 1: When we press 2, 3, 4 then adg, adh, adi, ., cfi are the list of possible words.
Testcase 2: When we press 3, 4, 5 then dgj, dgk, dgl,. , fil are the list of possible words., I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0)
{
int n = sc.nextInt(); // input size of array
int arr[] = new int[n]; //input the elements of array that are keys to be pressed
for(int i = 0; i < n; i++)
arr[i] = sc.nextInt();
possibleWords(arr, n);
System.out.println();
}
}
static String hash[] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
static void possibleWords(int arr[], int N)
{
String str = "";
for(int i = 0; i < N; i++)
str += arr[i];
ArrayList<String> res = possibleWordsUtil(str);
Collections.sort(res); // arrange all possible strings lexicographically
for(String s: res)
System.out.print(s + " ");
}
static ArrayList<String> possibleWordsUtil(String str)
{
// If str is empty
if (str.length() == 0) {
ArrayList<String> baseRes = new ArrayList<>();
baseRes.add("");
// Return an Arraylist containing
// empty string
return baseRes;
}
// First character of str
char ch = str.charAt(0);
// Rest of the characters of str
String restStr = str.substring(1);
// get all the combination
ArrayList<String> prevRes = possibleWordsUtil(restStr);
ArrayList<String> Res = new ArrayList<>();
String code = hash[ch - '0'];
for (String val : prevRes) {
for (int i = 0; i < code.length(); i++) {
Res.add(code.charAt(i) + val);
}
}
return Res;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers, and an integer ‘K’, find the count of pairs of elements in the array whose sum is equal to 'K'.The first line of the input contains 2 space separated integers N and K denoting the size of array and the sum respectively.
The second line of the input contains N space separated integers denoting the elements of the array.
Constraints:
1 <= N <= 100000
1 <= K <= 100000
1 <= A[i] <= 100000Print the count of pairs of elements in the array whose sum is equal to the K.Sample Input:
4 6
1 5 7 1
Sample Output:
2, I have written this Solution Code: n,k=input().split()
n=int(n)
k=int(k)
arr=input().split()
for i in range(0,n):
arr[i]=int(arr[i])
x=[0]*100000
for i in range(0,n):
x[arr[i]]+=1
count=0
for i in range(0,n):
count+=x[k-arr[i]]
if((k-arr[i])==arr[i]):
count-=1
print (int(count/2)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers, and an integer ‘K’, find the count of pairs of elements in the array whose sum is equal to 'K'.The first line of the input contains 2 space separated integers N and K denoting the size of array and the sum respectively.
The second line of the input contains N space separated integers denoting the elements of the array.
Constraints:
1 <= N <= 100000
1 <= K <= 100000
1 <= A[i] <= 100000Print the count of pairs of elements in the array whose sum is equal to the K.Sample Input:
4 6
1 5 7 1
Sample Output:
2, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define max1 1000008
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ull cnt[max1];
int main(){
int n,k;
cin>>n>>k;
int a[n];
unordered_map<int,int> m;
ll ans=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(m.find(k-a[i])!=m.end()){ans+=m[k-a[i]];}
m[a[i]]++;
}
cout<<ans<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers, and an integer ‘K’, find the count of pairs of elements in the array whose sum is equal to 'K'.The first line of the input contains 2 space separated integers N and K denoting the size of array and the sum respectively.
The second line of the input contains N space separated integers denoting the elements of the array.
Constraints:
1 <= N <= 100000
1 <= K <= 100000
1 <= A[i] <= 100000Print the count of pairs of elements in the array whose sum is equal to the K.Sample Input:
4 6
1 5 7 1
Sample Output:
2, I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int arrSize = sc.nextInt();
int targetK = sc.nextInt();
int arr[] = new int[arrSize];
for(int i = 0; i < arrSize; i++)
arr[i] = sc.nextInt();
System.out.println(countPairs(arr, arrSize, targetK));
}
static long countPairs(int arr[], int arrSize, int targetK)
{
long ans = 0;
HashMap<Integer, Integer> hash = new HashMap<>();
for(int i = 0; i < arrSize; i++)
{
int elem = arr[i];
if(hash.containsKey(targetK-elem) == true)
ans += hash.get(targetK-elem);
if(hash.containsKey(elem) == true)
{
int freq = hash.get(elem);
hash.put(elem, freq+1);
}
else
hash.put(elem, 1);
}
return ans;
}
}, 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, your task is to check if the given list is circular or not.
<b>Note: Sample Input and Output just show how a linked list will look depending on the questions. Do not copy-paste as it is in custom input</b><b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>check()</b> that takes the head node as a parameter.
<b>Note: 0 and 1 in sample input just show given LL is CLL or not. 1 denotes it is CLL, 0 denotes not</b>
Constraints:
1 <=N <= 1000
1 <= Node.data<= 1000
Return 1 if the given linked list is circular else return 0.Sample Input 1:-
3 0
1 2 3
Sample Output 1:-
0
Explanation:-
1->2->3
Sample Input 2:-
3 1
1 2 3
Sample Output 2:-
1
Explanation:-
1->2->3->1.......
, I have written this Solution Code: public static int check(Node head) {
if (head == null)
return 1;
Node node = head.next;
while (node != null && node != head)
node = node.next;
if(node==head){return 1;}
else {return 0;}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N points on 2D plane, you have to setup a camp at a point such that sum of Manhattan distance all the points from that point is minimum. If there are many such points you have to find the point with minimum X coordinate and if there are many points with same X coordinate, you have to minimize Y coordinate.
Manhattan distance between points (x1, y1) and (x2, y2) = |x1 - x2| + |y1 - y2|.First line of input contains N.
Next N lines contains two space separated integers denoting the ith coordinate.
Constraints:
1 <= N <= 100000
1 <= X[i], Y[i] <= 1000000000
Note:- the camp can overlap with the given points and the given points can also overlap(you have to consider overlapping points separately).Print two space separated integers, denoting the X and Y coordinate of the camp.Sample Input
3
3 3
1 1
3 2
Sample Output
3 2
Explanation:
Sum of distances = 1 + 3 + 0 = 4
This is the minimum distance possible., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int arr[] = new int[n];
int brr[] = new int[n];
for(int i=0;i<n;i++){
String str[] = br.readLine().split(" ");
arr[i] = Integer.parseInt(str[0]);
brr[i] = Integer.parseInt(str[1]);
}
Arrays.sort(arr);
Arrays.sort(brr);
int m=0;
if(n%2==0){
m = n/2;
}else{
m = (n/2)+1;
}
System.out.println(arr[m-1]+" "+brr[m-1]);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N points on 2D plane, you have to setup a camp at a point such that sum of Manhattan distance all the points from that point is minimum. If there are many such points you have to find the point with minimum X coordinate and if there are many points with same X coordinate, you have to minimize Y coordinate.
Manhattan distance between points (x1, y1) and (x2, y2) = |x1 - x2| + |y1 - y2|.First line of input contains N.
Next N lines contains two space separated integers denoting the ith coordinate.
Constraints:
1 <= N <= 100000
1 <= X[i], Y[i] <= 1000000000
Note:- the camp can overlap with the given points and the given points can also overlap(you have to consider overlapping points separately).Print two space separated integers, denoting the X and Y coordinate of the camp.Sample Input
3
3 3
1 1
3 2
Sample Output
3 2
Explanation:
Sum of distances = 1 + 3 + 0 = 4
This is the minimum distance possible., I have written this Solution Code: n = int(input())
x = []
y = []
for _ in range(n):
tempX,tempY = map(int,input().split())
x.append(tempX)
y.append(tempY)
x.sort()
y.sort()
print(x[(n-1)//2], y[(n-1)//2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N points on 2D plane, you have to setup a camp at a point such that sum of Manhattan distance all the points from that point is minimum. If there are many such points you have to find the point with minimum X coordinate and if there are many points with same X coordinate, you have to minimize Y coordinate.
Manhattan distance between points (x1, y1) and (x2, y2) = |x1 - x2| + |y1 - y2|.First line of input contains N.
Next N lines contains two space separated integers denoting the ith coordinate.
Constraints:
1 <= N <= 100000
1 <= X[i], Y[i] <= 1000000000
Note:- the camp can overlap with the given points and the given points can also overlap(you have to consider overlapping points separately).Print two space separated integers, denoting the X and Y coordinate of the camp.Sample Input
3
3 3
1 1
3 2
Sample Output
3 2
Explanation:
Sum of distances = 1 + 3 + 0 = 4
This is the minimum distance possible., I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int x[n],y[n];
for(int i=0;i<n;++i){
cin>>x[i]>>y[i];
}
sort(x,x+n);
sort(y,y+n);
cout<<x[(n-1)/2]<<" "<<y[(n-1)/2];
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: n=int(input())
for i in range(1,n+1):
if i%3==0 and i%5==0:
print("NewtonSchool",end=" ")
elif i%3==0:
print("Newton",end=" ")
elif i%5==0:
print("School",end=" ")
else:
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
static void NewtonSchool(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("NewtonSchool ");}
else if(i%5==0){System.out.print("School ");}
else if(i%3==0){System.out.print("Newton ");}
else{System.out.print(i+" ");}
}
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
NewtonSchool(x);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: m,n = map(int , input().split())
if (m%n==0):
print("Yes")
else:
print("No");, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,m;
cin>>n>>m;
if(n%m==0)
cout<<"Yes";
else
cout<<"No";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
Long m = sc.nextLong();
if(n%m==0){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 ≤ A, B ≤ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
String s[]=bu.readLine().split(" ");
int a=Integer.parseInt(s[0]),b=Integer.parseInt(s[1]);
int ans=2;
if(a==b) ans=0;
else if(a%b==0 || b%a==0 || a+1==b || b+1==a) ans=1;
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 ≤ A, B ≤ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: l=list(map(int, input().split()))
A=l[0]
B=l[1]
if A==B:
print(0)
elif A%B==0 or B%A==0 or abs(A-B)==1:
print(1)
else:
print(2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 ≤ A, B ≤ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a == b) cout << 0;
else if (abs(a - b) == 1) cout << 1;
else if (a % b == 0 || b % a == 0) cout << 1;
else cout << 2;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code: N = int(input())
Nums = list(map(int,input().split()))
f = False
for n in Nums:
if n < 0:
f = True
break
if (f):
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a;
bool win=false;
for(int i=0;i<n;i++){
cin>>a;
if(a<0){win=true;}}
if(win){
cout<<"Yes";
}
else{
cout<<"No";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = sc.nextInt();
}
for(int i=0;i<n;i++){
if(a[i]<0){System.out.print("Yes");return;}
}
System.out.print("No");
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to calculate the sum of the numbers occurring in the multiplication table of the given integer up to 10, and the numbers occurring in the multiplication table should be a single-digit number, if it's not single-digit then you need to sum its digit until it becomes a single-digit number before taking the sum.
i.e. 1x1=1, 1x2=2, ....,1x10=10. so the sum is 1+2+3...+10 => now 10 is a 2 digit number so it becomes 1+0=1, i.e sum becomes 46.The only line contains the value of integer n
<b>Constraints</b>
1 ≤ n ≤ 10Print the sumSample Input:
1
Sample output:
46
<b>Explanation</b>
As explained above in the Question., I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Solution {
public static int calculateSum(int n) {
int i = 1, sum = 0;
while(i <= 10) {
int num = i * n;
for(int j = 0; j < 4; j++) {
int tempSum = 0;
while(num != 0) {
tempSum += num % 10;
num /= 10;
}
num = tempSum;
}
sum += num;
i += 1;
}
return sum;
}
}
class Main{
public static void main(String[] args) throws java.lang.Exception{
Scanner myobj = new Scanner(System.in);
int n = myobj.nextInt();
Solution obj=new Solution();
System.out.println(obj.calculateSum(n));
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to calculate the sum of the numbers occurring in the multiplication table of the given integer up to 10, and the numbers occurring in the multiplication table should be a single-digit number, if it's not single-digit then you need to sum its digit until it becomes a single-digit number before taking the sum.
i.e. 1x1=1, 1x2=2, ....,1x10=10. so the sum is 1+2+3...+10 => now 10 is a 2 digit number so it becomes 1+0=1, i.e sum becomes 46.The only line contains the value of integer n
<b>Constraints</b>
1 ≤ n ≤ 10Print the sumSample Input:
1
Sample output:
46
<b>Explanation</b>
As explained above in the Question., I have written this Solution Code: #include <bits/stdc++.h> // header file includes every Standard library
using namespace std;
int main() {
int n;
cin>>n;
int i=1, sum = 0;
while(i<=10){
int num = i*n;
for(int i=0 ; i<4 ; i++){
int tempSum = 0;
while(num){
tempSum += num%10;
num/=10;
}
num = tempSum;
}
sum += num;
i+=1;
}
cout<<sum<<"\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array, your task is to sort the array using merge sort.<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>implementMergeSort()</b> that takes 3 arguments.
arr: input array
start: starting index which is 0
end: ending index of array
Constraints
1 <= T <= 100
1 <= N <= 10<sup>6</sup>
0 <= Arr[i] <= 10<sup>9</sup>
Sum of 'N' over all test cases does not exceed 10<sup>6</sup>You need to return the sorted array. The driver code will print the array in sorted form.Sample Input:
2
3
3 1 2
3
4 5 6
Sample Output:
1 2 3
4 5 6, I have written this Solution Code:
public static int[] implementMergeSort(int arr[], int start, int end)
{
if (start < end)
{
// Find the middle point
int mid = (start+end)/2;
// Sort first and second halves
implementMergeSort(arr, start, mid);
implementMergeSort(arr , mid+1, end);
// Merge the sorted halves
merge(arr, start, mid, end);
}
return arr;
}
public static void merge(int arr[], int start, int mid, int end)
{
// Find sizes of two subarrays to be merged
int n1 = mid - start + 1;
int n2 = end - mid;
/* Create temp arrays */
int L[] = new int [n1];
int R[] = new int [n2];
/*Copy data to temp arrays*/
for (int i=0; i<n1; ++i)
L[i] = arr[start + i];
for (int j=0; j<n2; ++j)
R[j] = arr[mid + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = start;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array, your task is to sort the array using merge sort.<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>implementMergeSort()</b> that takes 3 arguments.
arr: input array
start: starting index which is 0
end: ending index of array
Constraints
1 <= T <= 100
1 <= N <= 10<sup>6</sup>
0 <= Arr[i] <= 10<sup>9</sup>
Sum of 'N' over all test cases does not exceed 10<sup>6</sup>You need to return the sorted array. The driver code will print the array in sorted form.Sample Input:
2
3
3 1 2
3
4 5 6
Sample Output:
1 2 3
4 5 6, I have written this Solution Code: for _ in range(int(input())):
n = int(input())
print(*sorted(list(map(int,input().split())))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a Prefix expression, convert it into a Infix expression.
Infix : An expression is called the Infix expression if the operator appears in between the operands in the expression. Simply of the form (operand1 operator operand2).
Example : (M+N) * (O-P)
Prefix : An expression is called the prefix expression if the operator appears in the expression before the operands. Simply of the form (operator operand1 operand2).
Example : *+MN-OP (Infix : (M+N) * (O-P) )Input contains a single string of prefix expression.
Constraints:
1 < = string length < = 20
Note :- String will only contain uppercase english letters and maths operand :- '/', '*', '+', '-'.
Print the Infix expression.Sample Input
*-A/BC-/AKL
Sample Output:
((A-(B/C))*((A/K)-L))
Sample Input
+AB
Sample Output
A+B, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static void operationOnOperands(char ch,Stack<String> S)
{
String st="";
st=st+'(';
if(S.empty()==false)
st=st+S.pop();
st=st+ch;
if(S.empty()==false)
st=st+S.pop();
st=st+')';
S.push(st);
}
static String traversalOfString(String str,Stack<String> S)
{
for(int i=str.length()-1;i>=0;i--)
{
if(Character.isLetter(str.charAt(i)))
S.push(String.valueOf(str.charAt(i)));
else
operationOnOperands(str.charAt(i),S);
}
return S.pop();
}
public static void main (String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Stack<String> S=new Stack<String>();
String str=br.readLine();
System.out.print(traversalOfString(str,S));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a Prefix expression, convert it into a Infix expression.
Infix : An expression is called the Infix expression if the operator appears in between the operands in the expression. Simply of the form (operand1 operator operand2).
Example : (M+N) * (O-P)
Prefix : An expression is called the prefix expression if the operator appears in the expression before the operands. Simply of the form (operator operand1 operand2).
Example : *+MN-OP (Infix : (M+N) * (O-P) )Input contains a single string of prefix expression.
Constraints:
1 < = string length < = 20
Note :- String will only contain uppercase english letters and maths operand :- '/', '*', '+', '-'.
Print the Infix expression.Sample Input
*-A/BC-/AKL
Sample Output:
((A-(B/C))*((A/K)-L))
Sample Input
+AB
Sample Output
A+B, I have written this Solution Code: string=input()
stack=list()
for i in string[::-1]:
if i not in ['/','*','^','+','-']:
stack.append(i)
else:
stack.append('('+stack.pop()+i+stack.pop()+')')
print(stack[-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a Prefix expression, convert it into a Infix expression.
Infix : An expression is called the Infix expression if the operator appears in between the operands in the expression. Simply of the form (operand1 operator operand2).
Example : (M+N) * (O-P)
Prefix : An expression is called the prefix expression if the operator appears in the expression before the operands. Simply of the form (operator operand1 operand2).
Example : *+MN-OP (Infix : (M+N) * (O-P) )Input contains a single string of prefix expression.
Constraints:
1 < = string length < = 20
Note :- String will only contain uppercase english letters and maths operand :- '/', '*', '+', '-'.
Print the Infix expression.Sample Input
*-A/BC-/AKL
Sample Output:
((A-(B/C))*((A/K)-L))
Sample Input
+AB
Sample Output
A+B, I have written this Solution Code: #include <iostream>
#include <stack>
using namespace std;
// function to check if character is operator or not
bool isOperator(char x) {
switch (x) {
case '+':
case '-':
case '/':
case '*':
return true;
}
return false;
}
// Convert prefix to Infix expression
string preToInfix(string pre_exp) {
stack<string> s;
// length of expression
int length = pre_exp.size();
// reading from right to left
for (int i = length - 1; i >= 0; i--) {
// check if symbol is operator
if (isOperator(pre_exp[i])) {
// pop two operands from stack
string op1 = s.top(); s.pop();
string op2 = s.top(); s.pop();
// concat the operands and operator
string temp = "(" + op1 + pre_exp[i] + op2 + ")";
// Push string temp back to stack
s.push(temp);
}
// if symbol is an operand
else {
// push the operand to the stack
s.push(string(1, pre_exp[i]));
}
}
// Stack now contains the Infix expression
return s.top();
}
// Driver Code
int main() {
string pre_exp ;
cin>>pre_exp;
cout << preToInfix(pre_exp);
return 0;
} , In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: def QueenAttack(X, Y, P, Q):
if X==P or Y==Q or abs(X-P)==abs(Y-Q):
return 1
return 0, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: static int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || Math.abs(X-P)==Math.abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to calculate the sum of all the odd integers present in the array.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
1 < = Arr[i] < = 10000Print the sum of all the odd integers present in the array.Sample Input:-
4
1 2 3 4
Sample Output:-
4
Sample Input:-
2 4 6 8
Sample Output:-
0, I have written this Solution Code: n = int(input())
num = input().split(" ")
sums=0
for i in range(0,n):
if int(num[i])%2 != 0:
sums = sums + int(num[i])
print(sums), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to calculate the sum of all the odd integers present in the array.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
1 < = Arr[i] < = 10000Print the sum of all the odd integers present in the array.Sample Input:-
4
1 2 3 4
Sample Output:-
4
Sample Input:-
2 4 6 8
Sample Output:-
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a;
int sum=0;
for(int i=0;i<n;i++){
cin>>a;
if(a&1){sum+=a;}}
cout<<sum;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to calculate the sum of all the odd integers present in the array.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
1 < = Arr[i] < = 10000Print the sum of all the odd integers present in the array.Sample Input:-
4
1 2 3 4
Sample Output:-
4
Sample Input:-
2 4 6 8
Sample Output:-
0, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int sum=0;
for(int i=0;i<n;i++){
if(a[i]%2==1){
sum+=a[i];
}
}
System.out.print(sum);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){cout<<"FizzBuzz"<<" ";}
else if(i%5==0){cout<<"Buzz ";}
else if(i%3==0){cout<<"Fizz ";}
else{cout<<i<<" ";}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
fizzbuzz(x);
}
static void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");}
else if(i%5==0){System.out.print("Buzz ");}
else if(i%3==0){System.out.print("Fizz ");}
else{System.out.print(i+" ");}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: def fizzbuzz(n):
for i in range (1,n+1):
if (i%3==0 and i%5==0):
print("FizzBuzz",end=' ')
elif i%3==0:
print("Fizz",end=' ')
elif i%5==0:
print("Buzz",end=' ')
else:
print(i,end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){printf("FizzBuzz ");}
else if(i%5==0){printf("Buzz ");}
else if(i%3==0){printf("Fizz ");}
else{printf("%d ",i);}
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a 2D matrix of size [M, N], Q number of queries. In each query, you will be given a number X to check whether it is present in the matrix or not.The first line contains three integers M(number of rows), N(Number of columns), and Q(number of queries)
Next M lines contain N integers which are the elements of the matrix.
Next, Q lines will contain a single integer X.
Constraints:-
1<=M,N<=1000
1<=Q<=10000
1<=X, Arr[i]<=1000000000For each query, in a new line print "Yes" if the element is present in matrix or print "No" if the element is absent.Input:-
3 3 2
1 2 3
5 6 7
8 9 10
7
11
Output:-
Yes
No
Input:-
3 4 4
4 8 11 14
15 54 45 47
1 2 3 4
5
15
45
26
Output:-
No
Yes
Yes
No, I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int q = sc.nextInt();
int mat[] = new int[m*n];
int matSize = m*n;
for(int i = 0; i < m*n; i++)
{
int ele = sc.nextInt();
mat[i] = ele;
}
Arrays.sort(mat);
for(int i = 1; i <= q; i++)
{
int qs = sc.nextInt();
System.out.println(isPresent(mat, matSize, qs));
}
}
static String isPresent(int mat[], int size, int ele)
{
int l = 0, h = size-1;
while(l <= h)
{
int mid = l + (h-l)/2;
if(mat[mid] == ele)
return "Yes";
else if(mat[mid] > ele)
h = mid - 1;
else l = mid+1;
}
return "No";
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a 2D matrix of size [M, N], Q number of queries. In each query, you will be given a number X to check whether it is present in the matrix or not.The first line contains three integers M(number of rows), N(Number of columns), and Q(number of queries)
Next M lines contain N integers which are the elements of the matrix.
Next, Q lines will contain a single integer X.
Constraints:-
1<=M,N<=1000
1<=Q<=10000
1<=X, Arr[i]<=1000000000For each query, in a new line print "Yes" if the element is present in matrix or print "No" if the element is absent.Input:-
3 3 2
1 2 3
5 6 7
8 9 10
7
11
Output:-
Yes
No
Input:-
3 4 4
4 8 11 14
15 54 45 47
1 2 3 4
5
15
45
26
Output:-
No
Yes
Yes
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define N 1000000
long a[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,q;
cin>>n>>m>>q;
n=n*m;
long long sum=0,sum1=0;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
while(q--){
long x;
cin>>x;
int l=0;
int r=n-1;
while (r >= l) {
int mid = l + (r - l) / 2;
if (a[mid] == x) {
cout<<"Yes"<<endl;goto f;}
if (a[mid] > x)
{
r=mid-1;
}
else {l=mid+1;
}
}
cout<<"No"<<endl;
f:;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement the function <code>round</code>, which should take a number which can be a float(decimal)
and return its result as an integer rounded of (Use JS In built functions)Function will take a float as input (can be negative or positive)Function will return a rounded off numberconsole. log(round(1.112)) // prints 1
console. log(round(1.9)) // prints 2
console. log(round(-0.66)) // prints -1, I have written this Solution Code: function round(num){
// write code here
// return the output , do not use console.log here
return Math.round(num)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement the function <code>round</code>, which should take a number which can be a float(decimal)
and return its result as an integer rounded of (Use JS In built functions)Function will take a float as input (can be negative or positive)Function will return a rounded off numberconsole. log(round(1.112)) // prints 1
console. log(round(1.9)) // prints 2
console. log(round(-0.66)) // prints -1, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.math.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
double n=sc.nextDouble();
System.out.println(Math.round(n));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Let's assume some functional definitions for this problem.
We take prime(x) as the set of all prime divisors of x. For example, prime(140)={2,5,7}, prime(169)={13}.
Let f(x,p) be the maximum possible integer p**k where k is an integer such that x is divisible by p**k.
(Here a**b means a raised to the power b or pow(a, b))
For example:
f(99,3)=9 (99 is divisible by 3**2=9 but not divisible by 3**3=27),
f(63,7)=7 (63 is divisible by 7**1=7 but not divisible by 7**2=49).
Let g(x,y) be the product of f(y,p) for all p in prime(x).
For example:
g(30,70)=f(70,2)*f(70,3)*f(70,5)=2*1*5=10,
g(525,63)=f(63,3)*f(63,5)*f(63,7)=9*1*7=63.
You are given two integers x and n. Calculate g(x,1)*g(x,2)*…*g(x,n) mod (1000000007).
(Read modulo exponentiation before attempting this problem)The only line contains integers x and n — the numbers used in formula.
Constraints
2 ≤ x ≤ 1000000000
1 ≤ n ≤ 1000000000000000000Print the answer corresponding to the input.Sample Input 1
10 2
Sample Output 1
2
Sample Input 2
20190929 1605
Sample Output 2
363165664
Explanation
In the first example, g(10,1)=f(1,2)⋅f(1,5)=1, g(10,2)=f(2,2)⋅f(2,5)=2., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static long mod =1000000007;
public static boolean isPrime(long m){
if (m <2)
return false;
for(int i =2 ;i*i<=m;i++)
{
if (m%i == 0)
return false;
}
return true;
}
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s [] =br.readLine().trim().split(" ");
long x = Long.parseLong(s[0]);
long n = Long.parseLong(s[1]);
long ans = 1;
for(int i = 2; i*i <= x; i++){
if(x%i != 0) continue;
ans = (ans*f(n, i)) % mod;
while(x%i == 0)
x /= i;
}
if(x > 1)
ans = (ans*f(n, x)) % mod;
System.out.println(ans);
}
static long f(long n, long p){
long ans = 1;
long cur = 1;
while(cur <= n/p){
cur = cur*p;
long z = power(p, n/cur);
ans = (ans*z) % mod;
}
return ans;
}
public static long power(long no,long pow){
long p = 1000000007;
long result = 1;
while(pow > 0)
{
if ( (pow & 1) == 1)
result = ((result%p) * (no%p))%p;
no = ((no%p) * (no%p))%p;
pow >>= 1;
}
return result;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Let's assume some functional definitions for this problem.
We take prime(x) as the set of all prime divisors of x. For example, prime(140)={2,5,7}, prime(169)={13}.
Let f(x,p) be the maximum possible integer p**k where k is an integer such that x is divisible by p**k.
(Here a**b means a raised to the power b or pow(a, b))
For example:
f(99,3)=9 (99 is divisible by 3**2=9 but not divisible by 3**3=27),
f(63,7)=7 (63 is divisible by 7**1=7 but not divisible by 7**2=49).
Let g(x,y) be the product of f(y,p) for all p in prime(x).
For example:
g(30,70)=f(70,2)*f(70,3)*f(70,5)=2*1*5=10,
g(525,63)=f(63,3)*f(63,5)*f(63,7)=9*1*7=63.
You are given two integers x and n. Calculate g(x,1)*g(x,2)*…*g(x,n) mod (1000000007).
(Read modulo exponentiation before attempting this problem)The only line contains integers x and n — the numbers used in formula.
Constraints
2 ≤ x ≤ 1000000000
1 ≤ n ≤ 1000000000000000000Print the answer corresponding to the input.Sample Input 1
10 2
Sample Output 1
2
Sample Input 2
20190929 1605
Sample Output 2
363165664
Explanation
In the first example, g(10,1)=f(1,2)⋅f(1,5)=1, g(10,2)=f(2,2)⋅f(2,5)=2., I have written this Solution Code: import math
mod = 1000000007
def modExpo(x, n):
if n <= 0:
return 1
if n % 2 == 0:
return modExpo((x * x) % mod, n // 2)
return (x * modExpo((x * x) % mod, (n - 1) // 2)) % mod
def calc(n, p):
prod = 1
pPow = 1
while pPow <= (n // p):
pPow *= p
add = 0
while pPow != 1:
quo = n // pPow
quo -= add
power = modExpo(pPow, quo)
prod = (prod * power) % mod
add += quo
pPow //= p
return prod
x, n = map(int, input().split())
res = 1
i = 2
while (i * i) <= x:
if x % i == 0:
res = (res * calc(n, i)) % mod
while x % i == 0:
x //= i
i += 1
if x > 1:
res = (res * calc(n, x)) % mod
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Let's assume some functional definitions for this problem.
We take prime(x) as the set of all prime divisors of x. For example, prime(140)={2,5,7}, prime(169)={13}.
Let f(x,p) be the maximum possible integer p**k where k is an integer such that x is divisible by p**k.
(Here a**b means a raised to the power b or pow(a, b))
For example:
f(99,3)=9 (99 is divisible by 3**2=9 but not divisible by 3**3=27),
f(63,7)=7 (63 is divisible by 7**1=7 but not divisible by 7**2=49).
Let g(x,y) be the product of f(y,p) for all p in prime(x).
For example:
g(30,70)=f(70,2)*f(70,3)*f(70,5)=2*1*5=10,
g(525,63)=f(63,3)*f(63,5)*f(63,7)=9*1*7=63.
You are given two integers x and n. Calculate g(x,1)*g(x,2)*…*g(x,n) mod (1000000007).
(Read modulo exponentiation before attempting this problem)The only line contains integers x and n — the numbers used in formula.
Constraints
2 ≤ x ≤ 1000000000
1 ≤ n ≤ 1000000000000000000Print the answer corresponding to the input.Sample Input 1
10 2
Sample Output 1
2
Sample Input 2
20190929 1605
Sample Output 2
363165664
Explanation
In the first example, g(10,1)=f(1,2)⋅f(1,5)=1, g(10,2)=f(2,2)⋅f(2,5)=2., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int power(int a, int b){
int ans = 1;
b %= (mod-1);
while(b){
if(b&1)
ans = (ans*a) % mod;
b >>= 1;
a = (a*a) % mod;
}
return ans;
}
int f(int n, int p){
int ans = 1;
int cur = 1;
while(cur <= n/p){
cur = cur*p;
int z = power(p, n/cur);
ans = (ans*z) % mod;
}
return ans;
}
signed main() {
IOS;
int x, n, ans = 1;
cin >> x >> n;
for(int i = 2; i*i <= x; i++){
if(x%i != 0) continue;
ans = (ans*f(n, i)) % mod;
while(x%i == 0)
x /= i;
}
if(x > 1)
ans = (ans*f(n, x)) % mod;
cout << ans;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: def getMissingNo(arr, n):
total = (n+1)*(n)//2
sum_of_A = sum(arr)
return total - sum_of_A
N = int(input())
arr = list(map(int,input().split()))
one = getMissingNo(arr,N)
print(one), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
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();
int a[] = new int[n-1];
for(int i=0;i<n-1;i++){
a[i]=sc.nextInt();
}
boolean present = false;
for(int i=1;i<=n;i++){
present=false;
for(int j=0;j<n-1;j++){
if(a[j]==i){present=true;}
}
if(present==false){
System.out.print(i);
return;
}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++){
cin>>a[i];
}
sort(a,a+n-1);
for(int i=1;i<n;i++){
if(i!=a[i-1]){cout<<i<<endl;return 0;}
}
cout<<n;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string. Find out the distinct alphabets and the number of times they occur.The input contains a single string S.
Constraints:-
1 <= |S| <= 100000
Note:- String will contain only lowercase characters and spaces.Print 26 space separated numbers that denote the number of occurrences of each character from 'a' to 'z'.Sample Input:-
newton school
Sample Output:-
0 0 1 0 1 0 0 1 0 0 0 1 0 2 3 0 0 0 1 1 0 0 1 0 0 0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main{
public static void distinctAlphabet(String str){
int n=str.length();
int count[]=new int[26];
for(int i=0; i<n;i++){
if(str.charAt(i)!=' '){
count[str.charAt(i)-'a']++;
}
else if(str.charAt(i)==' '){
continue;
}
}
for(int i=0;i<26;i++){
System.out.print(count[i]+" ");
}
}
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
distinctAlphabet(s);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string. Find out the distinct alphabets and the number of times they occur.The input contains a single string S.
Constraints:-
1 <= |S| <= 100000
Note:- String will contain only lowercase characters and spaces.Print 26 space separated numbers that denote the number of occurrences of each character from 'a' to 'z'.Sample Input:-
newton school
Sample Output:-
0 0 1 0 1 0 0 1 0 0 0 1 0 2 3 0 0 0 1 1 0 0 1 0 0 0, I have written this Solution Code: #include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
string s;
getline(cin,s);
int a[26]={0};
for(int i=0;i<s.length();i++){
if(s[i]!=' '){
a[s[i]-'a']++;
}
}
for(int i=0;i<26;i++){
cout<<a[i]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string. Find out the distinct alphabets and the number of times they occur.The input contains a single string S.
Constraints:-
1 <= |S| <= 100000
Note:- String will contain only lowercase characters and spaces.Print 26 space separated numbers that denote the number of occurrences of each character from 'a' to 'z'.Sample Input:-
newton school
Sample Output:-
0 0 1 0 1 0 0 1 0 0 0 1 0 2 3 0 0 0 1 1 0 0 1 0 0 0, I have written this Solution Code: from collections import defaultdict
st=input()
d=defaultdict(int)
for i in st:
d[i]+=1
alpha="abcdefghijklmnopqrstuvwxyz"
for i in alpha:
print(d[i],end=" ")
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: n=int(input())
for i in range(1,n+1):
if i%3==0 and i%5==0:
print("NewtonSchool",end=" ")
elif i%3==0:
print("Newton",end=" ")
elif i%5==0:
print("School",end=" ")
else:
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
static void NewtonSchool(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("NewtonSchool ");}
else if(i%5==0){System.out.print("School ");}
else if(i%3==0){System.out.print("Newton ");}
else{System.out.print(i+" ");}
}
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
NewtonSchool(x);
}
}, 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.