Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Bob and Alice are playing a game with the following rules:
Initially, they have an integer sequence A1, A2, A3., An in addition, Bob has a lucky number
a and Alice has a lucky number b.
The players alternate turns. In each turn, the current player must remove a non- zero number of elements from the sequence; each removed element should be a multiple of the lucky number of this player.
If it is impossible to remove any elements, the current player loses the game.
It is clear that one player wins the game after a finite number of turns.
Find the winner of the game if Bob plays first and both Bob and Alice play optimally.First Line contains N , the Lucky Number of Bob and the Lucky Number of Alice
Second line contains a list of integersPrint a single line containing the string "ALICE" if the winner is Alice or "BOB" if the winner is Bob
(without quotes).Input :
5 3 2
1 2 3 4 5
Output : Alice
Bob removes 3 and the sequence becomes [1, 2, 4, 5].
Then, Alice removes 2 and the sequence becomes [1, 4, 5].
Now, Bob is left with no moves, so Alice is the winner., I have written this Solution Code: def luckyNumberGame(nums, a, b):
bobMoves = aliceMoves = commonMoves = 0
for num in nums:
if num%a == 0 and num%b == 0:
commonMoves += 1
elif num%a == 0:
bobMoves += 1
elif num%b == 0:
aliceMoves += 1
if commonMoves:
bobMoves += 1
if bobMoves > aliceMoves:
return 'BOB'
else:
return 'ALICE'
, 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 a right-angle triangle pattern of consecutive numbers of height n.<b>User Task:</b>
Take only one user input <b>n</b> the height of right angle triangle.
Constraint:
1 ≤ n ≤100
Print 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: import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int num = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(num + " ");
num++;
}
num=1;
System.out.println();
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two numbers m and n, multiply them using only "addition" operations.<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>Multiply()</b> that takes the integer M and N as a parameter.
Constraints:
1 ≤ T ≤ 100
0 ≤ M, N ≤ 100Return the product of N and M.Sample Input
2
2 3
3 4
Sample Output
6
12, I have written this Solution Code: static int Multiply(int n, int m)
{
if(n==0 || m==0){return 0;}
if (m == 1)
{ return n;}
return n + Multiply(n,m-1);
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two numbers m and n, multiply them using only "addition" operations.<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>Multiply()</b> that takes the integer M and N as a parameter.
Constraints:
1 ≤ T ≤ 100
0 ≤ M, N ≤ 100Return the product of N and M.Sample Input
2
2 3
3 4
Sample Output
6
12, I have written this Solution Code: def multiply_by_recursion(n,m):
# Base Case
if n==0 or m==0:
return 0
# Recursive Case
if m==1:
return n
return n + multiply_by_recursion(n,m-1)
# Driver Code
t=int(input())
while t>0:
l=list(map(int,input().strip().split()))
n=l[0]
m=l[1]
print(multiply_by_recursion(n,m))
t=t-1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A long queue of people are waiting in front of ATMs because of the demonetization initiative. People arrive in groups to withdraw money due to the daily withdrawal limit per person. Groups come one by one and line up behind the already present queue. The way the groupings organize themselves is peculiar. The individuals in a given group arrange themselves in ascending order of height (not necessarily strictly increasing).
Sam notices a long queue standing in front of the nearby ATM. He is a curious child and wants to count all of the groups standing in line to withdraw money. Since groups are positioned behind one another, it is impossible to distinguish between them and provide an accurate count. Can you tell him the minimum number of groups that can be observed in the queue?The first line of input contains one positive integer N. The second line contains N space- separated integers H[i] denoting the height of i- th person. Each group has group members standing in increasing order of their height.
<b>Constraints</b>
1 ≤ N ≤ 1,000,000
1 ≤ H[i] ≤ 1,000,000Print the minimum number of groups that are at least present in the queue.Sample Input
4
1 2 3 4
Sample Output
1, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n ;
cin>>n;
int h[n];
for(int i =0 ; i<n ; i++){
cin>>h[i];
}
int ans = 1;
for(int i=1 ; i<n ; i++){
if(h[i]>=h[i-1]){
continue;
}
else{
ans++;
}
}
cout<<ans;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A long queue of people are waiting in front of ATMs because of the demonetization initiative. People arrive in groups to withdraw money due to the daily withdrawal limit per person. Groups come one by one and line up behind the already present queue. The way the groupings organize themselves is peculiar. The individuals in a given group arrange themselves in ascending order of height (not necessarily strictly increasing).
Sam notices a long queue standing in front of the nearby ATM. He is a curious child and wants to count all of the groups standing in line to withdraw money. Since groups are positioned behind one another, it is impossible to distinguish between them and provide an accurate count. Can you tell him the minimum number of groups that can be observed in the queue?The first line of input contains one positive integer N. The second line contains N space- separated integers H[i] denoting the height of i- th person. Each group has group members standing in increasing order of their height.
<b>Constraints</b>
1 ≤ N ≤ 1,000,000
1 ≤ H[i] ≤ 1,000,000Print the minimum number of groups that are at least present in the queue.Sample Input
4
1 2 3 4
Sample Output
1, I have written this Solution Code: import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Main {
public static void main(String args[] ) throws Exception {
//BufferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String arr[] = br.readLine().split(" ");
int current = Integer.parseInt(arr[0]);
int count = 1;
for(int i=1;i<n;i++) {
if(current > Integer.parseInt(arr[i])) {
count+=1;
}
current = Integer.parseInt(arr[i]);
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it.
Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>.
Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j.
Find the minimum distance from city 1 to all the cities i (1 ≤ i ≤ n). If there exists no way to go from city 1 to city i, print -1.
<b>Note: </b>
All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively.
The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w.
<b>Constraints:</b>
1 ≤ n ≤ 3000
0 ≤ m ≤ 10000
1 ≤ x, y ≤ n
1 ≤ w ≤ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input
6 5
2 4 3
2 3 4
2 1 2
2 5 6
1 5 2
Sample Output
0
2
10
8
2
-1
Explanation:
Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10
Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2
There doesn't exist any path from 1 to 6 so print -1
, I have written this Solution Code:
import sys
from collections import defaultdict
from heapq import heappush, heappop
n, m = map(int, input().split())
d = defaultdict(list)
dist = [sys.maxsize]*n
dist[0] = 0
for _ in range(m):
start, dest, wt = map(int, input().split())
d[start-1].append((dest-1, wt))
d[dest-1].append((start-1, wt))
heap = [(0, 0, 0)]
while heap:
count, cost, u= heappop(heap)
for vertex, weight in d[u]:
if dist[vertex] > cost + weight*(count+1):
dist[vertex] = cost + weight*(count+1)
heappush(heap, (count+1, dist[vertex], vertex))
for d in dist:
if d == sys.maxsize:
print(-1)
else:
print(d), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it.
Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>.
Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j.
Find the minimum distance from city 1 to all the cities i (1 ≤ i ≤ n). If there exists no way to go from city 1 to city i, print -1.
<b>Note: </b>
All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively.
The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w.
<b>Constraints:</b>
1 ≤ n ≤ 3000
0 ≤ m ≤ 10000
1 ≤ x, y ≤ n
1 ≤ w ≤ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input
6 5
2 4 3
2 3 4
2 1 2
2 5 6
1 5 2
Sample Output
0
2
10
8
2
-1
Explanation:
Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10
Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2
There doesn't exist any path from 1 to 6 so print -1
, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF =1e18;
vector<tuple<int, int, int>> adj;
void solve()
{
int n, m;
cin>>n>>m;
// assert(1<=n && n<=3000);
// assert(0<=m && m<=10000);
adj.resize(n);
for(int i = 0;i<m;i++)
{
int x, y, w;
cin>>x>>y>>w;
x--;
y--;
// assert(0<=x && x<n);
// assert(0<=y && y<n);
// assert(1<=w && w<=1e9);
adj.push_back({x, y, w});
adj.push_back({y, x, w});
}
vector<int> dp_old(n, INF);
vector<int> dp_new(n, INF);
dp_old[0] = 0;
for(int i = 1;i<=n;i++)
{
fill(dp_new.begin(), dp_new.end(), INF);
for(auto [x, y,w]:adj)
{
dp_new[y]= min({dp_new[y], dp_old[x] + i * w});
}
for(int j = 0;j<n;j++)
dp_new[j] = min(dp_new[j], dp_old[j]);
swap(dp_new, dp_old);
}
for(int i = 0;i<n;i++)
{
if(dp_old[i] == INF)
dp_old[i] = -1;
cout<<dp_old[i]<<"\n";
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
}
#endif
solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it.
Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>.
Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j.
Find the minimum distance from city 1 to all the cities i (1 ≤ i ≤ n). If there exists no way to go from city 1 to city i, print -1.
<b>Note: </b>
All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively.
The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w.
<b>Constraints:</b>
1 ≤ n ≤ 3000
0 ≤ m ≤ 10000
1 ≤ x, y ≤ n
1 ≤ w ≤ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input
6 5
2 4 3
2 3 4
2 1 2
2 5 6
1 5 2
Sample Output
0
2
10
8
2
-1
Explanation:
Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10
Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2
There doesn't exist any path from 1 to 6 so print -1
, I have written this Solution Code: import java.io.*;import java.util.*;import java.math.*;import static java.lang.Math.*;import static java.
util.Map.*;import static java.util.Arrays.*;import static java.util.Collections.*;
import static java.lang.System.*;
public class Main
{
public void tq()throws Exception
{
st=new StringTokenizer(bq.readLine());
int tq=1;
sb=new StringBuilder(2000000);
o:
while(tq-->0)
{
int n=i();
int m=i();
LinkedList<int[]> l[]=new LinkedList[n];
for(int x=0;x<n;x++)l[x]=new LinkedList<>();
for(int x=0;x<m;x++)
{
int a=i()-1;
int b=i()-1;
int c=i();
l[a].add(new int[]{b,c});
l[b].add(new int[]{a,c});
}
long d[]=new long[n];
for(int x=0;x<n;x++)d[x]=maxl;
d[0]=0l;
PriorityQueue<long[]> p=new PriorityQueue<>(5000,(a,b)->a[2]-b[2]<1l?-1:1);
p.add(new long[]{0l,0,0});
while(p.size()>0)
{
long r[]=p.poll();
long di=r[0];
int no=(int)r[1];
long mu=r[2];
for(int e[]:l[no])
{
int node=e[0];
int w=e[1];
long de=di+w*(mu+1);
if(d[node]>de)
{
d[node]=de;
p.add(new long[]{de,node,mu+1});
}
}
}
for(long x:d)
{
sl(x==maxl?-1:x);
}
}
p(sb);
}
int di[][]={{-1,0},{1,0},{0,-1},{0,1}};
int de[][]={{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{1,1},{-1,1},{1,-1}};
long mod=1000000007l;int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;long maxl=Long.MAX_VALUE, minl=Long.
MIN_VALUE;BufferedReader bq=new BufferedReader(new InputStreamReader(in));StringTokenizer st;
StringBuilder sb;public static void main(String[] a)throws Exception{new Main().tq();}int[] so(int ar[])
{Integer r[]=new Integer[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length;
x++)ar[x]=r[x];return ar;}long[] so(long ar[]){Long r[]=new Long[ar.length];for(int x=0;x<ar.length;x++)
r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
char[] so(char ar[]) {Character
r[]=new Character[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++)
ar[x]=r[x];return ar;}void s(String s){sb.append(s);}void s(int s){sb.append(s);}void s(long s){sb.
append(s);}void s(char s){sb.append(s);}void s(double s){sb.append(s);}void ss(){sb.append(' ');}void sl
(String s){sb.append(s);sb.append("\n");}void sl(int s){sb.append(s);sb.append("\n");}void sl(long s){sb
.append(s);sb.append("\n");}void sl(char s) {sb.append(s);sb.append("\n");}void sl(double s){sb.append(s)
;sb.append("\n");}void sl(){sb.append("\n");}int l(int v){return 31-Integer.numberOfLeadingZeros(v);}
long l(long v){return 63-Long.numberOfLeadingZeros(v);}int sq(int a){return (int)sqrt(a);}long sq(long a)
{return (long)sqrt(a);}long gcd(long a,long b){while(b>0l){long c=a%b;a=b;b=c;}return a;}int gcd(int a,int b)
{while(b>0){int c=a%b;a=b;b=c;}return a;}boolean pa(String s,int i,int j){while(i<j)if(s.charAt(i++)!=
s.charAt(j--))return false;return true;}boolean[] si(int n) {boolean bo[]=new boolean[n+1];bo[0]=true;bo[1]
=true;for(int x=4;x<=n;x+=2)bo[x]=true;for(int x=3;x*x<=n;x+=2){if(!bo[x]){int vv=(x<<1);for(int y=x*x;y<=n;
y+=vv)bo[y]=true;}}return bo;}long mul(long a,long b,long m) {long r=1l;a%=m;while(b>0){if((b&1)==1)
r=(r*a)%m;b>>=1;a=(a*a)%m;}return r;}int i()throws IOException{if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());return Integer.parseInt(st.nextToken());}long l()throws IOException
{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Long.parseLong(st.nextToken());}String
s()throws IOException {if (!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return st.nextToken();}
double d()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Double.
parseDouble(st.nextToken());}void p(Object p){out.print(p);}void p(String p){out.print(p);}void p(int p)
{out.print(p);}void p(double p){out.print(p);}void p(long p){out.print(p);}void p(char p){out.print(p);}void
p(boolean p){out.print(p);}void pl(Object p){out.println(p);}void pl(String p){out.println(p);}void pl(int p)
{out.println(p);}void pl(char p){out.println(p);}void pl(double p){out.println(p);}void pl(long p){out.
println(p);}void pl(boolean p)
{out.println(p);}void pl(){out.println();}void s(int a[]){for(int e:a)
{sb.append(e);sb.append(' ');}sb.append("\n");}
void s(long a[])
{for(long e:a){sb.append(e);sb.append(' ')
;}sb.append("\n");}void s(int ar[][]){for(int a[]:ar){for(int e:a){sb.append(e);sb.append(' ');}sb.append
("\n");}}
void s(char a[])
{for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}void s(char ar[][])
{for(char a[]:ar){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}int[] ari(int n)throws
IOException {int ar[]=new int[n];if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());for(int x=0;
x<n;x++)ar[x]=Integer.parseInt(st.nextToken());return ar;}int[][] ari(int n,int m)throws
IOException {int ar[][]=new int[n][m];for(int x=0;x<n;x++){if (!st.hasMoreTokens())st=new StringTokenizer
(bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());}return ar;}long[] arl
(int n)throws IOException {long ar[]=new long[n];if(!st.hasMoreTokens()) st=new StringTokenizer(bq.readLine())
;for(int x=0;x<n;x++)ar[x]=Long.parseLong(st.nextToken());return ar;}long[][] arl(int n,int m)throws
IOException {long ar[][]=new long[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens()) st=new
StringTokenizer(bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());}return ar;}
String[] ars(int n)throws IOException {String ar[] =new String[n];if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken();return ar;}double[] ard
(int n)throws IOException {double ar[] =new double[n];if(!st.hasMoreTokens())st=new StringTokenizer
(bq.readLine());for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());return ar;}double[][] ard
(int n,int m)throws IOException{double ar[][]=new double[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens())
st=new StringTokenizer(bq.readLine());for(int y=0;y<m;y++) ar[x][y]=Double.parseDouble(st.nextToken());}
return ar;}char[] arc(int n)throws IOException{char ar[]=new char[n];if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);return ar;}char[][]
arc(int n,int m)throws IOException {char ar[][]=new char[n][m];for(int x=0;x<n;x++){String s=bq.readLine();
for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);}return ar;}void p(int ar[])
{StringBuilder sb=new StringBuilder
(2*ar.length);for(int a:ar){sb.append(a);sb.append(' ');}out.println(sb);}void p(int ar[][])
{StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(int a[]:ar){for(int aa:a){sb.append(aa);
sb.append(' ');}sb.append("\n");}p(sb);}void p(long ar[]){StringBuilder sb=new StringBuilder
(2*ar.length);for(long a:ar){ sb.append(a);sb.append(' ');}out.println(sb);}
void p(long ar[][])
{StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(long a[]:ar){for(long aa:a){sb.append(aa);
sb.append(' ');}sb.append("\n");}p(sb);}void p(String ar[]){int c=0;for(String s:ar)c+=s.length()+1;
StringBuilder sb=new StringBuilder(c);for(String a:ar){sb.append(a);sb.append(' ');}out.println(sb);}
void p(double ar[])
{StringBuilder sb=new StringBuilder(2*ar.length);for(double a:ar){sb.append(a);
sb.append(' ');}out.println(sb);}void p
(double ar[][]){StringBuilder sb=new StringBuilder(2*
ar.length*ar[0].length);for(double a[]:ar){for(double aa:a){sb.append(aa);sb.append(' ');}sb.append("\n")
;}p(sb);}void p(char ar[])
{StringBuilder sb=new StringBuilder(2*ar.length);for(char aa:ar){sb.append(aa);
sb.append(' ');}out.println(sb);}void p(char ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0]
.length);for(char a[]:ar){for(char aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: n = int(input())
if (n%4==0 and n%100!=0 or n%400==0):
print("YES")
elif 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 a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int n = scanner.nextInt();
LeapYear(n);
}
static void LeapYear(int year){
if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");}
else {
System.out.println("NO");}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers. Find the xor_value of the array.
xor_value of an array is the xor of all the elements if the ith element is taken i number of times (1 based indexing).
For example xor_value of array [2, 3, 1, 4] = 2 xor 3 xor 3 xor 1 xor 1 xor 1 xor 4 xor 4 xor 4 xor 4 = 3.First line of input contains N.
Second line of input contains N space seperated integers, representing the elements of the array.
Constraints
1 <= N <= 100000
1 <= Arr[i] <= 100000Print a single integer, the xor_value of the array.Sample input
4
2 3 1 4
Sample output
3
Sample Input
5
2 7 10 2 10
Sample Output
2, I have written this Solution Code: a = int(input())
arr = list(map(int, input().split()))
if len(arr) == 1:
print(arr[0])
else:
answer = arr[0]
for i in range(1, len(arr), 1):
if(i%2 == 0):
answer ^= arr[i]
else:
answer ^= arr[i]
answer ^= arr[i]
print(answer), 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. Find the xor_value of the array.
xor_value of an array is the xor of all the elements if the ith element is taken i number of times (1 based indexing).
For example xor_value of array [2, 3, 1, 4] = 2 xor 3 xor 3 xor 1 xor 1 xor 1 xor 4 xor 4 xor 4 xor 4 = 3.First line of input contains N.
Second line of input contains N space seperated integers, representing the elements of the array.
Constraints
1 <= N <= 100000
1 <= Arr[i] <= 100000Print a single integer, the xor_value of the array.Sample input
4
2 3 1 4
Sample output
3
Sample Input
5
2 7 10 2 10
Sample Output
2, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int ans=0;
for(int i=1;i<=n;++i)
{
int d;
cin>>d;
if(i%2==1)
ans^=d;
}
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers. Find the xor_value of the array.
xor_value of an array is the xor of all the elements if the ith element is taken i number of times (1 based indexing).
For example xor_value of array [2, 3, 1, 4] = 2 xor 3 xor 3 xor 1 xor 1 xor 1 xor 4 xor 4 xor 4 xor 4 = 3.First line of input contains N.
Second line of input contains N space seperated integers, representing the elements of the array.
Constraints
1 <= N <= 100000
1 <= Arr[i] <= 100000Print a single integer, the xor_value of the array.Sample input
4
2 3 1 4
Sample output
3
Sample Input
5
2 7 10 2 10
Sample Output
2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ;
int n = Integer.parseInt(br.readLine()) ;
String[] arr = br.readLine().split(" ") ;
int ans = 0 ;
for(int i=0; i<n; i += 2){
ans ^= Integer.parseInt(arr[i]) ;
}
System.out.print(ans) ;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have been given a sequence A of N digits. Each digit in this sequence ranges from 1 to 10^9. You need to perform 2 types of operations on this list:
Add(x): Add element x to the end of the list.
Max(list): Find the maximum element in the current sequence.
For each query of type 2, you need to print the result of that operation.The first line consists of a single integer N denoting the size of the initial sequence. The next line consists of N space-separated integers denoting the elements of the initial sequence. The next line contains a single integer q denoting the number of queries. The next q lines contain the details of the operation. The first integer type indicates the type of query. If typei ==1, it is followed by another integer x and you need to perform an operation of type 1 else operations of type 2
Constraints
1 < = N < = 10^5
1 < = Ai < = 10^9
1 < = q < = 10^4For each operation of the second type, print a single integer on a new line.Sample Input
5
1 2 3 4 5
6
1 1
1 2
1 3
2
1 8
2
Sample Output
5
8, I have written this Solution Code: a=int(input())
lis=list(map(int,input().split()))
mNow = max(lis)
qr=int(input())
for _ in range(qr):
inp = list(map(int,input().split()))
if(inp[0]==1):
if(inp[1]>mNow):
lis.append(inp[1])
mNow = inp[1]
else:
print(mNow), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have been given a sequence A of N digits. Each digit in this sequence ranges from 1 to 10^9. You need to perform 2 types of operations on this list:
Add(x): Add element x to the end of the list.
Max(list): Find the maximum element in the current sequence.
For each query of type 2, you need to print the result of that operation.The first line consists of a single integer N denoting the size of the initial sequence. The next line consists of N space-separated integers denoting the elements of the initial sequence. The next line contains a single integer q denoting the number of queries. The next q lines contain the details of the operation. The first integer type indicates the type of query. If typei ==1, it is followed by another integer x and you need to perform an operation of type 1 else operations of type 2
Constraints
1 < = N < = 10^5
1 < = Ai < = 10^9
1 < = q < = 10^4For each operation of the second type, print a single integer on a new line.Sample Input
5
1 2 3 4 5
6
1 1
1 2
1 3
2
1 8
2
Sample Output
5
8, 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
const int N = 3e5+5;
#define read(type) readInt<type>()
#define max1 20000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;
bool isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
return power(n, p-2, p);
}
int main()
{
priority_queue<ll> q;
int n;
cin>>n;
ll x;
FOR(i,n){
cin>>x;
q.push(x);}
int qa;
cin>>qa;
int i;
while(qa--){
cin>>i;
if(i==1){
cin>>x;
q.push(x);
}
else{out(q.top());}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have been given a sequence A of N digits. Each digit in this sequence ranges from 1 to 10^9. You need to perform 2 types of operations on this list:
Add(x): Add element x to the end of the list.
Max(list): Find the maximum element in the current sequence.
For each query of type 2, you need to print the result of that operation.The first line consists of a single integer N denoting the size of the initial sequence. The next line consists of N space-separated integers denoting the elements of the initial sequence. The next line contains a single integer q denoting the number of queries. The next q lines contain the details of the operation. The first integer type indicates the type of query. If typei ==1, it is followed by another integer x and you need to perform an operation of type 1 else operations of type 2
Constraints
1 < = N < = 10^5
1 < = Ai < = 10^9
1 < = q < = 10^4For each operation of the second type, print a single integer on a new line.Sample Input
5
1 2 3 4 5
6
1 1
1 2
1 3
2
1 8
2
Sample Output
5
8, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static long mod= (long) (1e9 +7);
static InputReader s;
static PrintWriter out;
public static void main(String args[]) {
new Thread(null, new Runnable() {
public void run() {
try{
solve();
out.flush();
out.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}, "1", 1 << 26).start();
}
public static void solve() throws IOException{
s= new InputReader(System.in);
OutputStream outputStream= System.out;
out= new PrintWriter(outputStream);
PriorityQueue<Integer> q= new PriorityQueue<>(Collections.reverseOrder());
int n= s.nextInt();
for(int i=0;i<n;i++){
q.add(s.nextInt());
}
int query = s.nextInt();
while(query-->0){
int type= s.nextInt();
if(type==1){
q.add(s.nextInt());
}
else{
out.println(q.peek());
}
}
}
static long combinations(long n,long r){
if(r==0 || r==n) return 1;
r= Math.min(r, n-r);
long ans=n;
for(int i=1;i<r;i++){
ans= (ans*(n-i))%mod;
ans= (ans*modulo(i+1,mod-2,mod))%mod;
}
return ans;
}
static long modulo(long x,long y,long p)
{
long res = 1;
x = x % p;
while (y > 0)
{
if (y%2==1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
static HashSet<Integer> primeFactors(int n)
{
HashSet<Integer> arr= new HashSet<>();
while (n%2 == 0)
{
arr.add(2);
n = n/2;
}
for (int i = 3; i <= Math.sqrt(n); i = i+2)
{
while (n%i == 0)
{
arr.add(i);
n = n/i;
}
}
if (n > 2)
arr.add(n);
return arr;
}
public static long expo(long a, long b){
if (b==0)
return 1;
if (b==1)
return a;
if (b==2)
return a*a;
if (b%2==0){
return expo(expo(a,(b/2)),2);
}
else{
return a*expo(expo(a,(b-1)/2),2);
}
}
static class Pair implements Comparable<Pair>
{
String x;
String y;
Pair(String ii, String cc)
{
x=ii;
y=cc;
}
public int compareTo(Pair o)
{
return this.x.compareTo(o.x);
}
public boolean equals(Object o) {
Pair other = (Pair) o;
return x == other.x && y == other.y;
}
public String toString() {
return "[x=" + x + ", y=" + y + "]";
}
}
public static int[] sieve(int N){
int arr[]= new int[N+1];
for(int i=2;i<=Math.sqrt(N);i++){
if(arr[i]==0){
for(int j= i*i;j<= N;j= j+i){
arr[j]=1;
}
}
}
return arr;
}
static int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
public static void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
static void catalan_numbers(int n) {
long catalan[]= new long[n+1];
catalan[1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i - 1; j++) {
catalan[i] = catalan[i] + ((catalan[j]) * catalan[i - j]);
}
}
}
static final class InputReader{
private final InputStream stream;
private final byte[] buf=new byte[1024];
private int curChar;
private int Chars;
public InputReader(InputStream stream){this.stream=stream;}
private int read()throws IOException{
if(curChar>=Chars){
curChar=0;
Chars=stream.read(buf);
if(Chars<=0)
return -1;
}
return buf[curChar++];
}
public final int nextInt()throws IOException{return (int)nextLong();}
public final long nextLong()throws IOException{
int c=read();
while(isSpaceChar(c)){
c=read();
if(c==-1) throw new IOException();
}
boolean negative=false;
if(c=='-'){
negative=true;
c=read();
}
long res=0;
do{
if(c<'0'||c>'9')throw new InputMismatchException();
res*=10;
res+=(c-'0');
c=read();
}while(!isSpaceChar(c));
return negative?(-res):(res);
}
public final int[] nextIntBrray(int size)throws IOException{
int[] arr=new int[size];
for(int i=0;i<size;i++)arr[i]=nextInt();
return arr;
}
public final String next()throws IOException{
int c=read();
while(isSpaceChar(c))c=read();
StringBuilder res=new StringBuilder();
do{
res.append((char)c);
c=read();
}while(!isSpaceChar(c));
return res.toString();
}
public final String nextLine()throws IOException{
int c=read();
while(isSpaceChar(c))c=read();
StringBuilder res=new StringBuilder();
do{
res.append((char)c);
c=read();
}while(c!='\n'&&c!=-1);
return res.toString();
}
private boolean isSpaceChar(int c){
return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, 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 arrsize=sc.nextInt();
int max=0,secmax=0,thirdmax=0,j;
for(int k=0;k<arrsize;k++){
j=sc.nextInt();
if(j>max){
thirdmax=secmax;
secmax=max;
max=j;
}
else if(j>secmax){
thirdmax=secmax;
secmax=j;
}
else if(j>thirdmax){
thirdmax=j;
}
if(k%10000==0){
System.gc();
}
}
System.out.println(max+" "+secmax+" "+thirdmax+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: t=int(input())
while t>0:
t-=1
n=int(input())
l=list(map(int,input().strip().split()))
li=[0,0,0]
for i in l:
x=i
for j in range(0,3):
y=min(x,li[j])
li[j]=max(x,li[j])
x=y
print(li[0],end=" ")
print(li[1],end=" ")
print(li[2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
vector<long> a(n);
long ans[3]={0};
long x,y;
for(int i=0;i<n;i++){
cin>>a[i];
x=a[i];
for(int j=0;j<3;j++){
y=min(x,ans[j]);
ans[j]=max(x,ans[j]);
// cout<<ans[j]<<" ";
x=y;
}
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
if(ans[2]<ans[1]){
swap(ans[1],ans[2]);
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: function maxNumbers(arr,n) {
// write code here
// do not console.log the answer
// return the answer as an array of 3 numbers
return arr.sort((a,b)=>b-a).slice(0,3)
};
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a tree rooted at node 1, find the height of the tree. The height of the tree is the maximum number of edges between the root node and any node of the tree.First line contains N, the number of nodes in the tree.
N-1 lines follow containing u and v denoting an edge between node u and node v.
The input is guaranteed to be a tree.
1 <= N <= 100000
1 <= u,v <= N
u != vOutput a single integer containing the height of the tree.Sample Input
4
1 2
2 3
1 4
Sample output
2
Sample Input
3
1 2
2 3
Sample output
2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Node{
int data;
List<Node> list;
Node(int data){
list = new ArrayList<Node>();
this.data = data;
}
}
class Main {
static Node rootNode;
public static int heightOfBinaryTree(Node root , int parent){
int height = 0;
int max = 0;
for(int i = 0; i < root.list.size(); i++){
if(parent == root.list.get(i).data){
continue;
}
int temp = heightOfBinaryTree(root.list.get(i) , root.data);
max = Math.max(max , temp);
}
return max + 1;
}
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
Node arr[] = new Node[N+1];
for(int i = 1; i <= N; i++)
arr[i] = new Node(i);
for(int i = 0; i < N - 1; i++){
int u = sc.nextInt();
int v = sc.nextInt();
arr[u].list.add(arr[v]);
arr[v].list.add(arr[u]);
}
int result = heightOfBinaryTree(arr[1] , 1);
System.out.println(result - 1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a tree rooted at node 1, find the height of the tree. The height of the tree is the maximum number of edges between the root node and any node of the tree.First line contains N, the number of nodes in the tree.
N-1 lines follow containing u and v denoting an edge between node u and node v.
The input is guaranteed to be a tree.
1 <= N <= 100000
1 <= u,v <= N
u != vOutput a single integer containing the height of the tree.Sample Input
4
1 2
2 3
1 4
Sample output
2
Sample Input
3
1 2
2 3
Sample output
2, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int maxheight(vector<int> tree[], int node, bool visited[]){
int height = 0;
for(auto child: tree[node]){
if(visited[child])
continue;
visited[child] = true;
height = max(height, maxheight(tree, child, visited) + 1);
}
return height;
}
int main(){
int n;
cin>>n;
bool visited[n+1] ={0};
vector<int> tree[100001];
for(int i=0; i<n-1; i++){
int u, v;
cin>>u>>v;
tree[u].push_back(v);
tree[v].push_back(u);
}
visited[1] = true;
cout<< maxheight(tree, 1, visited)<< endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John is confused about the number of ways to propose to Olivia. So, he asked for your help. Now, you need to determine the number of ways for John to propose to Olivia.
For that, You are given an integer N and you need to count the number of pairs (x<sub>1</sub>, x<sub>2</sub>) such that x<sub>1</sub><sup>2</sup> + x<sub>2</sub><sup>2</sup> = N and x<sub>1</sub>, x<sub>2</sub> both are positive integer.The first line contains a single integer T, the number of test cases.
T lines follow. Each line describes a single test case and contains a single integer N.
<b>Constraints:</b>
1 <= T <= 100
2 <= N <= 10<sup>5</sup>For each test case, print a single integer count of such pairs.Sample Input 1:
2
13
4
Sample Output 2:
2
0, I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("popcnt")
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
using cd = complex<double>;
const double PI = acos(-1);
// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define fr first
#define sc second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout);
#define out(x) cout << ((x) ? "Yes\n" : "No\n")
#define sz(x) x.size()
typedef long long ll;
typedef long long unsigned int llu;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
void solve(){
ll n; cin >> n;
ll ans = 0;
for(ll i = 1;i*i<n;i++){
ll x = sqrt(n - i*i);
if(x*x + i*i == n){
ans++;
}
}
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// cout.tie(NULL);
#ifdef LOCALFLAG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t = 1;
cin >> t;
while(t--){
solve();
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a Doubly linked list consisting of <b>N</b> nodes and given a number <b>K</b>. The task is to delete the Kth node from the end of the linked list.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>deleteElement()</b> that takes head node and the position K as parameter.
Constraints:
1 <=K<=N<= 1000
1 <=value<= 1000Return the head of the modified Doubly linked listInput:
5 3
1 2 3 4 5
Output:
1 2 4 5
Explanation:
After deleting 3rd node from the end of the linked list, 3 will be deleted and the list will become 1, 2, 4, 5., I have written this Solution Code: public static Node deleteElement(Node head,int k) {
int cnt=0;
Node temp=head;
while(temp!=null){
cnt++;
temp=temp.next;
}
k=cnt-k;
if(k==0){head=head.next;
head.prev=null;
return head;}
temp=head;
int i=0;
while(i!=k-1){
temp=temp.next;
i++;
}
temp.next=temp.next.next;
if(k!=cnt-1){temp.next.prev=temp;}
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: import math
n = int(input())
for i in range(n):
x = int(input())
count = 0
for i in range(1, int(math.sqrt(x))+1):
if x % i == 0:
if (i%2 == 0):
count+=1
if ((x/i) %2 == 0):
count+=1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-->0){
int n = Integer.parseInt(br.readLine());
int count=0;
for(int i=1;i<=Math.sqrt(n);i++){
if(n%i == 0)
{
if(i%2==0) {
count++;
}
if(i*i != n && (n/i)%2==0) {
count++;
}
}
}
System.out.println(count);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
if(n&1){cout<<0<<endl;continue;}
long x=sqrt(n);
int cnt=0;
for(long long i=1;i<=x;i++){
if(!(n%i)){
if(!(i%2)){cnt++;}
if(i*i!=n){
if(!((n/i)%2)){cnt++;}
}
}
}
cout<<cnt<<endl;}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r.
Constraints:-
1 <= N <= 100
1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:-
4 10 4
Sample Output:-
Yes
Sample Input:-
5 10 4
Sample Output:-
No, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String a[] = br.readLine().split(" ");
double n = Integer.parseInt(a[0]);
double R = Integer.parseInt(a[1]);
double r = Integer.parseInt(a[2]);
R=R-r;
double count = 0;
double d = Math.asin(r/R);
count = Math.PI/d;
if(n<=count)
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: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r.
Constraints:-
1 <= N <= 100
1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:-
4 10 4
Sample Output:-
Yes
Sample Input:-
5 10 4
Sample Output:-
No, I have written this Solution Code: import math
arr = list(map(int, input().split()))
n = arr[0]
R = arr[1]
r = arr[2]
if(r>R or n>1 and (R-r)*math.sin(math.acos(-1.0)/n)+1e-8<r):
print("No")
else:
print("Yes"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r.
Constraints:-
1 <= N <= 100
1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:-
4 10 4
Sample Output:-
Yes
Sample Input:-
5 10 4
Sample Output:-
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
int R,r,n;
cin>>n>>R>>r;
cout<<(r>R || n>1&& (R-r)*sin(acos(-1.0)/n)+1e-8<r ?"No":"Yes");
return 0;
}
//1340
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<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 an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: static void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
System.out.print(x+4*j+" ");
}
System.out.println();
x+=6;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<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 an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: def Pattern(N):
x=0
for i in range (0,N):
for j in range (0,N):
print(x+4*j,end=' ')
print()
x = x+6
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<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 an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<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 an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: for i in range(int(input())):
n, x = map(int, input().split())
if x >= 10:
print(0)
else:
print((10-x)*(n-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n, x;
cin >> n >> x;
if(x >= 10)
cout << 0 << endl;
else
cout << (10-x)*(n-1) << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
while (T -->0){
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int p = Integer.parseInt(s[1]);
if (p<10)
System.out.println(Math.abs(n-1)*(10-p));
else System.out.println(0);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, I have written this Solution Code: import math
n=int(input())
count=0
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
if (n / i == i) :
count=count+1
else:
count=count+2
i = i + 1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
int ans = 0;
for(int i=1; i*i<n; i++){
if(n%i == 0){
ans += 2;
}
}
int nn = sqrt(n);
if(nn*nn == n) {
ans++;
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, 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);
long num = sc.nextLong();
System.out.println(possibleValues(num));
}
static int possibleValues(long num)
{
int ans = 0;
for(int i = 1; (long)i*i < num; i++)
{
if(num%i == 0)
ans += 2;
}
int nn = (int)Math.sqrt(num);
if((long)(nn*nn) == num)
ans++;
return ans;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code: static int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
def RotationPolicy(A, B):
cnt=0
for i in range (A,B+1):
if(i-1)%2!=0 and (i-1)%3!=0:
cnt=cnt+1
return cnt
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code: function RotationPolicy(a, b) {
// write code here
// do no console.log the answer
// return the output using return keyword
let count = 0
for (let i = a; i <= b; i++) {
if((i-1)%2 !== 0 && (i-1)%3 !==0){
count++
}
}
return count
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare 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>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code: class Solution {
public static int Rare(int n, int k){
while(n>0){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare 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>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code: def Rare(N,K):
while N>0:
if(N%10)%K!=0:
return 0
N=N//10
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare 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>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code:
int Rare(int n, int k){
while(n){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare 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>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code:
int Rare(int n, int k){
while(n){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an index K, return the K-th row of <a href = "https://en.wikipedia.org/wiki/Pascal%27s_triangle">Pascal’s triangle</a>.
You must print the K-th row modulo 10<sup>9</sup> + 7.
<b>The rows of Pascal's triangle are conventionally enumerated starting with row K=0 at the top (the 0th row) </b>The only line of input contains the input K.
<b>Constraints:-</b>
0 ≤ K ≤ 3000
Print k-th row of Pascal's Triangle containing k+1 integers modulo 10^9+7.Sample Input :
3
Sample Output:
1 3 3 1, 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 k = sc.nextInt();
int digit = 1;
int m = 1000000007;;
int arr[] = new int[k+1];
arr[0] = 1;
arr[1] = 1;
for(int i=2; i<=k; i++){
for(int j=i;j>=1;j--){
arr[j] += arr[j-1];
arr[j] = arr[j]%m;
}
}
for(int i=0;i<=k;i++){
System.out.print(arr[i] + " ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an index K, return the K-th row of <a href = "https://en.wikipedia.org/wiki/Pascal%27s_triangle">Pascal’s triangle</a>.
You must print the K-th row modulo 10<sup>9</sup> + 7.
<b>The rows of Pascal's triangle are conventionally enumerated starting with row K=0 at the top (the 0th row) </b>The only line of input contains the input K.
<b>Constraints:-</b>
0 ≤ K ≤ 3000
Print k-th row of Pascal's Triangle containing k+1 integers modulo 10^9+7.Sample Input :
3
Sample Output:
1 3 3 1, I have written this Solution Code: def generateNthRow (N):
prev = 1
print(prev, end = '')
for i in range(1, N + 1):
curr = (prev * (N - i + 1)) // i
print("", curr%1000000007, end = '')
prev = curr
N = int(input())
generateNthRow(N), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an index K, return the K-th row of <a href = "https://en.wikipedia.org/wiki/Pascal%27s_triangle">Pascal’s triangle</a>.
You must print the K-th row modulo 10<sup>9</sup> + 7.
<b>The rows of Pascal's triangle are conventionally enumerated starting with row K=0 at the top (the 0th row) </b>The only line of input contains the input K.
<b>Constraints:-</b>
0 ≤ K ≤ 3000
Print k-th row of Pascal's Triangle containing k+1 integers modulo 10^9+7.Sample Input :
3
Sample Output:
1 3 3 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
signed main()
{
int t,n;
t=1;
vector<vector<long long> > v(3002);
for(int i=0; i<=3001; i++)
{
for (int j=0; j<=i; j++)
{
if (j==0 || j==i) v[i].push_back(1);
else v[i].push_back((v[i-1][j]%mod + v[i-1][j-1]%mod)%mod);
}
}
while (t--)
{
cin>>n;
n=n+1;
for (int i=0; i<v[n-1].size(); i++) cout<<v[n-1][i]<<" ";
cout<<"\n";
}
return 0;
}
, 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: 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: You are given three positive integers A, B and C. If all the three integers are equal, print "Yes". Otherwise, print "No".
Note that the quotation marks are not part of the string, thus you should print your answer without the quotation marks.The input consists of three space separated integers A, B and C.
Constraints:
1 ≤ A, B, C ≤ 100Print a single word "Yes" if all the integers are equal, otherwise print "No" (without the quotes). Note that the output is case- sensitive.Sample Input 1:
1 3 1
Sample Output 1:
No
Sample Input 2:
5 5 5
Sample Output 2:
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] input = in.readLine().split(" ");
int a = Integer.parseInt(input[0]);
int b = Integer.parseInt(input[1]);
int c = Integer.parseInt(input[2]);
if(a==b && b==c && c == a) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given three positive integers A, B and C. If all the three integers are equal, print "Yes". Otherwise, print "No".
Note that the quotation marks are not part of the string, thus you should print your answer without the quotation marks.The input consists of three space separated integers A, B and C.
Constraints:
1 ≤ A, B, C ≤ 100Print a single word "Yes" if all the integers are equal, otherwise print "No" (without the quotes). Note that the output is case- sensitive.Sample Input 1:
1 3 1
Sample Output 1:
No
Sample Input 2:
5 5 5
Sample Output 2:
Yes, I have written this Solution Code: a,b,c=map(int,input().split())
if a==b and b==c:
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given three positive integers A, B and C. If all the three integers are equal, print "Yes". Otherwise, print "No".
Note that the quotation marks are not part of the string, thus you should print your answer without the quotation marks.The input consists of three space separated integers A, B and C.
Constraints:
1 ≤ A, B, C ≤ 100Print a single word "Yes" if all the integers are equal, otherwise print "No" (without the quotes). Note that the output is case- sensitive.Sample Input 1:
1 3 1
Sample Output 1:
No
Sample Input 2:
5 5 5
Sample Output 2:
Yes, I have written this Solution Code: #include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == b && b == c) 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 integer N, Count the number of ways to colour a 2*N grid using two colours, say black and white such that:
- There is at least 1 cell of each colour.
- You can travel between any two cells of the same colour by going up, down, left or right in the grid and without passing through any cell of the opposite colour. In other words, the cells of each colour must form a connected component of the grid.
Print the answer modulo 10<sup>9</sup> + 7.The first line of the input contains a single integer T, the number of test cases.
T lines follow, i<sup>th</sup> of them contains the value of N for the i<sup>th</sup> test case.
<b>Constraints</b>
1 <= T <= 10
1 <= N <= 10<sup>5</sup>Print the answer to each test case in a different line.Sample Input:
2
2
4
Sample Output:
12
56, I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <sys/resource.h>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// DEFINE STATEMENTS
const long long INF = 1e18;
const int INFINT = INT_MAX/2;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x, y) freopen(x, "r", stdin); freopen(y, "w", stdout);
#define out(x) cout << ((x) ? "YES\n" : "NO\n")
#define CASE(x, y) cout << "Case #" << x << ":" << " \n"[y]
#define start_clock() auto start_time = std::chrono::high_resolution_clock::now(); auto end_time = start_time;
#define measure() end_time = std::chrono::high_resolution_clock::now(); cerr << (end_time - start_time)/std::chrono::milliseconds(1) << "ms" << endl;
#define reset_clock() start_time = std::chrono::high_resolution_clock::now();
typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifdef LOCALY
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
// DEBUG FUNCTIONS END
// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // FOR RANDOM NUMBER GENERATION
ll mod_exp(ll a, ll b, ll c)
{
ll res=1; a=a%c;
while(b>0)
{
if(b%2==1)
res=(res*a)%c;
b/=2;
a=(a*a)%c;
}
return res;
}
ll norm(ll a,ll b)
{
return (((a = a%b) < 0) ? a + b : a);
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
g++; g--; //this line was added just to remove compiler warning
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct Graph
{
vector<vector<int>> adj;
Graph(int n): adj(n+1) {}
void add_edge(int a, int b, bool directed = false)
{
adj[a].pb(b);
if(!directed) adj[b].pb(a);
}
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for(int i=0; i<t; i++) {
long long n;
cin >> n;
long long answer = 2 * n * ( 2 * n - 1);
answer = norm(answer, num1);
cout << answer << "\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: a, b = list(map(int, input().split(" ")))
print(str(a <= 10 and b >= 10).lower(), end=' ')
print(str(a % 2 == 0 or b % 2 == 0).lower(), end=' ')
print(str(not a == b).lower()), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Main {
static boolean Logical_AND(int a, int b){
if(a<=10 && b>=10){
return true;}
return false;}
static boolean Logical_OR(int a, int b){
if(a%2==0 || b%2==0){
return true;}
return false;}
static boolean Logical_NOT(int a, int b){
if(a!=b){
return true;}
return false;}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
System.out.print(Logical_AND(a, b)+" ");
System.out.print(Logical_OR(a,b)+" ");
System.out.print(Logical_NOT(a,b)+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a function f(x) = ax<sup>2 </sup> + bx + c. You are given an integer P. Print the value of f(P).The first input line contains three integers a, b, c - the coefficients of the quadratic equations.
The second line contains integer P
Constraints:
0 <= a, b, c, P <= 100Print the value of f(P).Sample Input 1:
1 1 1
1
Output:
3
Explanation:
f(x) = x<sup>2 </sup> + x + 1
f(1) = 1*1 + 1 +1 = 3
Sample Input 2:
1 2 3
7
Output:
66
Explanation:
f(x) = x<sup>2</sup> + 2x + 3
f(7) = 7*7 + 2*7 + 3 = 66, I have written this Solution Code: l=list(map(int,input().strip().split()))
a=l[0]
b=l[1]
c=l[2]
if len(l)<4:
x=int(input())
else:
x=l[3]
f=a*x*x+b*x+c
print(f), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a function f(x) = ax<sup>2 </sup> + bx + c. You are given an integer P. Print the value of f(P).The first input line contains three integers a, b, c - the coefficients of the quadratic equations.
The second line contains integer P
Constraints:
0 <= a, b, c, P <= 100Print the value of f(P).Sample Input 1:
1 1 1
1
Output:
3
Explanation:
f(x) = x<sup>2 </sup> + x + 1
f(1) = 1*1 + 1 +1 = 3
Sample Input 2:
1 2 3
7
Output:
66
Explanation:
f(x) = x<sup>2</sup> + 2x + 3
f(7) = 7*7 + 2*7 + 3 = 66, I have written this Solution Code: /*package whatever //do not write package name here */
import java.io.*;
import java.util.Scanner;
class Main {
public static void main (String[] args) {
int a,b,c,d;
Scanner s = new Scanner(System.in);
a = s.nextInt();
b = s.nextInt();
c = s.nextInt();
d = s.nextInt();
System.out.println(a*d*d + b*d + c);
}
}, 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: 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 marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows:
If the percentage is >= 80 then print Grade ‘A’
If the percentage is <80 and >=60 then print Grade ‘B’
If the percentage is <60 and >=40 then print Grade ‘C’
else print Grade ‘D’The input contains 5 integers separated by spaces.
<b>Constraints:</b>
1 ≤ marks ≤ 100You need to print the grade obtained by a student.Sample Input:
75 70 80 90 100
Sample Output:
A
<b>Explanation</b>
((75+70+80+90+100)/5)*100=83%
A grade.
, I have written this Solution Code: import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.io.*;
public class Main {
static final int MOD = 1000000007;
public static void main(String args[]) throws IOException {
BufferedReader br
= new BufferedReader(new InputStreamReader(System.in));
String str[] = br.readLine().trim().split(" ");
int a = Integer.parseInt(str[0]);
int b = Integer.parseInt(str[1]);
int c = Integer.parseInt(str[2]);
int d = Integer.parseInt(str[3]);
int e = Integer.parseInt(str[4]);
System.out.println(grades(a, b, c, d, e));
}
static char grades(int a, int b, int c, int d, int e)
{
int sum = a+b+c+d+e;
int per = sum/5;
if(per >= 80)
return 'A';
else if(per >= 60)
return 'B';
else if(per >= 40)
return 'C';
else
return 'D';
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows:
If the percentage is >= 80 then print Grade ‘A’
If the percentage is <80 and >=60 then print Grade ‘B’
If the percentage is <60 and >=40 then print Grade ‘C’
else print Grade ‘D’The input contains 5 integers separated by spaces.
<b>Constraints:</b>
1 ≤ marks ≤ 100You need to print the grade obtained by a student.Sample Input:
75 70 80 90 100
Sample Output:
A
<b>Explanation</b>
((75+70+80+90+100)/5)*100=83%
A grade.
, I have written this Solution Code: li = list(map(int,input().strip().split()))
avg=0
for i in li:
avg+=i
avg=avg/5
if(avg>=80):
print("A")
elif(avg>=60 and avg<80):
print("B")
elif(avg>=40 and avg<60):
print("C")
else:
print("D"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: def compound_interest(principle, rate, time):
Amount = principle * (pow((1 + rate / 100), time))
CI = Amount - principle
print( '%.2f'%CI)
principle,rate,time=map(int, input().split())
compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: function calculateCI(P, R, T)
{
let interest = P * (Math.pow(1.0 + R/100.0, T) - 1);
return interest.toFixed(2);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int p,r,t;
cin>>p>>r>>t;
double rate= (float)r/100;
double amt = (float)p*(pow(1+rate,t));
cout << fixed << setprecision(2) << (amt - p);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s= br.readLine().split(" ");
double[] darr = new double[s.length];
for(int i=0;i<s.length;i++){
darr[i] = Double.parseDouble(s[i]);
}
double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0];
System.out.printf("%.2f",ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given four positive integers A, B, C, and D, can a rectangle have these integers as its sides?The input consists of a single line containing four space-separated integers A, B, C and D.
<b> Constraints: </b>
1 ≤ A, B, C, D ≤ 1000Output "Yes" if a rectangle is possible; otherwise, "No" (without quotes).Sample Input 1:
3 4 4 3
Sample Output 1:
Yes
Sample Explanation 1:
A rectangle is possible with 3, 4, 3, and 4 as sides in clockwise order.
Sample Input 2:
3 4 3 5
Sample Output 2:
No
Sample Explanation 2:
No rectangle can be made with these side lengths., I have written this Solution Code: #include<iostream>
using namespace std;
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
if((a==c) &&(b==d)){
cout << "Yes\n";
}else if((a==b) && (c==d)){
cout << "Yes\n";
}else if((a==d) && (b==c)){
cout << "Yes\n";
}else{
cout << "No\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a circular linked list consisting of N nodes, your task is to exchange the first and last node of the list.
<b>Note:
Examples in 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>exchangeNodes()</b> that takes head node as parameter.
Constraints:
3 <= N <= 1000
1 <= Node. data<= 1000Return the head of the modified linked list.Sample Input 1:-
3
1- >2- >3
Sample Output 1:-
3- >2- >1
Sample Input 2:-
4
1- >2- >3- >4
Sample Output 2:-
4- >2- >3- >1, I have written this Solution Code: public static Node exchangeNodes(Node head) {
Node p = head;
while (p.next.next != head)
p = p.next;
p.next.next = head.next;
head.next = p.next;
p.next = head;
head = head.next;
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the Main class. Implement the getArea() and getPerimeter() methods for the child classes Parallelogram, Rhombus, Rectangle, and Square having Abstract class Quadrilateral as a parent class.
Do not change the name of any classThe first line of input contains side1, side2 and height of the parallelogram
The second line of input contains side and height of rhombus
The third line of input contains length and height of the rectangle
The fourth line of input contains side of square
If the length of any side or height for any shape is negative, then print <b><i>Length of a side cannot be negative. Please Enter a positive integer.</b></i>"Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea()
"Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea()
"Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea()
"Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea()
Sample Input 1:
1.0 2.0 3.0
7.0 5.0
4.0 2.0
6.0
Sample Output 2:
Perimeter of Parallelogram is 6.0 and Area of Parallelogram is 3.0
Perimeter of Rhombus is 28.0 and Area of Rhombus is 35.0
Perimeter of Rectangle is 12.0 and Area of Rectangle is 8.0
Perimeter of Square is 24.0 and Area of Square is 36.0
Sample Input 2:
3.0 9.0 7.0
6.0 4.0
-1.0 5.0
8.0
Sample Output 2:
Length of a side cannot be negative. Please Enter a positive integer
, I have written this Solution Code: from abc import ABC, abstractmethod
class Quadrilateral(ABC):
def __init__(self, side1, side2, side3, side4):
self.side1, self.side2, self.side3, self.side4 = side1, side2, side3, side4
@abstractmethod
def getArea(self):
pass
def getPerimeter(self):
return (self.side1+self.side2+self.side3+self.side4)
class Parallelogram(Quadrilateral):
def __init__(self, side1, side2, height):
super().__init__(side1, side2, side1, side2)
self.heightPerpendicularToSide1 = height
def getArea(self):
return self.side1*self.heightPerpendicularToSide1
class Rhombus(Parallelogram):
def __init__(self, side, height):
super().__init__(side, side, height)
class Rectangle(Parallelogram):
def __init__(self, length, breadth):
super().__init__(length, breadth, breadth)
class Square(Rhombus):
def __init__(self, side):
super().__init__(side, side)
def main():
# Parallelogram
side1, side2, height = map(float, input().split())
# side1 = float(input())
# side2 = float(input())
# height = float(input())
parallelogram = Parallelogram(side1, side2, height)
# Rhombus
side, heightOfRhombus = map(float, input().split())
# side = float(input())
# heightOfRhombus = float(input())
rhombus = Rhombus(side, heightOfRhombus)
# Rectangle
length, breadth = map(float, input().split())
# length = float(input())
# breadth = float(input())
rectangle = Rectangle(length, breadth)
# Square
sideOfSquare = float(input())
square = Square(sideOfSquare)
if(side1 < 0 or side2 < 0 or heightOfRhombus < 0 or height < 0 or side < 0 or length < 0 or breadth < 0 or sideOfSquare < 0):
print("Length of a side cannot be negative. Please Enter a positive integer")
return
print("Perimeter of Parallelogram is",
parallelogram.getPerimeter(), "and Area of Parallelogram is", parallelogram.getArea())
print("Perimeter of Rhombus is",
rhombus.getPerimeter(), "and Area of Rhombus is", rhombus.getArea())
print("Perimeter of Rectangle is",
rectangle.getPerimeter(), "and Area of Rectangle is", rectangle.getArea())
print("Perimeter of Square is",
square.getPerimeter(), "and Area of Square is", square.getArea())
if __name__ == "__main__":
main()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the Main class. Implement the getArea() and getPerimeter() methods for the child classes Parallelogram, Rhombus, Rectangle, and Square having Abstract class Quadrilateral as a parent class.
Do not change the name of any classThe first line of input contains side1, side2 and height of the parallelogram
The second line of input contains side and height of rhombus
The third line of input contains length and height of the rectangle
The fourth line of input contains side of square
If the length of any side or height for any shape is negative, then print <b><i>Length of a side cannot be negative. Please Enter a positive integer.</b></i>"Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea()
"Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea()
"Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea()
"Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea()
Sample Input 1:
1.0 2.0 3.0
7.0 5.0
4.0 2.0
6.0
Sample Output 2:
Perimeter of Parallelogram is 6.0 and Area of Parallelogram is 3.0
Perimeter of Rhombus is 28.0 and Area of Rhombus is 35.0
Perimeter of Rectangle is 12.0 and Area of Rectangle is 8.0
Perimeter of Square is 24.0 and Area of Square is 36.0
Sample Input 2:
3.0 9.0 7.0
6.0 4.0
-1.0 5.0
8.0
Sample Output 2:
Length of a side cannot be negative. Please Enter a positive integer
, I have written this Solution Code: //Do not change the name of the class
import java.util.*;
// Do not edit the Quadrilateral class
abstract class Quadrilateral {
double side1;
double side2;
double side3;
double side4;
public Quadrilateral(double side1, double side2, double side3, double side4) {
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
this.side4 = side4;
}
protected abstract double getArea();
protected double getPerimeter() {
return (side1+side2+side3+side4);
}
}
class Parallelogram extends Quadrilateral {
double heightPerpendicularToSide1;
public Parallelogram(double side1, double side2, double height) {
super(side1, side2, side1, side2);
this.heightPerpendicularToSide1 = height;
}
public double getArea() {
return side1*heightPerpendicularToSide1;
}
}
class Rhombus extends Parallelogram {
public Rhombus(double side, double height) {
super(side, side, height);
}
}
class Rectangle extends Parallelogram {
public Rectangle(double length, double breadth) {
super(length, breadth, breadth);
}
}
class Square extends Rhombus {
public Square(double side) {
super(side, side);
}
}
// Do not edit the Main class
class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//Parallelogram
double side1 = scan.nextDouble();
double side2 = scan.nextDouble();
double height = scan.nextDouble();
Parallelogram parallelogram = new Parallelogram(side1, side2, height);
//Rhombus
double side = scan.nextDouble();
double heightOfRhombus = scan.nextDouble();
Rhombus rhombus = new Rhombus(side, heightOfRhombus);
//Rectangle
double length = scan.nextDouble();
double breadth = scan.nextDouble();
Rectangle rectangle = new Rectangle(length, breadth);
//Square
double sideOfSquare = scan.nextDouble();
Square square = new Square(sideOfSquare);
if(side1<0 || side2<0 || heightOfRhombus<0 || height<0 || side<0 || length<0 || breadth<0 || sideOfSquare<0){
System.out.println("Length of a side cannot be negative. Please Enter a positive integer");
return;
}
System.out.println("Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea());
System.out.println("Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea());
System.out.println("Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea());
System.out.println("Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea());
scan.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code: static int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
def RotationPolicy(A, B):
cnt=0
for i in range (A,B+1):
if(i-1)%2!=0 and (i-1)%3!=0:
cnt=cnt+1
return cnt
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code: function RotationPolicy(a, b) {
// write code here
// do no console.log the answer
// return the output using return keyword
let count = 0
for (let i = a; i <= b; i++) {
if((i-1)%2 !== 0 && (i-1)%3 !==0){
count++
}
}
return count
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, the task is to find the nearest greater element G[i] for every element of A[i] such that the element has index greater than i, If no such element exists, output -1.
More formally:
G[i] for an element A[i] = an element A[j] such that
j is minimum possible AND
j > i AND
A[j] > A[i]Each test case consists of two lines. The first line contains an integer N denoting the size of the array. The Second line of each test case contains N space separated positive integers denoting the values/elements in the array A.
Constraints:
1 <= N <= 10^5
1 <= Ai <= 10^9For each test case, print the next greater element for each array element separated by space in order.Sample Input
4
1 3 2 4
Sample Output
3 4 4 -1
Sample Input
4
4 3 2 1
Sample Output
-1 -1 -1 -1, I have written this Solution Code: def rightlarg(arr):
n = len(arr)
A =[None]*n
A[-1] = -1
Indx = [-1]*n
stack = []
s = 1
stack.append([arr[-1],n-1])
for i in range(n-2,-1,-1):
while s :
if stack[0][0]>arr[i] :
A[i] = stack[0][0]
Indx[i] = stack[0][1]
break
else:
stack.pop(0)
s -= 1
else:
A[i] = -1
stack.insert(0,[arr[i],i])
s += 1
for x in Indx:
#print("kjhx ",x," jhgk")
if x==-1:
print(x,end=" ")
else:
print(arr[x],end=" ")
n=int(input())
B=[int(x) for x in input().split()]
rightlarg(B), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, the task is to find the nearest greater element G[i] for every element of A[i] such that the element has index greater than i, If no such element exists, output -1.
More formally:
G[i] for an element A[i] = an element A[j] such that
j is minimum possible AND
j > i AND
A[j] > A[i]Each test case consists of two lines. The first line contains an integer N denoting the size of the array. The Second line of each test case contains N space separated positive integers denoting the values/elements in the array A.
Constraints:
1 <= N <= 10^5
1 <= Ai <= 10^9For each test case, print the next greater element for each array element separated by space in order.Sample Input
4
1 3 2 4
Sample Output
3 4 4 -1
Sample Input
4
4 3 2 1
Sample Output
-1 -1 -1 -1, 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 arr[] = new int[arrSize];
for(int i = 0; i < arrSize; i++)
arr[i] = sc.nextInt();
nextLarger(arr, arrSize);
}
static void nextLarger(int arr[], int arrSize)
{
Stack<Integer> s = new Stack<>();
int a = 0;
for(int i=arrSize-1;i>=0;i--)
{
a= arr[i];
while(!(s.empty() == true)){
if(s.peek()>a){break;}
s.pop();
}
if(s.empty() == true){arr[i]=-1;}
else{arr[i]=s.peek();}
s.push(a);
}
for(int i=0;i<arrSize;i++)
{
System.out.print(arr[i]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, the task is to find the nearest greater element G[i] for every element of A[i] such that the element has index greater than i, If no such element exists, output -1.
More formally:
G[i] for an element A[i] = an element A[j] such that
j is minimum possible AND
j > i AND
A[j] > A[i]Each test case consists of two lines. The first line contains an integer N denoting the size of the array. The Second line of each test case contains N space separated positive integers denoting the values/elements in the array A.
Constraints:
1 <= N <= 10^5
1 <= Ai <= 10^9For each test case, print the next greater element for each array element separated by space in order.Sample Input
4
1 3 2 4
Sample Output
3 4 4 -1
Sample Input
4
4 3 2 1
Sample Output
-1 -1 -1 -1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
stack <long long > s;
long long a,b[n];
for(int i=0;i<n;i++){
cin>>b[i];}
for(int i=n-1;i>=0;i--){
a=b[i];
while(!(s.empty())){
if(s.top()>a){break;}
s.pop();
}
if(s.empty()){b[i]=-1;}
else{b[i]=s.top();}
s.push(a);
}
for(int i=0;i<n;i++){
cout<<b[i]<<" ";
}
}
, 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: 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 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: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two integer arrays A and B of sizes N and M respectively. You need to modify the elements of A so that B becomes its subarray. Modifying an element means change the element to any other value.
Find the minimum number of modifications to achieve this.The first line of the input contains two integers N and M.
The second line of the input contains N space separated integers, the elements of array A.
The third line of the input contains M space separated integers, the elements of array B.
Constraints
1 <= M <= N <= 500
1 <= A[i], B[i] <= 10Output a single integer, the minimum number of modifications in A to make B its subarray.Sample Input
6 3
3 1 2 1 3 3
1 2 3
Sample Output
1
Explanation: If you modify A[4] from 1 to 3. A[2]. A[4] represents the array B, so B is its subarray.
Sample Input
10 5
3 4 5 3 4 3 1 3 5 2
1 4 4 4 3
Sample Output
3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String str[] = read.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
int m = Integer.parseInt(str[1]);
int listn[] = new int[n];
int listm[] = new int[m];
str = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
listn[i]=Integer.parseInt(str[i]);
str = read.readLine().trim().split(" ");
for(int i = 0; i < m; i++)
listm[i]=Integer.parseInt(str[i]);
int ans =m;
for(int i=0; i < n-m+1 ; i++){
int ct=0;
for(int j=0;j <m; j++){
if(listn[i+j] != listm[j]){
ct++;
}
}
ans = Math.min(ans,ct);
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two integer arrays A and B of sizes N and M respectively. You need to modify the elements of A so that B becomes its subarray. Modifying an element means change the element to any other value.
Find the minimum number of modifications to achieve this.The first line of the input contains two integers N and M.
The second line of the input contains N space separated integers, the elements of array A.
The third line of the input contains M space separated integers, the elements of array B.
Constraints
1 <= M <= N <= 500
1 <= A[i], B[i] <= 10Output a single integer, the minimum number of modifications in A to make B its subarray.Sample Input
6 3
3 1 2 1 3 3
1 2 3
Sample Output
1
Explanation: If you modify A[4] from 1 to 3. A[2]. A[4] represents the array B, so B is its subarray.
Sample Input
10 5
3 4 5 3 4 3 1 3 5 2
1 4 4 4 3
Sample Output
3, I have written this Solution Code: n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
k = 0
matched = 0
while(n-k >= m):
c = 0
for i in range(m):
if(a[k:][i] == b[i]):
c += 1
matched = max(matched,c)
k += 1
print(m-matched), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.