Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Ram has a military dog who has the special ability of hearing, He can hear frequencies starting from 70Hz to 44000Hz (both inclusive). Now Ram wants to detect some unusual sounds across him. Tell "Yes" or "No" whether his dog can detect the sound or not.First line of the input contains the value of Test cases T.
Each test case consists of a single integer X - the frequency of unusual sound in Hertz.
<b>Constraints</b>
1 β€ T β€ 10<sup>4</sup>
1 β€ X β€ 10<sup>5</sup>Print Yes or No wether his dog can detect them or not for each test case.Sample Input
3
21
453
45000
Sample Output
No
Yes
No, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t>0){
int x=s.nextInt();
boolean flag=false;
for(int i=70;i<=44000;i++){
if(x==i){
flag=true;
}
}
if(flag){
System.out.println("Yes");
}
else{
System.out.println("No");
}
t--;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram has a military dog who has the special ability of hearing, He can hear frequencies starting from 70Hz to 44000Hz (both inclusive). Now Ram wants to detect some unusual sounds across him. Tell "Yes" or "No" whether his dog can detect the sound or not.First line of the input contains the value of Test cases T.
Each test case consists of a single integer X - the frequency of unusual sound in Hertz.
<b>Constraints</b>
1 β€ T β€ 10<sup>4</sup>
1 β€ X β€ 10<sup>5</sup>Print Yes or No wether his dog can detect them or not for each test case.Sample Input
3
21
453
45000
Sample Output
No
Yes
No, I have written this Solution Code: T = int(input())
for i in range(T):
X = int(input())
if X>=70 and X<=44000:
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <b> The only difference between the easy and the tricky version is the constraint on the number of queries Q. Solving the tricky version automatically solves the easy version.</b>
You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array A.
The third line of the input contains an integer Q.
The next Q lines contain two integers L and R.
Constraints
1 <= N <= 200000
1 <= A[i] <= 1000000000
1 <= Q <= 100000
1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query modulo 10<sup>9</sup>+7.Sample Input
4
5 3 3 1
2
2 3
4 4
Sample Output
6
11
Explanation: The array A = [5, 3, 3, 1].
First Query: Sum = 5 + 1 = 6.
Second Query: Sum = 5 + 3 + 3 = 11, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main (String[] args) throws IOException {
Reader sc = new Reader();
int arrSize = sc.nextInt();
long[] arr = new long[arrSize];
for(int i = 0; i < arrSize; i++)
{
arr[i] = sc.nextLong();
}
long[] prefix = new long[arrSize];
prefix[0] = arr[0];
for(int i = 1; i < arrSize; i++)
{
long val = 1000000007;
prefix[i - 1] %= val;
long prefixSum = prefix[i - 1] + arr[i];
prefixSum %= val;
prefix[i] = prefixSum;
}
long[] suffix = new long[arrSize];
suffix[arrSize - 1] = arr[arrSize - 1];
for(int i = arrSize - 2; i >= 0; i--)
{
long val = 1000000007;
suffix[i + 1] %= val;
long suffixSum = suffix[i + 1] + arr[i];
suffixSum %= val;
suffix[i] = suffixSum;
}
int query = sc.nextInt();
for(int x = 1; x <= query; x++)
{
int l = sc.nextInt();
int r = sc.nextInt();
long val = 1000000007;
long ans = 0;
ans += (l != 1 ? prefix[l-2] : 0);
ans %= val;
ans += (r != arrSize ? suffix[r] : 0);
ans %= val;
System.out.println(ans);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <b> The only difference between the easy and the tricky version is the constraint on the number of queries Q. Solving the tricky version automatically solves the easy version.</b>
You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array A.
The third line of the input contains an integer Q.
The next Q lines contain two integers L and R.
Constraints
1 <= N <= 200000
1 <= A[i] <= 1000000000
1 <= Q <= 100000
1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query modulo 10<sup>9</sup>+7.Sample Input
4
5 3 3 1
2
2 3
4 4
Sample Output
6
11
Explanation: The array A = [5, 3, 3, 1].
First Query: Sum = 5 + 1 = 6.
Second Query: Sum = 5 + 3 + 3 = 11, I have written this Solution Code: n = int(input())
arr = list(map(int ,input().rstrip().split(" ")))
temp = 0
modified = []
for i in range(n):
temp = temp + arr[i]
modified.append(temp)
q = int(input())
for i in range(q):
s = list(map(int ,input().rstrip().split(" ")))
l = s[0]
r = s[1]
sum = 0
sum = ((modified[l-1]-arr[l-1])+(modified[n-1]-modified[r-1]))%1000000007
print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <b> The only difference between the easy and the tricky version is the constraint on the number of queries Q. Solving the tricky version automatically solves the easy version.</b>
You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array A.
The third line of the input contains an integer Q.
The next Q lines contain two integers L and R.
Constraints
1 <= N <= 200000
1 <= A[i] <= 1000000000
1 <= Q <= 100000
1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query modulo 10<sup>9</sup>+7.Sample Input
4
5 3 3 1
2
2 3
4 4
Sample Output
6
11
Explanation: The array A = [5, 3, 3, 1].
First Query: Sum = 5 + 1 = 6.
Second Query: Sum = 5 + 3 + 3 = 11, 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;
vector<int> a(n+1);
vector<int> pre(n+1, 0);
int tot = 0;
For(i, 1, n+1){
cin>>a[i];
assert(a[i]>0LL && a[i]<=1000000000LL);
tot += a[i];
pre[i]=pre[i-1]+a[i];
}
int q; cin>>q;
while(q--){
int l, r; cin>>l>>r;
int s = tot - (pre[r]-pre[l-1]);
s %= MOD;
cout<<s<<"\n";
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code: def OccurenceOfX(N,X):
cnt=0
for i in range(1, N+1):
if(X%i==0 and X/i<=N):
cnt=cnt+1
return cnt, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code:
int OccurenceOfX(int N,long X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code:
int OccurenceOfX(int N,long X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}
int main()
{
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code: public static int OccurenceOfX(int N,int X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N robots standing in a row. Ultron wants to delegate a task of difficulty X to two of them. Each robot has its own ability, A[i] for the i<sup>th</sup> robot from the left. The task can only be completed if the sum of the abilities of the two robots is exactly equal to X. Ultron wants to find out the number of distinct unordered pairs of robots he can choose to complete this task. He wants to find this number for Q (not necessarily distinct) subarrays of robots.
Formally, for each query, you will be given two integers L and R and you need to calculate the number of pairs (i, j) such that L β€ i < j β€ R and A[i] + A[j] = X.
Further, these subarrays have a nice property that for every pair of them at least one of the following three statements hold:
1. Their intersection is one of the two intervals itself (for example, segments [2, 6] and [2, 4]).
2. Their intersection is empty (for example, segments [2, 6] and [7, 8]).
3. Their intersection consists of exactly one element (for example, segments [2, 5] and [5, 8]).
For another example, note that the segments [2, 5] and [4, 7] do not satisfy any of the above conditions, and thus cannot both appear in the input.
You need to find the answer to each one of Ultron's queries and report the XOR of their answers.
<b>Note:</b> Since the input is large, it is recommended that you use fast input/output methods.The first line of the input contains two space-separated integers, N, the number of robots and X, the difficulty of the task.
The second line contains N space-separated integers A[1], A[2], ... A[n] - the abilities of the robots.
The third line of input contains an integer Q - the number of queries Ultron has.
Q lines follow, the i<sup>th</sup> of them contains two integers L and R for the i<sup>th</sup> query.
It is guaranteed that the given subarrays satisfy the properties mentioned in the problem statement.
<b>Constraints: </b>
2 β€ N β€ 400000
1 β€ X β€ 1000000
0 β€ A[i] β€ X
1 β€ Q β€ 400000
1 β€ L < R β€ N for each queryPrint a single integer, the bitwise XOR of the answers of the Q queries.Sample Input:
7 10
2 9 1 8 4 4 6
5
1 7
2 5
1 6
3 4
4 5
Sample Output:
7
Explanation:
For the first query there are 4 pairs of indices, (2, 3), (1, 4), (5, 7), (6, 7).
For the second query there is 1 pair of indices, (2, 3)
Similarly you can verify that the answers for the five queries are (4, 1, 2, 0, 0) in order. So we print their bitwise XOR = 7.
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
int X;
vector<int> adj[400005];
int ans[400005];
int cnt[1000005];
int A[400005];
pair<int, int> Q[400005];
void dfs(int x, bool keep = false)
{
int bigChild = -1, sz = 0;
for(auto &p: adj[x])
{
if(Q[p-1].second - Q[p-1].first > sz)
{
sz = Q[p-1].second - Q[p-1].first;
bigChild = p;
}
}
if(x > 0 && bigChild == -1)
{
for(int cur = Q[x-1].first; cur <= Q[x-1].second; cur++)
{
ans[x-1] += cnt[X-A[cur]];
cnt[A[cur]]++;
}
if(!keep)
{
for(int cur = Q[x-1].first; cur <= Q[x-1].second; cur++)
{
cnt[A[cur]]--;
}
}
return;
}
for(auto &p: adj[x])
{
if(p != bigChild)
{
dfs(p);
}
}
dfs(bigChild, true);
if(x > 0)
{
ans[x-1] = ans[bigChild-1];
for(int cur = Q[x-1].first; cur <= Q[x-1].second; cur++)
{
if(cur == Q[bigChild-1].first)
{
cur = Q[bigChild-1].second;
continue;
}
ans[x-1] += cnt[X-A[cur]];
cnt[A[cur]]++;
}
if(!keep)
{
for(int cur = Q[x-1].first; cur <= Q[x-1].second; cur++)
{
cnt[A[cur]]--;
}
}
}
}
bool my(int a, int b)
{
if(Q[a].first < Q[b].first) return true;
else if(Q[a].first == Q[b].first) return Q[a].second > Q[b].second;
return false;
}
void sack(int n, int q)
{
vector<int> order;
for(int i=0; i<q; i++) order.push_back(i);
sort(order.begin(), order.end(), my);
stack<int> right_ends;
stack<int> st;
for(int i=0; i<q; i++)
{
while(right_ends.size() && right_ends.top() <= Q[order[i]].first)
{
int which = st.top();
st.pop();
right_ends.pop();
if(st.empty())
{
adj[0].push_back(which+1);
}
else
{
adj[st.top()+1].push_back(which+1);
}
}
st.push(order[i]);
// cout << "inserting " << queries[i][2] << " into stack\n";
right_ends.push(Q[order[i]].second);
}
while(!st.empty())
{
int which = st.top();
st.pop();
right_ends.pop();
if(st.empty())
{
adj[0].push_back(which+1);
}
else
{
adj[st.top()+1].push_back(which+1);
}
}
// for(int i=0; i<=q; i++)
// {
// for(auto &x: adj[i])
// {
// cout << i << " has child " << x << "\n";
// }
// }
dfs(0);
}
signed main()
{
// freopen("input.txt", "r", stdin);
// freopen("output_sack.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n >> X;
for(int i=0; i<n; i++)
{
cin >> A[i];
}
int q;
cin >> q;
for(int i=0; i<q; i++)
{
cin >> Q[i].first >> Q[i].second;
Q[i].first--;
Q[i].second--;
}
sack(n, q);
int ansr = 0;
for(int i=0; i<q; i++)
{
ansr ^= ans[i];
}
cout << ansr << "\n";
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list consisting of N nodes, your task is to traverse the list and print its elements.<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>printList()</b> that takes head node of the linked list as parameter.
<b>Constraints:</b>
1 <=N <= 1000
1 <=Node.data<= 1000For each testcase you need to print the elements of the linked list separated by space. The driver code will take care of printing new line.Sample input
5
2 4 5 6 7
Sample output
2 4 5 6 7
Sample Input
4
1 2 3 5
Sample output
1 2 3 5, I have written this Solution Code: public static void printList(Node head) {
while(head!=null)
{
System.out.print(head.val + " ");
head=head.next;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
bool EqualOrNot(int h1, int h2, int v1,int v2){
if (v2>v1&&(h1-h2)%(v2-v1)==0){
return true;
}
return false;
}
int main(){
int n1,n2,v1,v2;
cin>>n1>>n2>>v1>>v2;
if(EqualOrNot(n1,n2,v1,v2)){
cout<<"Yes";}
else{
cout<<"No";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code: def EqualOrNot(h1,h2,v1,v2):
if (v2>v1 and (h1-h2)%(v2-v1)==0):
return True
else:
return False
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code: static boolean EqualOrNot(int h1, int h2, int v1,int v2){
if (v2>v1&&(h1-h2)%(v2-v1)==0){
return true;
}
return false;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: On his birthday, newton was given an n*n matrix and instructions for it. The instruction consisted of symbols L and R where if the symbol L is given you need to rotate the matrix 90 degrees to the left, and for the symbol R you need to rotate the matrix 90 degrees to the right. The instruction was only 3 characters in length so newton could handle the twists with ease. Your task is to display the matrix that newton had at the end of these turns.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You have to complete the function <b>Rotate()</b> that takes an integer n and 2d matrix a of size n*n and a string of length 3 as parameters.
<b>Constraints:</b>
1 ≤ N ≤ 500
Numbers can range from 1 to 500.Output the final matrix n*n.Sample Input:-
2
1 2
3 4
RLR
Sample Output:-
3 1
4 2, I have written this Solution Code: class Solution {
public void Rotate(int n,int [][]a,String s) {
int l=0,r=0;
for(char c:s.toCharArray()){
if(c=='R')r++;
else l++;
}
if(l==r){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
else if(l>r){
l=l-r;
if(l%4==0){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}else{
l=l%4;
for(int i=0;i<l;i++){
a=leftrotate(a,n);
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}else{
r=r-l;
if(r%4==0){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}else{
r=r%4;
//out.println("wow"+" "+r);
for(int i=0;i<r;i++){
a=rightrotate(a,n);
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
}
int[][] leftrotate(int[][] a,int n){
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
int tmp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = tmp;
}
}
for(int i=0;i<n;i++){
int low= 0;
int high= n-1;
while(low<high){
int tmp = a[low][i];
a[low][i] = a[high][i];
a[high][i] = tmp;
low++;
high--;
}
}
return a;
}
int[][] rightrotate(int[][] a,int n){
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
int tmp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = tmp;
}
}
for(int i=0;i<n;i++){
int low= 0;
int high= n-1;
while(low<high){
int tmp = a[i][low];
a[i][low] = a[i][high];
a[i][high] = tmp;
low++;
high--;
}
}
return a;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni loves vectors. She considers a vector awesome if it follows the following conditions:
-> Each element is greater than or equal to 1.
-> Number of elements in the vector is equal to K.
-> Sum of all the elements in the vector is equal to N.
-> The elements in the vector are in <b>strictly decreasing</b> order.
As Saloni is too moody, the values of N and K changes every moment for her. So, you will be given Q queries, each query contains two integers N and K. Find the number of distinct awesome vectors corresponding to each query. Report the answers modulo 1000000007.The first line of input contains an integer Q.
The next Q lines contain two integers N and K.
Constraints
1 <= Q <= 10000
1 <= N, K <= 50000For each query, print the number of awesome permutations modulo 1000000007.Sample Input
4
6 1
6 2
6 3
6 4
Sample Output
1
2
1
0
Explanation:
For N=6 and K=1, the only awesome vector is [6].
For N=6 and K=2, the awesome vectors are [4, 2] and [5, 1]. Note, [3, 3] is not an awesome vector as it violates fourth condition.
For N=6 and K=3, the only awesome vector is [3, 2, 1].
For N=6 and K=4, we can show that there is no awesome vector.
, 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>
/////////////
int dp[50001][425];
int pr[425][425];
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
dp[0][0]=1;
pr[0][0]=1;
int mo=1000000007;
for(int i=1;i<=50000;++i)
{
for(int j=1;j<425;++j)
{
dp[i][j]=pr[i%j][j-1];
// if(i<10&&j<10)
// cout<<dp[i][j]<<" ";
}
for(int j=1;j<425;++j)
pr[i%(j+1)][j]=(pr[i%(j+1)][j]+dp[i][j])%mo;
// cout<<"\n";
}
int q;
cin>>q;
while(q){
--q;
int n,k;
cin>>n>>k;
if(k>=425)
{
cout<<"0\n";
}
else
cout<<dp[n][k]<<"\n";
}
#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: Implement the function <code>floor</code>, which should take a number which can be a float(decimal)
and return its result as an integer with floor function applied to it (Use JS In built functions)Function will take a float as inputFunction will return a numberconsole.log(floor(1.99)) // prints 1
console.log(floor(2.1)) // prints 2
console.log(floor(-0.8)) // prints -1, I have written this Solution Code: function floor(num){
// write code here
// return the output , do not use console.log here
return Math.floor(num)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement the function <code>floor</code>, which should take a number which can be a float(decimal)
and return its result as an integer with floor function applied to it (Use JS In built functions)Function will take a float as inputFunction will return a numberconsole.log(floor(1.99)) // prints 1
console.log(floor(2.1)) // prints 2
console.log(floor(-0.8)) // prints -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);
float a = sc.nextFloat();
System.out.print((int)Math.floor(a));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b your task is to print the summation of these two numbersInput contains a single line containing two space separated integers a and b.
Constraints:-
1 <= a, b <= 10<sup>20000</sup>Print the sum of a and b.Sample Input:-
3 8
Sample Output:-
11
Sample Input:-
15 1
Sample Output:-
16, I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
import java.math.BigInteger;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger sum;
String ip1 = sc.next();
String ip2 = sc.next();
BigInteger a = new BigInteger(ip1);
BigInteger b = new BigInteger(ip2);
sum = a.add(b);
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b your task is to print the summation of these two numbersInput contains a single line containing two space separated integers a and b.
Constraints:-
1 <= a, b <= 10<sup>20000</sup>Print the sum of a and b.Sample Input:-
3 8
Sample Output:-
11
Sample Input:-
15 1
Sample Output:-
16, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-02-03 02:46:30
**/
#include <bits/stdc++.h>
#define NX 105
#define MX 3350
using namespace std;
const int mod = 998244353;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
typedef long long INT;
const int pb = 10;
const int base_digits = 9;
const int base = 1000000000;
const int DIV = 100000;
struct bigint {
vector<int> a;
int sign;
bigint() : sign(1) {}
bigint(INT v) { *this = v; }
bigint(const string &s) { read(s); }
void operator=(const bigint &v) { sign = v.sign, a = v.a; }
void operator=(INT v) {
sign = 1;
if (v < 0) sign = -1, v = -v;
for (; v > 0; v = v / base) a.push_back(v % base);
}
bigint operator+(const bigint &v) const {
if (sign == v.sign) {
bigint res = v;
for (int i = 0, carry = 0; i < (int)max(a.size(), v.a.size()) ||
carry;
i++) {
if (i == (int)res.a.size()) res.a.push_back(0);
res.a[i] += carry + (i < (int)a.size() ? a[i] : 0);
carry = res.a[i] >= base;
if (carry) res.a[i] -= base;
}
return res;
}
return *this - (-v);
}
bigint operator-(const bigint &v) const {
if (sign == v.sign) {
if (abs() >= v.abs()) {
bigint res = *this;
for (int i = 0, carry = 0; i < (int)v.a.size() || carry; i++) {
res.a[i] -= carry + (i < (int)v.a.size() ? v.a[i] : 0);
carry = res.a[i] < 0;
if (carry) res.a[i] += base;
}
res.trim();
return res;
}
return -(v - *this);
}
return *this + (-v);
}
void operator*=(int v) {
if (v < 0) sign = -sign, v = -v;
for (int i = 0, carry = 0; i < (int)a.size() || carry; i++) {
if (i == (int)a.size()) a.push_back(0);
INT cur = a[i] * (INT)v + carry;
carry = (int)(cur / base);
a[i] = (int)(cur % base);
}
trim();
}
bigint operator*(int v) const {
bigint res = *this;
res *= v;
return res;
}
friend pair<bigint, bigint> DIVmod(const bigint &a1, const bigint &b1) {
int norm = base / (b1.a.back() + 1);
bigint a = a1.abs() * norm;
bigint b = b1.abs() * norm;
bigint q, r;
q.a.resize(a.a.size());
for (int i = a.a.size() - 1; i >= 0; i--) {
r *= base;
r += a.a[i];
int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
int d = ((INT)base * s1 + s2) / b.a.back();
r -= b * d;
while (r < 0) r += b, --d;
q.a[i] = d;
}
q.sign = a1.sign * b1.sign;
r.sign = a1.sign;
q.trim();
r.trim();
return make_pair(q, r / norm);
}
bigint operator/(const bigint &v) const { return DIVmod(*this, v).first; }
bigint operator%(const bigint &v) const { return DIVmod(*this, v).second; }
void operator/=(int v) {
if (v < 0) sign = -sign, v = -v;
for (int i = (int)a.size() - 1, rem = 0; i >= 0; i--) {
INT cur = a[i] + rem * (INT)base;
a[i] = (int)(cur / v);
rem = (int)(cur % v);
}
trim();
}
bigint operator/(int v) const {
bigint res = *this;
res /= v;
return res;
}
int operator%(int v) const {
if (v < 0) v = -v;
int m = 0;
for (int i = a.size() - 1; i >= 0; --i)
m = (a[i] + m * (INT)base) % v;
return m * sign;
}
void operator+=(const bigint &v) { *this = *this + v; }
void operator-=(const bigint &v) { *this = *this - v; }
void operator*=(const bigint &v) { *this = *this * v; }
void operator/=(const bigint &v) { *this = *this / v; }
bool operator<(const bigint &v) const {
if (sign != v.sign) return sign < v.sign;
if (a.size() != v.a.size()) return a.size() * sign < v.a.size() * v.sign;
for (int i = a.size() - 1; i >= 0; i--)
if (a[i] != v.a[i]) return a[i] * sign < v.a[i] * sign;
return false;
}
bool operator>(const bigint &v) const { return v < *this; }
bool operator<=(const bigint &v) const { return !(v < *this); }
bool operator>=(const bigint &v) const { return !(*this < v); }
bool operator==(const bigint &v) const { return !(*this < v) && !(v < *this); }
bool operator!=(const bigint &v) const { return *this < v || v < *this; }
void trim() {
while (!a.empty() && !a.back()) a.pop_back();
if (a.empty()) sign = 1;
}
bool isZero() const { return a.empty() || (a.size() == 1 && !a[0]); }
bigint operator-() const {
bigint res = *this;
res.sign = -sign;
return res;
}
bigint abs() const {
bigint res = *this;
res.sign *= res.sign;
return res;
}
INT longValue() const {
INT res = 0;
for (int i = a.size() - 1; i >= 0; i--) res = res * base + a[i];
return res * sign;
}
friend bigint gcd(const bigint &a, const bigint &b) { return b.isZero() ? a : gcd(b, a % b); }
friend bigint lcm(const bigint &a, const bigint &b) { return a / gcd(a, b) * b; }
void read(const string &s) {
sign = 1;
a.clear();
int pos = 0;
while (pos < (int)s.size() && (s[pos] == '-' || s[pos] == '+')) {
if (s[pos] == '-') sign = -sign;
pos++;
}
for (int i = s.size() - 1; i >= pos; i -= base_digits) {
int x = 0;
for (int j = max(pos, i - base_digits + 1); j <= i; j++) x = x *
pb +
s[j] - '0';
a.push_back(x);
}
trim();
}
friend istream &operator>>(istream &stream, bigint &v) {
string s;
stream >> s;
v.read(s);
return stream;
}
friend ostream &operator<<(ostream &stream, const bigint &v) {
if (v.sign == -1) stream << '-';
stream << (v.a.empty() ? 0 : v.a.back());
for (int i = (int)v.a.size() - 2; i >= 0; --i) stream << setw(base_digits) << setfill('0') << v.a[i];
return stream;
}
static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
vector<INT> p(max(old_digits, new_digits) + 1);
p[0] = 1;
for (int i = 1; i < (int)p.size(); i++) p[i] = p[i - 1] * pb;
vector<int> res;
INT cur = 0;
int cur_digits = 0;
for (int i = 0; i < (int)a.size(); i++) {
cur += a[i] * p[cur_digits];
cur_digits += old_digits;
while (cur_digits >= new_digits) {
res.push_back(int(cur % p[new_digits]));
cur /= p[new_digits];
cur_digits -= new_digits;
}
}
res.push_back((int)cur);
while (!res.empty() && !res.back()) res.pop_back();
return res;
}
typedef vector<INT> vll;
static vll karatsubaMultiply(const vll &a, const vll &b) {
int n = a.size();
vll res(n + n);
if (n <= 32) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
res[i + j] += a[i] * b[j];
return res;
}
int k = n >> 1;
vll a1(a.begin(), a.begin() + k);
vll a2(a.begin() + k, a.end());
vll b1(b.begin(), b.begin() + k);
vll b2(b.begin() + k, b.end());
vll a1b1 = karatsubaMultiply(a1, b1);
vll a2b2 = karatsubaMultiply(a2, b2);
for (int i = 0; i < k; i++) a2[i] += a1[i];
for (int i = 0; i < k; i++) b2[i] += b1[i];
vll r = karatsubaMultiply(a2, b2);
for (int i = 0; i < (int)a1b1.size(); i++) r[i] -= a1b1[i];
for (int i = 0; i < (int)a2b2.size(); i++) r[i] -= a2b2[i];
for (int i = 0; i < (int)r.size(); i++) res[i + k] += r[i];
for (int i = 0; i < (int)a1b1.size(); i++) res[i] += a1b1[i];
for (int i = 0; i < (int)a2b2.size(); i++) res[i + n] += a2b2[i];
return res;
}
bigint operator*(const bigint &v) const {
vector<int> a5 = convert_base(this->a, base_digits, 5);
vector<int> b5 = convert_base(v.a, base_digits, 5);
vll a(a5.begin(), a5.end());
vll b(b5.begin(), b5.end());
while (a.size() < b.size()) a.push_back(0);
while (b.size() < a.size()) b.push_back(0);
while (a.size() & (a.size() - 1)) a.push_back(0), b.push_back(0);
vll c = karatsubaMultiply(a, b);
bigint res;
res.sign = sign * v.sign;
for (int i = 0, carry = 0; i < (int)c.size(); i++) {
INT cur = c[i] + carry;
res.a.push_back((int)(cur % DIV));
carry = (int)(cur / DIV);
}
res.a = convert_base(res.a, 5, base_digits);
res.trim();
return res;
}
inline bool isOdd() { return a[0] & 1; }
};
int main() {
bigint n, m;
cin >> n >> m;
cout << n + m << "\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 print the summation of these two numbersInput contains a single line containing two space separated integers a and b.
Constraints:-
1 <= a, b <= 10<sup>20000</sup>Print the sum of a and b.Sample Input:-
3 8
Sample Output:-
11
Sample Input:-
15 1
Sample Output:-
16, I have written this Solution Code: n,m = map(int,input().split())
print(n+m) , In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int len = Integer.parseInt(br.readLine());
char[] str = new char[len];
for(int i = 0; i < len; i++){
if(i%2 == 0){
str[i] = 'a';
} else{
str[i] = 'b';
}
}
System.out.println(str);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
#define rep(i,n) for (int i=0; i<(n); i++)
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
string s(n,'a');
for(int i=1;i<n;i+=2)
s[i]='b';
cout<<s;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: a="ab"
inp = int(input())
print(a*(inp//2)+a[0:inp%2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a class with the name SumCalculator. The class needs two fields (public variables) with names num1 and num2 both of type int.
Write the following methods (instance methods):
<b>*Method named sum without any parameters, it needs to return the value of num1 + num2.</b>
<b>*Method named sum2 with two parameters a, b, it needs to return the value of a + b.</b>
<b>*Method named fromObject with two parameters of type sumCalculator object named obj1 and obj2, and you have to call sum function for respective object and return sum of both</b>
NOTE: All methods should be defined as public, NOT public static.
NOTE: In total, you have to write 3 methods.
NOTE: Do not add the main method to the solution code.You don't have to take any input, You only have to write class <b>SumCalculator</b>.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Input:
1
Sample Output:
Correct, I have written this Solution Code: class SumCalculator():
def __init__(self,a,b):
self.a=a
self.b=b
def sum(self):
return self.a+self.b
def sum2(self,a,b):
return a+b
def fromObject(self,ob1,ob2):
return ob1.sum+ob2.sum, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a class with the name SumCalculator. The class needs two fields (public variables) with names num1 and num2 both of type int.
Write the following methods (instance methods):
<b>*Method named sum without any parameters, it needs to return the value of num1 + num2.</b>
<b>*Method named sum2 with two parameters a, b, it needs to return the value of a + b.</b>
<b>*Method named fromObject with two parameters of type sumCalculator object named obj1 and obj2, and you have to call sum function for respective object and return sum of both</b>
NOTE: All methods should be defined as public, NOT public static.
NOTE: In total, you have to write 3 methods.
NOTE: Do not add the main method to the solution code.You don't have to take any input, You only have to write class <b>SumCalculator</b>.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Input:
1
Sample Output:
Correct, I have written this Solution Code: class SumCalculator{
public int num1,num2;
SumCalculator(int _num1,int _num2){
num1=_num1;
num2=_num2;
}
public int sum() {
return num1+num2;
}
public int sum2(int a,int b){
return a+b;
}
public int fromObject(SumCalculator obj1,SumCalculator obj2){
return obj1.sum() + obj2.sum();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N. You have to print the maximum in every <b>K-sized subarray</b> from the left to the right in the array A.
More formally, you have to print N - K + 1 integers X<sub>1</sub>, X<sub>2</sub>, ..., X<sub>N-K+1</sub> such that X<sub>i</sub> (1 <= i <= N - K + 1) is the maximum element in the subarray A<sub>i</sub>, A<sub>i+1</sub>, ..., A<sub>i+K-1</sub>.1. The first line contains an integer N, denoting the size of the array.
2. The second line has N space-separated integers of the array A.
3. The third line contains integer K, denoting the size of the sliding window
<b>Constraints :</b>
1 ≤ N ≤ 10<sup>5</sup>
-10<sup>4</sup> ≤ A[i] ≤ 10<sup>4</sup>
1 ≤ K ≤ NPrint the max of K numbers for each position of sliding windowSample Input:-
8
1 3 -1 -3 5 3 6 7
3
Sample Output:-
3 3 5 5 6 7
Explanation:-
Window position Max
- - - -
[1 3 -1] -3 5 3 6 7 3
1 [3 -1 -3] 5 3 6 7 3
1 3 [-1 -3 5] 3 6 7 5
1 3 -1 [-3 5 3] 6 7 5
1 3 -1 -3 [5 3 6] 7 6
1 3 -1 -3 5 [3 6 7] 7
Sample Input:-
1
1
1
Sample Output:-
1 , I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
int n=Integer.parseInt(bu.readLine());
String s[]=bu.readLine().split(" ");
int a[]=new int[n],i;
PriorityQueue<int[]> pq=new PriorityQueue<>(new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if(o1[0]<o2[0]) return 1;
else return -1;
}});
for(i=0;i<n;i++) a[i]=Integer.parseInt(s[i]);
int k=Integer.parseInt(bu.readLine());
for(i=0;i<k;i++) pq.add(new int[]{a[i],i});
sb.append(pq.peek()[0]+" ");
for(i=k;i<n;i++)
{
pq.add(new int[]{a[i],i});
while(!pq.isEmpty() && pq.peek()[1]<=i-k) pq.poll();
sb.append(pq.peek()[0]+" ");
}
System.out.println(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N. You have to print the maximum in every <b>K-sized subarray</b> from the left to the right in the array A.
More formally, you have to print N - K + 1 integers X<sub>1</sub>, X<sub>2</sub>, ..., X<sub>N-K+1</sub> such that X<sub>i</sub> (1 <= i <= N - K + 1) is the maximum element in the subarray A<sub>i</sub>, A<sub>i+1</sub>, ..., A<sub>i+K-1</sub>.1. The first line contains an integer N, denoting the size of the array.
2. The second line has N space-separated integers of the array A.
3. The third line contains integer K, denoting the size of the sliding window
<b>Constraints :</b>
1 ≤ N ≤ 10<sup>5</sup>
-10<sup>4</sup> ≤ A[i] ≤ 10<sup>4</sup>
1 ≤ K ≤ NPrint the max of K numbers for each position of sliding windowSample Input:-
8
1 3 -1 -3 5 3 6 7
3
Sample Output:-
3 3 5 5 6 7
Explanation:-
Window position Max
- - - -
[1 3 -1] -3 5 3 6 7 3
1 [3 -1 -3] 5 3 6 7 3
1 3 [-1 -3 5] 3 6 7 5
1 3 -1 [-3 5 3] 6 7 5
1 3 -1 -3 [5 3 6] 7 6
1 3 -1 -3 5 [3 6 7] 7
Sample Input:-
1
1
1
Sample Output:-
1 , I have written this Solution Code: N = int(input())
A = [int(x) for x in input().split()]
K = int(input())
def print_max(a, n, k):
max_upto = [0 for i in range(n)]
s = []
s.append(0)
for i in range(1, n):
while (len(s) > 0 and a[s[-1]] < a[i]):
max_upto[s[-1]] = i - 1
del s[-1]
s.append(i)
while (len(s) > 0):
max_upto[s[-1]] = n - 1
del s[-1]
j = 0
for i in range(n - k + 1):
while (j < i or max_upto[j] < i + k - 1):
j += 1
print(a[j], end=" ")
print()
print_max(A, N, K), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N. You have to print the maximum in every <b>K-sized subarray</b> from the left to the right in the array A.
More formally, you have to print N - K + 1 integers X<sub>1</sub>, X<sub>2</sub>, ..., X<sub>N-K+1</sub> such that X<sub>i</sub> (1 <= i <= N - K + 1) is the maximum element in the subarray A<sub>i</sub>, A<sub>i+1</sub>, ..., A<sub>i+K-1</sub>.1. The first line contains an integer N, denoting the size of the array.
2. The second line has N space-separated integers of the array A.
3. The third line contains integer K, denoting the size of the sliding window
<b>Constraints :</b>
1 ≤ N ≤ 10<sup>5</sup>
-10<sup>4</sup> ≤ A[i] ≤ 10<sup>4</sup>
1 ≤ K ≤ NPrint the max of K numbers for each position of sliding windowSample Input:-
8
1 3 -1 -3 5 3 6 7
3
Sample Output:-
3 3 5 5 6 7
Explanation:-
Window position Max
- - - -
[1 3 -1] -3 5 3 6 7 3
1 [3 -1 -3] 5 3 6 7 3
1 3 [-1 -3 5] 3 6 7 5
1 3 -1 [-3 5 3] 6 7 5
1 3 -1 -3 [5 3 6] 7 6
1 3 -1 -3 5 [3 6 7] 7
Sample Input:-
1
1
1
Sample Output:-
1 , I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
vector<int> maxSwindow(vector<int>& arr, int k) {
vector<int> result;
deque<int> Q(k); // store the indices
// process the first window
for(int i = 0; i < k; i++) {
while(!Q.empty() and arr[i] >= arr[Q.back()])
Q.pop_back();
Q.push_back(i);
}
// process the remaining elements
for(int i = k; i < arr.size(); i++) {
// add the max of the current window
result.push_back(arr[Q.front()]);
// remove the elements going out of the window
while(!Q.empty() and Q.front() <= i - k)
Q.pop_front();
// remove the useless elements
while(!Q.empty() and arr[i] >= arr[Q.back()])
Q.pop_back();
// add the current element in the deque
Q.push_back(i);
}
result.push_back(arr[Q.front()]);
return result;
}
int main()
{
int k, n, m;
cin >> n;
vector<int> nums, res;
for(int i =0; i < n; i++){
cin >> m;
nums.push_back(m);
}
cin >> k;
res = maxSwindow(nums,k);
for(auto i = res.begin(); i!=res.end(); i++)
cout << *i << " ";
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two arrays - value and frequency both containing N elements.
There is also a third array C which is currently empty. Then you perform N insertion operation in the array. For ith operation you insert value[i] to the end of the array frequency[i] number of times.
Finally you have to tell the kth smallest element in the array C.First line of input contains N.
Second line contains N integers denoting array - value
Third line contains N integers denoting array - frequency
Fourth line contains single integer K.
Constraints
1 <= N, value[i], frequency[i] <= 100000
1 <= k <= frequency[1] + frequency[2] +frequency[3] +........ + frequency[N]
Output a single integer which is the kth smallest element of the array C.Sample input 1
5
1 2 3 4 5
1 1 1 2 2
3
Sample output 1
3
Explanation 1:
Array C constructed is 1 2 3 4 4 5 5
Third smallest element is 3
Sample input 2
3
2 1 3
3 3 2
2
sample output 2
1
Explanation 2:
Array C constructed is 2 2 2 1 1 1 3 3
Second smallest element is 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int[] val = new int[n];
for(int i=0; i<n; i++){
val[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(br.readLine());
int[] freq = new int[n];
for(int i=0; i<n; i++){
freq[i] = Integer.parseInt(st.nextToken());
}
int k = Integer.parseInt(br.readLine());
for (int i=0; i<n; i++) {
for (int j=i+1; j<n; j++) {
if (val[j] < val[i]) {
int temp = val[i];
val[i] = val[j];
val[j] = temp;
int temp1 = freq[i];
freq[i] = freq[j];
freq[j] = temp1;
}
}
}
int element=0;
for(int i=0; i<n; i++){
for(int j=0; j<freq[i]; j++){
element++;
int value = val[i];
if(element==k){
System.out.print(value);
break;
}
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two arrays - value and frequency both containing N elements.
There is also a third array C which is currently empty. Then you perform N insertion operation in the array. For ith operation you insert value[i] to the end of the array frequency[i] number of times.
Finally you have to tell the kth smallest element in the array C.First line of input contains N.
Second line contains N integers denoting array - value
Third line contains N integers denoting array - frequency
Fourth line contains single integer K.
Constraints
1 <= N, value[i], frequency[i] <= 100000
1 <= k <= frequency[1] + frequency[2] +frequency[3] +........ + frequency[N]
Output a single integer which is the kth smallest element of the array C.Sample input 1
5
1 2 3 4 5
1 1 1 2 2
3
Sample output 1
3
Explanation 1:
Array C constructed is 1 2 3 4 4 5 5
Third smallest element is 3
Sample input 2
3
2 1 3
3 3 2
2
sample output 2
1
Explanation 2:
Array C constructed is 2 2 2 1 1 1 3 3
Second smallest element is 1, I have written this Solution Code: def myFun():
n = int(input())
arr1 = list(map(int,input().strip().split()))
arr2 = list(map(int,input().strip().split()))
k = int(input())
arr = []
for i in range(n):
arr.append((arr1[i], arr2[i]))
arr.sort()
c = 0
for i in arr:
k -= i[1]
if k <= 0:
print(i[0])
return
myFun()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two arrays - value and frequency both containing N elements.
There is also a third array C which is currently empty. Then you perform N insertion operation in the array. For ith operation you insert value[i] to the end of the array frequency[i] number of times.
Finally you have to tell the kth smallest element in the array C.First line of input contains N.
Second line contains N integers denoting array - value
Third line contains N integers denoting array - frequency
Fourth line contains single integer K.
Constraints
1 <= N, value[i], frequency[i] <= 100000
1 <= k <= frequency[1] + frequency[2] +frequency[3] +........ + frequency[N]
Output a single integer which is the kth smallest element of the array C.Sample input 1
5
1 2 3 4 5
1 1 1 2 2
3
Sample output 1
3
Explanation 1:
Array C constructed is 1 2 3 4 4 5 5
Third smallest element is 3
Sample input 2
3
2 1 3
3 3 2
2
sample output 2
1
Explanation 2:
Array C constructed is 2 2 2 1 1 1 3 3
Second smallest element is 1, 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 inf 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;ll K;
cin>>N;
int c=0;
pair<int, ll> A[N];
for(int i=0;i<N;++i){
cin >> A[i].first ;
}
for(int i=0;i<N;++i){
cin >> A[i].second ;
}
cin>>K;
sort(A, A+N);
for(int i=0;i<N;++i){
K -= A[i].second;
if(K <= 0){
cout << A[i].first << endl;;
break;
}
}
#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 arr[] of N integers and another integer D, your task is to perform D right circular rotations on the array and print the modified array.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>circularRotate() </b> which takes the deque, number of rotation and the number of elements in deque as parameters.
Constraint:
1 <= T <= 100
1 <= N <= 100000
1 <= elements <= 10000
1 <= D <= 100000You don't need to print anything you just need to complete the function.Input:
2
5
1 2 3 4 5
6
4
1 2 3 4
7
Output:
5 1 2 3 4
2 3 4 1, I have written this Solution Code: static void circularRotate(Deque<Integer> deq, int d, int n)
{
// Push first d elements
// from last to the beginning
for (int i = 0; i < d%n; i++) {
int val = deq.peekLast();
deq.pollLast();
deq.addFirst(val);
}
}, 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 number of mountains in the array. A mountain is a tuple (i,j,k,l,m) such that i < j < k < l < m and Arr[i] < Arr[j] < Arr[k] > Arr[l] > Arr[m].
As the number of such mountains can be large print number of mountains modulo 1000000007The first line of input contains two integers N.
Second line contains N space seperated integers.
Constraints
1 <= N <= 100000
1 <= Arr[i] <= 1000000000Output a single integer, the required value modulo 1000000007.sample input
5
1 2 3 2 1
sample output
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
#define ld long double
int power_mod(int num,int g)
{
if(g==0)return 1;
if(g%2==1)return (num*power_mod((num*num)%mod,g/2))%mod;
return power_mod((num*num)%mod,g/2);
}
int power(int num,int g)
{
if(g==0)return 1;
if(g%2==1)return (num*power((num*num),g/2));
return power((num*num),g/2);
}
pair<int,int> pa[100005];
int tree[400005];
void update(int start,int end,int index,int ind,int val) {
if(start==end) {
tree[index]+=val;
return;
}
int mid=(start+end)/2;
if(ind<=mid)update(start,mid,2*index,ind,val);
else update(mid+1,end,2*index+1,ind,val);
tree[index]=tree[2*index]+tree[2*index+1];
tree[index]%=mod;
}
int search(int start,int end,int index,int l,int r) {
if(start>r || end<l)return 0;
if(start>=l && end<=r)return tree[index];
int mid=(start+end)/2;
return search(start,mid,2*index,l,r)+search(mid+1,end,2*index+1,l,r);
}
int32_t main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
int a[n];
For(i,n)cin>>a[i];
set<int> st;
For(i,n)st.insert(a[i]);
map<int,int> mp1;
int z=1;
for(auto it=st.begin();it!=st.end();it++) {
mp1[*it]=z;
z++;
}
For(i,n)a[i]=mp1[a[i]];
mem(tree,0);
int b[n];
For(i,n) {
b[i]=search(1,z,1,1,a[i]-1);
update(1,z,1,a[i],1);
b[i]%=mod;
}
mem(tree,0);
int c[n];
For(i,n) {
c[i]=search(1,z,1,1,a[i]-1);
update(1,z,1,a[i],b[i]);
c[i]%=mod;
}
For(i,n/2)swap(a[i],a[n-i-1]);
mem(tree,0);
For(i,n) {
b[i]=search(1,z,1,1,a[i]-1);
update(1,z,1,a[i],1);
b[i]%=mod;
}
mem(tree,0);
int d[n];
For(i,n) {
d[i]=search(1,z,1,1,a[i]-1);
update(1,z,1,a[i],b[i]);
d[i]%=mod;
}
For(i,n/2)swap(d[i],d[n-i-1]);
int ans=0;
For(i,n) {
d[i]%=mod;
c[i]%=mod;
ans+=c[i]*d[i];
ans%=mod;
}
cout<<ans<<endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers find the number of mountains in the array. A mountain is a tuple (i,j,k,l,m) such that i < j < k < l < m and Arr[i] < Arr[j] < Arr[k] > Arr[l] > Arr[m].
As the number of such mountains can be large print number of mountains modulo 1000000007The first line of input contains two integers N.
Second line contains N space seperated integers.
Constraints
1 <= N <= 100000
1 <= Arr[i] <= 1000000000Output a single integer, the required value modulo 1000000007.sample input
5
1 2 3 2 1
sample output
1, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.awt.*;
import java.math.*;
class Main {
public static void main(String[] args) throws Exception {
new Solver().solve();
}
static class Solver {
final Helper hp;
final int MAXN = 1000_006;
final long MOD = (long) 1e9 + 7;
Solver() {
hp = new Helper(MOD, MAXN);
hp.initIO(System.in, System.out);
}
void solve() throws Exception {
int i, j, k;
FenwickTree[] seg;
TreeMap<Integer, Long>[] pending = new TreeMap[]{new TreeMap<>(), new TreeMap<>()};
long last;
int N = hp.nextInt();
if (N < 5) {
System.out.println(0);
return;
}
long[] A = hp.getLongArray(N);
Integer[] idx = new Integer[N];
for (i = 0; i < N; ++i) idx[i] = i;
Arrays.sort(idx, (a, b) -> Long.compare(A[a], A[b]));
long[][] prefix = new long[N][3];
seg = new FenwickTree[]{new FenwickTree(N), new FenwickTree(N)};
last = -7;
for (int ind : idx) {
if (A[ind] != last) {
while (!pending[0].isEmpty()) {
Map.Entry<Integer, Long> entry = pending[0].pollFirstEntry();
seg[0].update(entry.getKey(), entry.getValue());
}
while (!pending[1].isEmpty()) {
Map.Entry<Integer, Long> entry = pending[1].pollFirstEntry();
seg[1].update(entry.getKey(), entry.getValue());
}
last = A[ind];
}
++prefix[ind][0];
prefix[ind][1] = seg[0].query(0, ind - 1);
prefix[ind][2] = seg[1].query(0, ind - 1);
pending[0].put(ind, 1l);
pending[1].put(ind, prefix[ind][1]);
}
pending[0].clear();
pending[1].clear();
long[][] suffix = new long[N][3];
seg = new FenwickTree[]{new FenwickTree(N), new FenwickTree(N)};
last = -7;
for (int ind : idx) {
if (A[ind] != last) {
while (!pending[0].isEmpty()) {
Map.Entry<Integer, Long> entry = pending[0].pollFirstEntry();
seg[0].update(entry.getKey(), entry.getValue());
}
while (!pending[1].isEmpty()) {
Map.Entry<Integer, Long> entry = pending[1].pollFirstEntry();
seg[1].update(entry.getKey(), entry.getValue());
}
last = A[ind];
}
++suffix[ind][0];
suffix[ind][1] = seg[0].query(ind + 1, N - 1);
suffix[ind][2] = seg[1].query(ind + 1, N - 1);
pending[0].put(ind, 1l);
pending[1].put(ind, suffix[ind][1]);
}
pending[0].clear();
pending[1].clear();
long ans = 0;
for (i = 0; i < N; ++i) {
ans = (ans + prefix[i][2] * suffix[i][2] % MOD) % MOD;
}
hp.println(ans);
hp.flush();
}
}
static class FenwickTree {
final long MOD = (long) 1e9 + 7;
int N;
long[] tree;
FenwickTree(int size) {
N = size + 1;
tree = new long[N];
}
void update(int idx, long val) {
++idx;
while (idx < N) {
tree[idx] = (tree[idx] + val) % MOD;
idx += idx & -idx;
}
}
long query(int idx) {
++idx;
long ret = 0;
while (idx > 0) {
ret = (ret + tree[idx]) % MOD;
idx -= idx & -idx;
}
return ret;
}
long query(int l, int r) {
long ret = query(r);
if (l > 0) ret -= query(l - 1);
return (ret % MOD + MOD) % MOD;
}
}
static class Helper {
final long MOD;
final int MAXN;
final Random rnd;
public Helper(long mod, int maxn) {
MOD = mod;
MAXN = maxn;
rnd = new Random();
}
public static int[] sieve;
public static ArrayList<Integer> primes;
public void setSieve() {
primes = new ArrayList<>();
sieve = new int[MAXN];
int i, j;
for (i = 2; i < MAXN; ++i)
if (sieve[i] == 0) {
primes.add(i);
for (j = i; j < MAXN; j += i) {
sieve[j] = i;
}
}
}
public static long[] factorial;
public void setFactorial() {
factorial = new long[MAXN];
factorial[0] = 1;
for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
}
public long getFactorial(int n) {
if (factorial == null) setFactorial();
return factorial[n];
}
public long ncr(int n, int r) {
if (r > n) return 0;
if (factorial == null) setFactorial();
long numerator = factorial[n];
long denominator = factorial[r] * factorial[n - r] % MOD;
return numerator * pow(denominator, MOD - 2, MOD) % MOD;
}
public long[] getLongArray(int size) throws Exception {
long[] ar = new long[size];
for (int i = 0; i < size; ++i) ar[i] = nextLong();
return ar;
}
public int[] getIntArray(int size) throws Exception {
int[] ar = new int[size];
for (int i = 0; i < size; ++i) ar[i] = nextInt();
return ar;
}
public String[] getStringArray(int size) throws Exception {
String[] ar = new String[size];
for (int i = 0; i < size; ++i) ar[i] = next();
return ar;
}
public String joinElements(long[] ar) {
StringBuilder sb = new StringBuilder();
for (long itr : ar) sb.append(itr).append(" ");
return sb.toString().trim();
}
public String joinElements(int[] ar) {
StringBuilder sb = new StringBuilder();
for (int itr : ar) sb.append(itr).append(" ");
return sb.toString().trim();
}
public String joinElements(String[] ar) {
StringBuilder sb = new StringBuilder();
for (String itr : ar) sb.append(itr).append(" ");
return sb.toString().trim();
}
public String joinElements(Object[] ar) {
StringBuilder sb = new StringBuilder();
for (Object itr : ar) sb.append(itr).append(" ");
return sb.toString().trim();
}
public long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
public int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public long max(long[] ar) {
long ret = ar[0];
for (long itr : ar) ret = Math.max(ret, itr);
return ret;
}
public int max(int[] ar) {
int ret = ar[0];
for (int itr : ar) ret = Math.max(ret, itr);
return ret;
}
public long min(long[] ar) {
long ret = ar[0];
for (long itr : ar) ret = Math.min(ret, itr);
return ret;
}
public int min(int[] ar) {
int ret = ar[0];
for (int itr : ar) ret = Math.min(ret, itr);
return ret;
}
public long sum(long[] ar) {
long sum = 0;
for (long itr : ar) sum += itr;
return sum;
}
public long sum(int[] ar) {
long sum = 0;
for (int itr : ar) sum += itr;
return sum;
}
public void shuffle(int[] ar) {
int r;
for (int i = 0; i < ar.length; ++i) {
r = rnd.nextInt(ar.length);
if (r != i) {
ar[i] ^= ar[r];
ar[r] ^= ar[i];
ar[i] ^= ar[r];
}
}
}
public void shuffle(long[] ar) {
int r;
for (int i = 0; i < ar.length; ++i) {
r = rnd.nextInt(ar.length);
if (r != i) {
ar[i] ^= ar[r];
ar[r] ^= ar[i];
ar[i] ^= ar[r];
}
}
}
public long pow(long base, long exp, long MOD) {
base %= MOD;
long ret = 1;
while (exp > 0) {
if ((exp & 1) == 1) ret = ret * base % MOD;
base = base * base % MOD;
exp >>= 1;
}
return ret;
}
static byte[] buf = new byte[2048];
static int index, total;
static InputStream in;
static BufferedWriter bw;
public void initIO(InputStream is, OutputStream os) {
try {
in = is;
bw = new BufferedWriter(new OutputStreamWriter(os));
} catch (Exception e) {
}
}
public void initIO(String inputFile, String outputFile) {
try {
in = new FileInputStream(inputFile);
bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outputFile)));
} catch (Exception e) {
}
}
private int scan() throws Exception {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0)
return -1;
}
return buf[index++];
}
public String next() throws Exception {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan())
sb.append((char) c);
return sb.toString();
}
public int nextInt() throws Exception {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+')
c = scan();
for (; c >= '0' && c <= '9'; c = scan())
val = (val << 3) + (val << 1) + (c & 15);
return neg ? -val : val;
}
public long nextLong() throws Exception {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+')
c = scan();
for (; c >= '0' && c <= '9'; c = scan())
val = (val << 3) + (val << 1) + (c & 15);
return neg ? -val : val;
}
public void print(Object a) throws Exception {
bw.write(a.toString());
}
public void printsp(Object a) throws Exception {
print(a);
print(" ");
}
public void println() throws Exception {
bw.write("\n");
}
public void println(Object a) throws Exception {
print(a);
println();
}
public void flush() throws Exception {
bw.flush();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N.
Constraints:
1 < = T < = 100
1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input:
2
5
10
Sample Output:
15
55, 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());
System.out.println(n*(n+1)/2);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N.
Constraints:
1 < = T < = 100
1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input:
2
5
10
Sample Output:
15
55, I have written this Solution Code: for t in range(int(input())):
n = int(input())
print(n*(n+1)//2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N.
Constraints:
1 < = T < = 100
1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input:
2
5
10
Sample Output:
15
55, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
cout<<(n*(n+1))/2<<endl;
}
}, 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 containing only 0 or 1. You can do the following operations on the array:
<ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul>
You have to do the minimum number of the above operations such that the final array is non-decreasing.
<b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N.
The second line of input contains N space-separated integers denoting the array.
Constraints:
1 ≤ N ≤ 100000
elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1
5
1 1 0 0 1
Sample Output 1
2
Explanation:
Swap indices (1, 3)
Swap indices (2, 4)
Sample Input 2
5
0 0 1 1 1
Sample Output 2
0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine().trim());
String array[] = br.readLine().trim().split(" ");
boolean decreasingOrder = false;
int[] arr = new int[n];
int totalZeroCount = 0,
totalOneCount = 0;
for(int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(array[i]);
if(i != 0 && arr[i] < arr[i - 1])
decreasingOrder = true;
if(arr[i] % 2 == 0)
++totalZeroCount;
else
++totalOneCount;
}
if(!decreasingOrder) {
System.out.println("0");
} else {
int oneCount = 0;
for(int i = 0; i < totalZeroCount; i++) {
if(arr[i] == 1)
++oneCount;
}
System.out.println(oneCount);
}
}
}, 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 containing only 0 or 1. You can do the following operations on the array:
<ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul>
You have to do the minimum number of the above operations such that the final array is non-decreasing.
<b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N.
The second line of input contains N space-separated integers denoting the array.
Constraints:
1 ≤ N ≤ 100000
elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1
5
1 1 0 0 1
Sample Output 1
2
Explanation:
Swap indices (1, 3)
Swap indices (2, 4)
Sample Input 2
5
0 0 1 1 1
Sample Output 2
0, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i]==0) cnt++;
}
int ans = 0;
for (int i = 0; i < cnt; i++) if (a[i] == 1) ans++;
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 containing only 0 or 1. You can do the following operations on the array:
<ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul>
You have to do the minimum number of the above operations such that the final array is non-decreasing.
<b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N.
The second line of input contains N space-separated integers denoting the array.
Constraints:
1 ≤ N ≤ 100000
elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1
5
1 1 0 0 1
Sample Output 1
2
Explanation:
Swap indices (1, 3)
Swap indices (2, 4)
Sample Input 2
5
0 0 1 1 1
Sample Output 2
0, I have written this Solution Code: n=int(input())
l=list(map(int,input().split()))
x=l.count(0)
c=0
for i in range(0,x):
if(l[i]==1):
c+=1
print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array Arr of N integers. You have to process Q queries on the array. Each query contains L and R, for each query you have to report the number of indices i in the array such that L <= Arr[i] <= R.First line of input contains two integers N and Q representing number of elements in the array and number of queries.
Second line of input contains N integers representing the array Arr.
Next Q lines of input contains L and R for that query.
Constraints
1 <= N,Q <= 100000
1 <= Arr[i] <= 100000
1 <= L <= R <= 100000For each query you have to print the number of index i in the array such that L <= Arr[i] <= R in a seperate line.Sample input
10 10
3 6 7 4 9 1 7 10 9 4
1 9
4 6
4 7
4 6
6 8
5 8
2 6
2 3
9 9
2 5
Sample output
9
3
5
3
3
3
4
1
2
3
Explanation :
For range 1 to 9 : all indexes except index 8 (with value 10) have values in the range 1 to 9
For range 4 to 6 : indexes 2(with value 6), 4(with value 4) and 10(with value 4) have value in the range 4 to 6, 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[] strArr = br.readLine().split(" ");
int N = Integer.parseInt(strArr[0]);
int Q = Integer.parseInt(strArr[1]);
int[] arr = new int[100001];
strArr = br.readLine().split(" ");
int max = 0;
for(int i=0; i<N; i++){
int curr = Integer.parseInt(strArr[i]);
arr[curr]++;
if(curr>max){
max = curr;
}
}
long[] prefixSum = new long[100001];
long sum = 0;
for(int i=0; i<=100000; i++){
sum = sum + arr[i];
prefixSum[i] = sum;
}
for(int i=0; i<Q; i++){
strArr = br.readLine().split(" ");
int L = Integer.parseInt(strArr[0]);
int R = Integer.parseInt(strArr[1]);
long count = prefixSum[R]-prefixSum[L-1];
System.out.println(count);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array Arr of N integers. You have to process Q queries on the array. Each query contains L and R, for each query you have to report the number of indices i in the array such that L <= Arr[i] <= R.First line of input contains two integers N and Q representing number of elements in the array and number of queries.
Second line of input contains N integers representing the array Arr.
Next Q lines of input contains L and R for that query.
Constraints
1 <= N,Q <= 100000
1 <= Arr[i] <= 100000
1 <= L <= R <= 100000For each query you have to print the number of index i in the array such that L <= Arr[i] <= R in a seperate line.Sample input
10 10
3 6 7 4 9 1 7 10 9 4
1 9
4 6
4 7
4 6
6 8
5 8
2 6
2 3
9 9
2 5
Sample output
9
3
5
3
3
3
4
1
2
3
Explanation :
For range 1 to 9 : all indexes except index 8 (with value 10) have values in the range 1 to 9
For range 4 to 6 : indexes 2(with value 6), 4(with value 4) and 10(with value 4) have value in the range 4 to 6, I have written this Solution Code: n,q=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*(100001)
for i in range(n):
b[a[i]]+=1
s=0
for i in range(100001):
s+=b[i]
b[i]=s
for i in range(q):
v=[int(k) for k in input().split()]
print(b[v[1]]-b[v[0]-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array Arr of N integers. You have to process Q queries on the array. Each query contains L and R, for each query you have to report the number of indices i in the array such that L <= Arr[i] <= R.First line of input contains two integers N and Q representing number of elements in the array and number of queries.
Second line of input contains N integers representing the array Arr.
Next Q lines of input contains L and R for that query.
Constraints
1 <= N,Q <= 100000
1 <= Arr[i] <= 100000
1 <= L <= R <= 100000For each query you have to print the number of index i in the array such that L <= Arr[i] <= R in a seperate line.Sample input
10 10
3 6 7 4 9 1 7 10 9 4
1 9
4 6
4 7
4 6
6 8
5 8
2 6
2 3
9 9
2 5
Sample output
9
3
5
3
3
3
4
1
2
3
Explanation :
For range 1 to 9 : all indexes except index 8 (with value 10) have values in the range 1 to 9
For range 4 to 6 : indexes 2(with value 6), 4(with value 4) and 10(with value 4) have value in the range 4 to 6, 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,q;
cin>>n>>q;
int c[100001]={};
int a[n+1];
for(int i=1;i<=n;++i)
{
cin>>a[i];
c[a[i]]++;
}
vector<int> ans;
for(int i=1;i<=100000;++i)
c[i]=c[i]+c[i-1];
for(int i=1;i<=q;++i)
{
int l,r;
cin>>l>>r;
ans.push_back(c[r]-c[l-1]);
}
for(auto r:ans)
cout<<r<<"\n";
#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: Ronaldo has challenged Messi to beat his team in the upcoming βFriendlyβ fixture. But both these legends are tired of the original football rules, so they decided to play Football with a twist. Each player is assigned an ID, from 1 to 10^6. Initially Ronaldo has the ball in his posession. Given a sequence of N passes, help Messi Know which ID player has the ball, after N passes.
Note: Passes are of two types :
i) P ID, which means the player currently having the ball passes it to Player with identity ID.
ii) B, which means the player currently having the ball passes it back to the Player he got the Pass From.
Also, It is guaranteed that the given order of passes will be a valid order.The first line of input contains number of testcases T. The 1st line of each testcase, contains two integers, N and ID1, denoting the total number of passes and the ID of Ronaldo. Respectively. Each of the next N lines, contains the information of a Pass which can be either of the above two types, i.e:
1) P ID
2) B
Constraints
1 <= T <= 100
1 <= N <= 10^5
1 <= IDs <= 10^6
Sum of N for every test case is less than 10^6For each testcase you need to print the ID of the Player having the ball after N passes.Input :
2
3 1
P 13
P 14
B
5 1
P 12
P 13
P 14
B
B
Output :
13
14
Explanation :
Testcase 1: Initially, the ball is with Ronaldo, having ID 1.
In the first pass, he passes the ball to Player with ID 13.
In the Second Pass, the player currently having the ball, ie Player with ID 13, passes it to player with ID 14.
In the last pass the player currently having the ball, ie Player with ID 14 passed the ball back to the player from whom he got the Pass, i.e the ball is passed back to Player with Player ID 13, as Player ID 13 had passed the ball to player ID 14 in the previous pass.
Testcase 2: Initially, the ball is with Ronaldo, having ID 1.
In the first pass he passes the ball to player with ID 12.
In the second pass, the second player passes the ball to palyer with ID 13, again the player with ID 13 passes the ball to player with ID 14.
Now, player with ID 14 passed back the ball to 13, and again 13 passes back the ball to 14., 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().trim());
while (t-- > 0) {
String[] line = br.readLine().trim().split(" ");
int n = Integer.parseInt(line[0]);
int curr = Integer.parseInt(line[1]);
int prev = curr;
while (n-- > 0) {
String[] currLine = br.readLine().trim().split(" ");
if (currLine[0].equals("P")) {
prev = curr;
curr = Integer.parseInt(currLine[1]);
}
if (currLine[0].equals("B")) {
int temp = curr;
curr = prev;
prev = temp;
}
}
System.out.println(curr);
System.gc();
}
br.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ronaldo has challenged Messi to beat his team in the upcoming βFriendlyβ fixture. But both these legends are tired of the original football rules, so they decided to play Football with a twist. Each player is assigned an ID, from 1 to 10^6. Initially Ronaldo has the ball in his posession. Given a sequence of N passes, help Messi Know which ID player has the ball, after N passes.
Note: Passes are of two types :
i) P ID, which means the player currently having the ball passes it to Player with identity ID.
ii) B, which means the player currently having the ball passes it back to the Player he got the Pass From.
Also, It is guaranteed that the given order of passes will be a valid order.The first line of input contains number of testcases T. The 1st line of each testcase, contains two integers, N and ID1, denoting the total number of passes and the ID of Ronaldo. Respectively. Each of the next N lines, contains the information of a Pass which can be either of the above two types, i.e:
1) P ID
2) B
Constraints
1 <= T <= 100
1 <= N <= 10^5
1 <= IDs <= 10^6
Sum of N for every test case is less than 10^6For each testcase you need to print the ID of the Player having the ball after N passes.Input :
2
3 1
P 13
P 14
B
5 1
P 12
P 13
P 14
B
B
Output :
13
14
Explanation :
Testcase 1: Initially, the ball is with Ronaldo, having ID 1.
In the first pass, he passes the ball to Player with ID 13.
In the Second Pass, the player currently having the ball, ie Player with ID 13, passes it to player with ID 14.
In the last pass the player currently having the ball, ie Player with ID 14 passed the ball back to the player from whom he got the Pass, i.e the ball is passed back to Player with Player ID 13, as Player ID 13 had passed the ball to player ID 14 in the previous pass.
Testcase 2: Initially, the ball is with Ronaldo, having ID 1.
In the first pass he passes the ball to player with ID 12.
In the second pass, the second player passes the ball to palyer with ID 13, again the player with ID 13 passes the ball to player with ID 14.
Now, player with ID 14 passed back the ball to 13, and again 13 passes back the ball to 14., I have written this Solution Code: for i in range(int(input())):
N, ID = map(int,input().split())
pre = 0
for i in range(N):
arr = input().split()
if len(arr)==2:
pre,ID = ID,arr[1]
else:
ID,pre = pre,ID
print(ID) if pre else print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ronaldo has challenged Messi to beat his team in the upcoming βFriendlyβ fixture. But both these legends are tired of the original football rules, so they decided to play Football with a twist. Each player is assigned an ID, from 1 to 10^6. Initially Ronaldo has the ball in his posession. Given a sequence of N passes, help Messi Know which ID player has the ball, after N passes.
Note: Passes are of two types :
i) P ID, which means the player currently having the ball passes it to Player with identity ID.
ii) B, which means the player currently having the ball passes it back to the Player he got the Pass From.
Also, It is guaranteed that the given order of passes will be a valid order.The first line of input contains number of testcases T. The 1st line of each testcase, contains two integers, N and ID1, denoting the total number of passes and the ID of Ronaldo. Respectively. Each of the next N lines, contains the information of a Pass which can be either of the above two types, i.e:
1) P ID
2) B
Constraints
1 <= T <= 100
1 <= N <= 10^5
1 <= IDs <= 10^6
Sum of N for every test case is less than 10^6For each testcase you need to print the ID of the Player having the ball after N passes.Input :
2
3 1
P 13
P 14
B
5 1
P 12
P 13
P 14
B
B
Output :
13
14
Explanation :
Testcase 1: Initially, the ball is with Ronaldo, having ID 1.
In the first pass, he passes the ball to Player with ID 13.
In the Second Pass, the player currently having the ball, ie Player with ID 13, passes it to player with ID 14.
In the last pass the player currently having the ball, ie Player with ID 14 passed the ball back to the player from whom he got the Pass, i.e the ball is passed back to Player with Player ID 13, as Player ID 13 had passed the ball to player ID 14 in the previous pass.
Testcase 2: Initially, the ball is with Ronaldo, having ID 1.
In the first pass he passes the ball to player with ID 12.
In the second pass, the second player passes the ball to palyer with ID 13, again the player with ID 13 passes the ball to player with ID 14.
Now, player with ID 14 passed back the ball to 13, and again 13 passes back the ball to 14., 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, id; cin >> n >> id;
int pre = 0, cur = id;
for(int i = 1; i <= n; i++){
char c; cin >> c;
if(c == 'P'){
int x; cin >> x;
pre = cur;
cur = x;
}
else{
swap(pre, cur);
}
}
cout << cur << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, super primes are those integers from 1 to N whose multiples (other than themselves) do no exist in the range [1, N].
Your task is to generate all super primes <= N in sorted order.
</b>Note: Super primes are not related to primes in any way.</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>SuperPrime()</b> that takes the integer N as a parameter.
Constraints:-
2 < = N <= 1000Printing will be done by the driver code you just need to complete the generator function.Sample Input:-
5
Sample Output:-
3 4 5
Sample Input:-
4
Sample Output:-
3 4, I have written this Solution Code: public static void SuperPrimes(int n){
int x = n/2+1;
for(int i=x ; i<=n ; i++){
out.printf("%d ",i);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, super primes are those integers from 1 to N whose multiples (other than themselves) do no exist in the range [1, N].
Your task is to generate all super primes <= N in sorted order.
</b>Note: Super primes are not related to primes in any way.</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>SuperPrime()</b> that takes the integer N as a parameter.
Constraints:-
2 < = N <= 1000Printing will be done by the driver code you just need to complete the generator function.Sample Input:-
5
Sample Output:-
3 4 5
Sample Input:-
4
Sample Output:-
3 4, I have written this Solution Code: def SuperPrimes(N):
for i in range (int(N/2)+1,N+1):
yield i
return
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a Binary Search Tree. The task is to find the <b>minimum element</b> in this given BST. If the tree is empty, there is no minimum element, so print <b>-1</b> in that case.<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>minValue()</b> that takes "root" node as parameter and returns the minimum value(-1 in case tree is empty). The printing is done by the driver code.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^3
1 <= node values <= 10^4
<b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the minimum element in BST.Input:
2
5 4 6 3 N N 7 1
9 N 10 N 11
Output:
1
9
Explanation:
Testcase 1: We construct the following BST by inserting given values one by one in an empty BST.
5
/ \
4 6
/ \
3 7
/
1
The minimum value in the given BST is 1.
Testcase 2: We construct the following BST by inserting given values one by one in an empty BST.
9
\
10
\
11
The minimum value in the given BST is 9., I have written this Solution Code:
static int minValue(Node node)
{
// base case
if(node==null)
return -1;
Node current = node;
// iterate left till node is not null
while (current.left != null)
{
current = current.left;
}
return (current.data);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For an integer N, your task is to calculate sum of first N natural numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to worry about input. You just have to complete the function <b>sum()</b> which takes the integer N as a parameter.
Constraints:
1 <= N < = 100000000Print the sum of first N natural numbers.Sample Input:-
5
Sample Output:-
15
Sample Input:-
3
Sample Output:-
6, I have written this Solution Code:
static void sum(int N){
long x=N;
x=x*(x+1);
x=x/2;
System.out.print(x);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: As they were totally exhausted with the daily chores, Ketani and Nilswap decided to play a game.They get alternate turns in the game and Ketani starts the game. The game consists of a tree containing N nodes numbered 1 to N. On each turn the person chooses a node of the tree that is not yet numbered. If it's Ketani's turn, he writes an odd number to this node whereas if it's Nilswap's turn, he writes an even number to this node.
After the entire tree has been numbered, all the odd numbered nodes that are adjacent to an even numbered node turn even (instantaneous, no propagation).
If the tree contains any odd number in the end, Ketani wins otherwise Nilswap wins. You need to output the name of the winner.
Note: Initially none of the nodes contains a number. Both players play optimally.The first line of the input contains an integer N, the number of nodes in the tree.
The next N-1 lines contain two integers u, v indicating there is an edge between u and v.
Constraints
2 <= N <= 100000
1 <= u, v <= 100000
u != v
The given edges form a tree.Output a single string, the winner of the game.Sample Input 1
3
1 2
2 3
Sample Output 1
Ketani
Sample Input 2
2
1 2
Sample Output 2
Nilswap
Explanation 1:
-> Ketani writes an odd number to node 2.
-> Nilswap writes an even number to node 3.
-> Ketani writes an odd number to node 1.
-> After this, node 2 converts to an even number. But node 1 is still white. So Ketani wins., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 100005;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
vector<int> adj[N];
bool ans;
bool dfs(int u, int par = 0) {
int cnt = 0;
for (auto v: adj[u])
if (v != par)
cnt += dfs(v, u);
if (cnt >= 2) {
ans = true;
return false;
}
return 1 - cnt;
}
signed main(){
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
fast
int n; cin >> n;
for (int i = 1; i < n; i++) {
int v, u;
cin >> v >> u;
adj[v].pb(u);
adj[u].pb(v);;
}
ans |= dfs(1);
if(ans){
cout<<"Ketani";
}
else{
cout<<"Nilswap";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array and Q queries. Your task is to perform these operations:-
enqueue: this operation will add an element to your current queue.
dequeue: this operation will delete the element from the starting of the queue
displayfront: this operation will print the element presented at the frontUser task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>enqueue()</b>:- that takes the integer to be added and the maximum size of array as parameter.
<b>dequeue()</b>:- that takes the queue as parameter.
<b>displayfront()</b> :- that takes the queue as parameter.
Constraints:
1 <= Q(Number of queries) <= 10<sup>3</sup>
<b> Custom Input:</b>
First line of input should contains two integer number of queries Q and the size of the array N. Next Q lines contains any of the given three operations:-
enqueue x
dequeue
displayfrontDuring a dequeue operation if queue is empty you need to print "Queue is empty", during enqueue operation if the maximum size of array is reached you need to print "Queue is full" and during displayfront operation you need to print the element which is at the front and if the queue is empty you need to print "Queue is empty".
Note:-Each msg or element is to be printed on a new line
Sample Input:-
8 2
displayfront
enqueue 2
displayfront
enqueue 4
displayfront
dequeue
displayfront
enqueue 5
Sample Output:-
Queue is empty
2
2
4
Queue is full
Explanation:-here size of given array is 2 so when last enqueue operation perfomed the array was already full so we display the msg "Queue is full".
Sample input:
5 5
enqueue 4
enqueue 5
displayfront
dequeue
displayfront
Sample output:-
4
5, I have written this Solution Code: public static void enqueue(int x,int k)
{
if (rear >= k) {
System.out.println("Queue is full");
}
else {
a[rear] = x;
rear++;
}
}
public static void dequeue()
{
if (rear <= front) {
System.out.println("Queue is empty");
}
else {
front++;
}
}
public static void displayfront()
{
if (rear<=front) {
System.out.println("Queue is empty");
}
else {
int x = a[front];
System.out.println(x);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter.
Constraints:
1 <= T <= 100
1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input:
3
3
5
6
Sample Output:
0
5
9
Explanation:
For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code: static int numberOfDiagonal(int N){
if(N<=3){return 0;}
return (N*(N-3))/2;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter.
Constraints:
1 <= T <= 100
1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input:
3
3
5
6
Sample Output:
0
5
9
Explanation:
For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code:
int numberOfDiagonals(int n){
if(n<=3){return 0;}
return (n*(n-3))/2;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter.
Constraints:
1 <= T <= 100
1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input:
3
3
5
6
Sample Output:
0
5
9
Explanation:
For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code: def numberOfDiagonals(n):
if n <=3:
return 0
return (n*(n-3))//2
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter.
Constraints:
1 <= T <= 100
1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input:
3
3
5
6
Sample Output:
0
5
9
Explanation:
For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code:
int numberOfDiagonals(int n){
if(n<=3){return 0;}
return (n*(n-3))/2;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Create a new class for a bank account (BankAccount)
Create fields for the balance(balance), customer name(name).
Create constructor with two parameter as balance and name
Create two additional methods
1. To allow the customer to deposit funds named depositFund() with one parameter as fund to be added (this should increment the balance field).
2. To allow the customer to withdraw funds named withdrawFund() with one parameter as fund to be withdrawn from account and should return boolean as if withdraw went successful else false. This should deduct from the balance field, but not allow
the withdrawal to complete if their are insufficient funds.
Note: Each methods and variable should be publicYou don't have to take any input, You only have to write class <b>BankAccount</b>.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Input:
class BankAccount{
// if your code works fine for the testert
}
Sample Output:
Correct, I have written this Solution Code: class BankAccount{
public int balance;
public String name;
BankAccount(int _balance,String _name){
balance=_balance;
name =_name;
}
public void depositFund(int fund){
balance += fund;
}
public boolean withdrawFund(int fund){
if(fund <= balance){
balance -= fund;
return true;
}
return false;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Create a new class for a bank account (BankAccount)
Create fields for the balance(balance), customer name(name).
Create constructor with two parameter as balance and name
Create two additional methods
1. To allow the customer to deposit funds named depositFund() with one parameter as fund to be added (this should increment the balance field).
2. To allow the customer to withdraw funds named withdrawFund() with one parameter as fund to be withdrawn from account and should return boolean as if withdraw went successful else false. This should deduct from the balance field, but not allow
the withdrawal to complete if their are insufficient funds.
Note: Each methods and variable should be publicYou don't have to take any input, You only have to write class <b>BankAccount</b>.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Input:
class BankAccount{
// if your code works fine for the testert
}
Sample Output:
Correct, I have written this Solution Code: class Bank_Account:
def __init__(self,b,n):
self.balance=b
self.name=n
def depositFund(self,b):
self.balance += b
def withdrawFund(self,f):
if self.balance>=f:
self.balance-=f
return True
else:
return False
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:-
1. Think of a number X(don't tell Sara)
2. Add A(Given by Sara) to it.
3. Double the sum in your mind.
4. Add an even number B(Given by Sara) to it.
5. Half the amount
6. Subtract the initial number which you had taken from the sum
After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her?
<b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b>
<b>Constraints</b>:-
1 <= A, B <= 1000Print the resulting amountSample Input:-
3 4
Sample Output:-
5
Sample Input:-
8 4
Sample Output:-
10, I have written this Solution Code: void magicTrick(int a, int b){
cout<<a+b/2;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:-
1. Think of a number X(don't tell Sara)
2. Add A(Given by Sara) to it.
3. Double the sum in your mind.
4. Add an even number B(Given by Sara) to it.
5. Half the amount
6. Subtract the initial number which you had taken from the sum
After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her?
<b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b>
<b>Constraints</b>:-
1 <= A, B <= 1000Print the resulting amountSample Input:-
3 4
Sample Output:-
5
Sample Input:-
8 4
Sample Output:-
10, I have written this Solution Code: static void magicTrick(int a, int b){
System.out.println(a + b/2);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:-
1. Think of a number X(don't tell Sara)
2. Add A(Given by Sara) to it.
3. Double the sum in your mind.
4. Add an even number B(Given by Sara) to it.
5. Half the amount
6. Subtract the initial number which you had taken from the sum
After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her?
<b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b>
<b>Constraints</b>:-
1 <= A, B <= 1000Print the resulting amountSample Input:-
3 4
Sample Output:-
5
Sample Input:-
8 4
Sample Output:-
10, I have written this Solution Code: A,B = map(int,input().split(' '))
C = A+B//2
print(C)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not.
<b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements.
<b>Constraints:</b>
1 ≤ T ≤ 10
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 10<sup>9</sup>
1 ≤ arr[i] ≤ 10<sup>9</sup>
<b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input:
2
5 6
1 2 3 4 6
5 2
1 3 4 5 6
Sample Output:
1
-1, I have written this Solution Code: static int isPresent(long arr[], int n, long k)
{
int left = 0;
int right = n-1;
int res = -1;
while(left<=right){
int mid = (left+right)/2;
if(arr[mid] == k){
res = 1;
break;
}else if(arr[mid] < k){
left = mid + 1;
}else{
right = mid - 1;
}
}
return res;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not.
<b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements.
<b>Constraints:</b>
1 ≤ T ≤ 10
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 10<sup>9</sup>
1 ≤ arr[i] ≤ 10<sup>9</sup>
<b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input:
2
5 6
1 2 3 4 6
5 2
1 3 4 5 6
Sample Output:
1
-1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
unordered_map<long long,int> m;
long k;
cin>>k;
long long a;
for(int i=0;i<n;i++){
cin>>a;
m[a]++;
}
if(m.find(k)!=m.end()){
cout<<1<<endl;
}
else{
cout<<-1<<endl;
}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not.
<b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements.
<b>Constraints:</b>
1 ≤ T ≤ 10
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 10<sup>9</sup>
1 ≤ arr[i] ≤ 10<sup>9</sup>
<b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input:
2
5 6
1 2 3 4 6
5 2
1 3 4 5 6
Sample Output:
1
-1, I have written this Solution Code: def binary_search(arr, low, high, x):
if high >= low:
mid = (high + low) // 2
if arr[mid] == x:
return 1
elif arr[mid] > x:
return binary_search(arr, low, mid - 1, x)
else:
return binary_search(arr, mid + 1, high, x)
else:
return -1
def position(n,arr,x):
return binary_search(arr,0,n-1,x)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not.
<b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements.
<b>Constraints:</b>
1 ≤ T ≤ 10
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 10<sup>9</sup>
1 ≤ arr[i] ≤ 10<sup>9</sup>
<b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input:
2
5 6
1 2 3 4 6
5 2
1 3 4 5 6
Sample Output:
1
-1, I have written this Solution Code: // arr is they array to search from
// x is target
function binSearch(arr, x) {
// write code here
// do not console.log
// return the 1 or -1
let l = 0;
let r = arr.length - 1;
let mid;
while (r >= l) {
mid = l + Math.floor((r - l) / 2);
// If the element is present at the middle
// itself
if (arr[mid] == x)
return 1;
// If element is smaller than mid, then
// it can only be present in left subarray
if (arr[mid] > x)
r = mid - 1;
// Else the element can only be present
// in right subarray
else
l = mid + 1;
}
// We reach here when element is not
// present in array
return -1;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int len = Integer.parseInt(br.readLine());
char[] str = new char[len];
for(int i = 0; i < len; i++){
if(i%2 == 0){
str[i] = 'a';
} else{
str[i] = 'b';
}
}
System.out.println(str);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
#define rep(i,n) for (int i=0; i<(n); i++)
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
string s(n,'a');
for(int i=1;i<n;i+=2)
s[i]='b';
cout<<s;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, construct a string of length N such that no two adjacent characters are the same. Among all possible strings, find the lexicographically minimum string.
Note: You can use only lowercase characters from 'a' to 'z'.The first and only line of input contains an integer N.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>Print the required string.Sample Input 1:
1
Sample Output 1:
a
Sample Input 2:
2
Sample Output 2:
ab, I have written this Solution Code: a="ab"
inp = int(input())
print(a*(inp//2)+a[0:inp%2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N and K, find the lexicographically smallest string of length N using only the first K lowercase letters of the alphabet such that each letter is used at least once and no two adjacent characters are equal.
If such a string doesn't exist, print -1.The first line of input contains a single integer, T (1 <= T <= 100).
Then T lines follow, each containing two space-separated integers, N (1 <= N <= 10<sup>5</sup>) and K (1 <= K <= 26).
It is guaranteed that sum of N over all test cases does not exceed 10<sup>6</sup>For each test case, output its answer in a new line.Sample Input:
2
2 3
3 2
Sample Output:
-1
aba, 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));
BufferedWriter bo=new BufferedWriter(new OutputStreamWriter(System.out));
int t;
try{
t=Integer.parseInt(br.readLine());
}
catch(Exception e)
{
return;
}
while(t-->0)
{
String[] g=br.readLine().split(" ");
int n=Integer.parseInt(g[0]);
int k=Integer.parseInt(g[1]);
if(k>n || (k==1) || (k>26))
{
if(n==1 && k==1)
bo.write("a\n");
else
bo.write(-1+"\n");
}
else
{
int extra=k-2;
boolean check=true;
while(n>extra)
{
if(check==true)
bo.write("a");
else
bo.write("b");
if(check==true)
check=false;
else
check=true;
n--;
}
for(int i=0;i<extra;i++)
bo.write((char)(i+99));
bo.write("\n");
}
}
bo.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N and K, find the lexicographically smallest string of length N using only the first K lowercase letters of the alphabet such that each letter is used at least once and no two adjacent characters are equal.
If such a string doesn't exist, print -1.The first line of input contains a single integer, T (1 <= T <= 100).
Then T lines follow, each containing two space-separated integers, N (1 <= N <= 10<sup>5</sup>) and K (1 <= K <= 26).
It is guaranteed that sum of N over all test cases does not exceed 10<sup>6</sup>For each test case, output its answer in a new line.Sample Input:
2
2 3
3 2
Sample Output:
-1
aba, I have written this Solution Code: t=int(input())
for tt in range(t):
n,k=map(int,input().split())
if (k==1 and n>1) or (k>n):
print(-1)
continue
s="abcdefghijklmnopqrstuvwxyz"
ss="ab"
if (n-k)%2==0:
a=ss*((n-k)//2)+s[:k]
else:
a=ss*((n-k)//2)+s[:2]+"a"+s[2:k]
print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N and K, find the lexicographically smallest string of length N using only the first K lowercase letters of the alphabet such that each letter is used at least once and no two adjacent characters are equal.
If such a string doesn't exist, print -1.The first line of input contains a single integer, T (1 <= T <= 100).
Then T lines follow, each containing two space-separated integers, N (1 <= N <= 10<sup>5</sup>) and K (1 <= K <= 26).
It is guaranteed that sum of N over all test cases does not exceed 10<sup>6</sup>For each test case, output its answer in a new line.Sample Input:
2
2 3
3 2
Sample Output:
-1
aba, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef unsigned long long int ull;
const long double PI = acos(-1);
const ll mod=1e9+7;
const ll mod1=998244353;
const int inf = 1e9;
const ll INF=1e18;
void precompute(){
}
void TEST_CASE(){
int n,k;
cin >> n >> k;
if(k==1){
if(n>1){
cout << -1 << endl;
}else{
cout << 'a' << endl;
}
}else if(n<k){
cout << -1 << endl;
}else if(n==k){
string s="";
for(int i=0 ; i<k ; i++){
s+=('a'+i);
}
cout << s << endl;
}else{
string s="";
for(int i=0 ; i<(n-k+2) ; i++){
if(i%2){
s+="b";
}else{
s+="a";
}
}
for(int i=2 ; i<k ; i++){
s+=('a'+i);
}
cout << s << endl;
}
}
signed main(){
fast;
//freopen ("INPUT.txt","r",stdin);
//freopen ("OUTPUT.txt","w",stdout);
int test=1,TEST=1;
precompute();
cin >> test;
while(test--){
TEST_CASE();
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<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>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code:
int mythOrFact(int N){
int prime =1;
int cnt = N+1;
for(int i=2;i<N;i++){
if(N%i==0){cnt+=i;prime=0;}
}
int p = 3*N;
p/=2;
if((cnt<=p && prime==1) || (cnt>p && prime==0) ){return 1;}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<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>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code:
int mythOrFact(int N){
int prime =1;
int cnt = N+1;
for(int i=2;i<N;i++){
if(N%i==0){cnt+=i;prime=0;}
}
int p = 3*N;
p/=2;
if((cnt<=p && prime==1) || (cnt>p && prime==0) ){return 1;}
return 0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<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>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code: static int mythOrFact(int N){
int prime =1;
int cnt = N+1;
for(int i=2;i<N;i++){
if(N%i==0){cnt+=i;prime=0;}
}
int p = 3*N;
p/=2;
if((cnt<=p && prime==1) || (cnt>p && prime==0) ){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<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>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code: def mythOrFact(N):
prime=1
cnt=N+1
for i in range (2,N):
if N%i==0:
prime=0
cnt=cnt+i
x = 3*N
x=x//2
if(cnt <= x and prime==1) or (cnt>x and prime==0):
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a 2*N matrix in which each cell contains some candies in it. You are at the top left corner of the matrix and want to reach the bottom right corner of the matrix i. e from (1, 1) to (2, N). You can only move right or down. You have to find the maximum number of candies you can collect in your journey.The first line of input contains a single integer N. The second line of input contains N spaces separated integers. The last line of input contains N space-separated integers.
<b>Constraints:-</b>
2 <= N <= 10000
1 <= Matrix[i][j] <= 100000Print the maximum amount of candies you can have at the end of your journey.Sample Input 1:-
5
1 3 5 6 2
2 4 8 4 2
Sample Output 1:-
23
Sample Input 2:-
4
1 1 1 1
1 1 1 1
Sample Output 2:-
5, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin>>n;
int a[n][2];
for(int i=0;i<n;i++){
cin>>a[i][0];
}
for(int i=0;i<n;i++){
cin>>a[i][1];
}
for(int i=1;i<n;i++){
a[i][0]+=a[i-1][0];
}
for(int i = n-2;i>=0;i--){
a[i][1]+=a[i+1][1];
}
int ans=0;
for(int i=0;i<n;i++){
ans=max(a[i][0]+a[i][1],ans);
}
cout<<ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You must be familiar with various types of operators. One of the most commonly used operators in any language are increment and decrement operators. Given two numbers X and Y. Your task is to print the value of X decremented by 1 and value of Y after incremented by 1.The first line of the input contains two integers X and Y.
<b>Constraints:</b>
1 ≤ X, Y ≤ 10000You need to perform the task as mentioned in the question, and finally, print the result separated by a space.Sample Input 1:
4 5
Sample Output 1:
3 6
Sample Input 2:
5 6
Sample Output 2:
4 7, 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 x = sc.nextInt();
int y = sc.nextInt();
x--;
y++;
System.out.print(x);
System.out.print(" ");
System.out.print(y);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You must be familiar with various types of operators. One of the most commonly used operators in any language are increment and decrement operators. Given two numbers X and Y. Your task is to print the value of X decremented by 1 and value of Y after incremented by 1.The first line of the input contains two integers X and Y.
<b>Constraints:</b>
1 ≤ X, Y ≤ 10000You need to perform the task as mentioned in the question, and finally, print the result separated by a space.Sample Input 1:
4 5
Sample Output 1:
3 6
Sample Input 2:
5 6
Sample Output 2:
4 7, I have written this Solution Code: def incremental_decremental(x, y):
x -= 1
y += 1
print(x, y, end =' ')
def main():
input1 = input().split()
x = int(input1[0])
y = int(input1[1])
#z = int(input1[2])
incremental_decremental(x, y)
if __name__ == '__main__':
main(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them.
If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T β the number of test cases.
Each of the next T lines contains 3 space separated integers A, B and C respectively.
<b> Constraints: </b>
1 β€ T β€ 10
0 β€ A, B, C β€ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" β the answer to the i<sup>th</sup> test case.Sample Input 1:
2
3 4 2
2 2 2
Sample Output 1:
No
Yes
Sample Explanation 1:
For the first test case, there is no possible way to make all the elements zero.
For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.hasMoreTokens()){
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str="";
try {
str=br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("").append(String.valueOf(object));
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
public static void main(String[] args) throws Exception{
try {
FastReader in=new FastReader();
FastWriter out = new FastWriter();
int testCases=in.nextInt();
while(testCases-- > 0) {
int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
while ((a>0&&b>0)||(a>0&&c>0)||(b>0&&c>0)) {
if (a >= b && a >= c) {
a--;
if (b >= c) {
b--;
}
else{
c--;
}
}
else if (b >= a && b >= c) {
b--;
if (a >= c) {
a--;
}
else{
c--;
}
}
else{
c--;
if (a >= b) {
a--;
}
else{
b--;
}
}
}
if (a==0&&b==0&&c==0){
out.println("Yes");
}
else{
out.println("No");
}
}
out.close();
} catch (Exception e) {
return;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them.
If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T β the number of test cases.
Each of the next T lines contains 3 space separated integers A, B and C respectively.
<b> Constraints: </b>
1 β€ T β€ 10
0 β€ A, B, C β€ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" β the answer to the i<sup>th</sup> test case.Sample Input 1:
2
3 4 2
2 2 2
Sample Output 1:
No
Yes
Sample Explanation 1:
For the first test case, there is no possible way to make all the elements zero.
For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), I have written this Solution Code: t=int(input())
for i in range(t):
arr=list(map(int,input().split()))
a,b,c=sorted(arr)
if((a+b+c)%2):
print("No")
elif ((a+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 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them.
If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T β the number of test cases.
Each of the next T lines contains 3 space separated integers A, B and C respectively.
<b> Constraints: </b>
1 β€ T β€ 10
0 β€ A, B, C β€ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" β the answer to the i<sup>th</sup> test case.Sample Input 1:
2
3 4 2
2 2 2
Sample Output 1:
No
Yes
Sample Explanation 1:
For the first test case, there is no possible way to make all the elements zero.
For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), I have written this Solution Code:
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
long long powm(long long a, long long b,long long mod) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a %mod;
a = a * a %mod;
b >>= 1;
}
return res;
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
if(fopen("input.txt","r"))
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
#endif
int t;
cin>>t;
while(t--)
{
int a,b,c;
cin>>a>>b>>c;
if(a>b+c||b>a+c||c>a+b)
cout<<"No\n";
else
{
int sum=a+b+c;
if(sum%2)
cout<<"No\n";
else
cout<<"Yes\n";
}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to check whether the given number is <b>Palindrome</b> or not. A number is said to be Palindrome when it reads the same from backward as forward.User task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isPalindrome()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 9999You need to return "true" is the number is palindrome otherwise "false".Sample Input:
5
Sample Output:
true
Sample Input:
121
Sample Output:
true, I have written this Solution Code: static boolean isPalindrome(int N)
{
int sum = 0;
int rev = N;
while(N > 0)
{
int digit = N%10;
sum = sum*10+digit;
N = N/10;
}
if(rev == sum)
return true;
else return false;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to check whether the given number is <b>Palindrome</b> or not. A number is said to be Palindrome when it reads the same from backward as forward.User task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isPalindrome()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 9999You need to return "true" is the number is palindrome otherwise "false".Sample Input:
5
Sample Output:
true
Sample Input:
121
Sample Output:
true, I have written this Solution Code: def isPalindrome(N):
sum1 = 0
rev = N
while(N > 0):
digit = N%10
sum1 = sum1*10+digit
N = N//10
if(rev == sum1):
return True
return False, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Insertion is a basic but frequently used operation. Arrays in most languages cannnot be dynamically shrinked or expanded. Here, we will work with such arrays and try to insert an element at the end of array.
You are given an array arr. The size of the array is N. You need to insert an element at its end and print this newly modified array.The first line of input contains T denoting the number of testcases.
T testcases follow. Each testcase contains two lines of input.
The first line contains size of the array denoted by N and element to be inserted.
The third line contains N elements separated by spaces.
Constraints:
1 <= T <= 20
2 <= N <= 10000
0 <= element, arri <= 10^6For each testcase, in a new line, print the modified array.Input:
2
5 90
1 2 3 4 5
3 50
1 2 3
Output:
1 2 3 4 5 90
1 2 3 50
Explanation:
Testcase 1: After inserting 90 at end, we have array elements as 1 2 3 4 5 90.
Testcase 2: After inserting 50 at end, we have array elements as 1 2 3 50., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--) {
long int n, el;
cin>>n>>el;
long int arr[n+1];
for(long int i=0; i<n; i++) {
cin>>arr[i];
}
arr[n] = el;
for(long int i=0; i<=n; i++) {
cout<<arr[i];
if (i != n) {
cout<<" ";
}
else if(t != 0) {
cout<<endl;
}
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Insertion is a basic but frequently used operation. Arrays in most languages cannnot be dynamically shrinked or expanded. Here, we will work with such arrays and try to insert an element at the end of array.
You are given an array arr. The size of the array is N. You need to insert an element at its end and print this newly modified array.The first line of input contains T denoting the number of testcases.
T testcases follow. Each testcase contains two lines of input.
The first line contains size of the array denoted by N and element to be inserted.
The third line contains N elements separated by spaces.
Constraints:
1 <= T <= 20
2 <= N <= 10000
0 <= element, arri <= 10^6For each testcase, in a new line, print the modified array.Input:
2
5 90
1 2 3 4 5
3 50
1 2 3
Output:
1 2 3 4 5 90
1 2 3 50
Explanation:
Testcase 1: After inserting 90 at end, we have array elements as 1 2 3 4 5 90.
Testcase 2: After inserting 50 at end, we have array elements as 1 2 3 50., I have written this Solution Code: t=int(input())
while t>0:
t-=1
li = list(map(int,input().strip().split()))
n=li[0]
num=li[1]
a= list(map(int,input().strip().split()))
a.insert(len(a),num)
for i in a:
print(i,end=" ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Insertion is a basic but frequently used operation. Arrays in most languages cannnot be dynamically shrinked or expanded. Here, we will work with such arrays and try to insert an element at the end of array.
You are given an array arr. The size of the array is N. You need to insert an element at its end and print this newly modified array.The first line of input contains T denoting the number of testcases.
T testcases follow. Each testcase contains two lines of input.
The first line contains size of the array denoted by N and element to be inserted.
The third line contains N elements separated by spaces.
Constraints:
1 <= T <= 20
2 <= N <= 10000
0 <= element, arri <= 10^6For each testcase, in a new line, print the modified array.Input:
2
5 90
1 2 3 4 5
3 50
1 2 3
Output:
1 2 3 4 5 90
1 2 3 50
Explanation:
Testcase 1: After inserting 90 at end, we have array elements as 1 2 3 4 5 90.
Testcase 2: After inserting 50 at end, we have array elements as 1 2 3 50., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n =Integer.parseInt(br.readLine().trim());
while(n-->0){
String str[]=br.readLine().trim().split(" ");
String newel =br.readLine().trim()+" "+str[1];
System.out.println(newel);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In a cricket tournament, there are n teams. Each team plays twice against every other team which includes one home match and another away match. Find out the total number of matches played in the tournament.The input consists of an integer n.
<b>Constraints</b>
1 ≤ n ≤ 10<sup>5</sup>Print the total number of matches played in the tournament.<b>Sample Input 1</b>
8
<b>Sample Output 1</b>
56
<b>Sample Input 1</b>
10
<b>Sample Output 1</b>
90, I have written this Solution Code: #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define int long long int
#define endl '\n'
void fastio()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
using namespace __gnu_pbds;
const int M = 1e9 + 7;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// Author:Abhas
void solution()
{
int n;
cin >> n;
cout << n * (n - 1) << endl;
}
signed main()
{
fastio();
int t = 1;
// cin >> t;
while (t--)
{
solution();
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is an integer array nums having n integers, given as input. Find the sum of all subarrays of given array nums and Return it.There is an integer n (size of array nums) given as input.
In the Second line, n space-separated integers are given as input.
<b>Constraints</b>
1 ≤ n ≤ 10<sup>5</sup>
0 ≤ nums[i] ≤ 5*10<sup>4</sup>
0 ≤ i ≤ n-1Return the sum of all the subarrays of given array nums.Sample Input:
3
1 2 3
Sample Output:
20
Explanation :
{1} + {2} + {3} + {2 + 3} + {1 + 2} + {1 + 2 + 3} = 20, I have written this Solution Code: import java.io.*;
import java.security.KeyStore.Entry;
import java.util.*;
public class Main{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
long ans=0;
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
for(int i=0;i<n;i++){
ans+=(long)(i+1)*(n-i)*arr[i];
}
System.out.println(ans);
return;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, A of N integers. Find the product of maximum values for every subarray of size K. Print the answer modulo 10<sup>9</sup>+7.
A subarray is any contiguous sequence of elements in an array.The first line contains two integers N and K, denoting the size of the array and the size of the subarray respectively.
The next line contains N integers denoting the elements of the array.
<b>Constarints</b>
1 <= K <= N <= 1000000
1 <= A[i] <= 1000000Print a single integer denoting the product of maximums for every subarray of size K modulo 1000000007Sample Input 1:
6 4
1 5 2 3 6 4
Sample Output 1:
180
<b>Explanation:</b>
For subarray [1, 5, 2, 3], maximum = 5
For subarray [5, 2, 3, 6], maximum = 6
For subarray [2, 3, 6, 4], maximum = 6
Therefore, ans = 5*6*6 = 180, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
Reader sc=new Reader();
int n=sc.nextInt();
int b=sc.nextInt();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int j, max;
long mul=1;
Deque<Integer> dq= new LinkedList<Integer>();
for (int i = 0;i<b;i++)
{
while (!dq.isEmpty() && a[i] >=a[dq.peekLast()])
dq.removeLast();
dq.addLast(i);
}
mul=((mul%1000000007)*(a[dq.peek()]%1000000007))%1000000007;
for (int i=b; i < n;i++)
{
while ((!dq.isEmpty()) && dq.peek() <=i-b)
dq.removeFirst();
while ((!dq.isEmpty()) && a[i]>=a[dq.peekLast()])
dq.removeLast();
dq.addLast(i);
mul=((mul%1000000007)*(a[dq.peek()]%1000000007))%1000000007;
}
System.out.println(mul%1000000007);
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, A of N integers. Find the product of maximum values for every subarray of size K. Print the answer modulo 10<sup>9</sup>+7.
A subarray is any contiguous sequence of elements in an array.The first line contains two integers N and K, denoting the size of the array and the size of the subarray respectively.
The next line contains N integers denoting the elements of the array.
<b>Constarints</b>
1 <= K <= N <= 1000000
1 <= A[i] <= 1000000Print a single integer denoting the product of maximums for every subarray of size K modulo 1000000007Sample Input 1:
6 4
1 5 2 3 6 4
Sample Output 1:
180
<b>Explanation:</b>
For subarray [1, 5, 2, 3], maximum = 5
For subarray [5, 2, 3, 6], maximum = 6
For subarray [2, 3, 6, 4], maximum = 6
Therefore, ans = 5*6*6 = 180, I have written this Solution Code: from collections import deque
deq=deque()
n,k=list(map(int,input().split()))
array=list(map(int,input().split()))
for i in range(k):
while(deq and array[deq[-1]]<=array[i]):
deq.pop()
deq.append(i)
ans=1
for j in range(k,n):
ans=ans*array[deq[0]]
ans=(ans)%1000000007
while(deq and deq[0]<=j-k):
deq.popleft()
while(deq and array[deq[-1]]<=array[j]):
deq.pop()
deq.append(j)
ans=ans*array[deq[0]]
ans=(ans)%1000000007
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, A of N integers. Find the product of maximum values for every subarray of size K. Print the answer modulo 10<sup>9</sup>+7.
A subarray is any contiguous sequence of elements in an array.The first line contains two integers N and K, denoting the size of the array and the size of the subarray respectively.
The next line contains N integers denoting the elements of the array.
<b>Constarints</b>
1 <= K <= N <= 1000000
1 <= A[i] <= 1000000Print a single integer denoting the product of maximums for every subarray of size K modulo 1000000007Sample Input 1:
6 4
1 5 2 3 6 4
Sample Output 1:
180
<b>Explanation:</b>
For subarray [1, 5, 2, 3], maximum = 5
For subarray [5, 2, 3, 6], maximum = 6
For subarray [2, 3, 6, 4], maximum = 6
Therefore, ans = 5*6*6 = 180, I have written this Solution Code: #include<bits/stdc++.h>
#define int long long
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<int,int>
#define vi vector<int>
#define all(a) (a).begin(),(a).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define hell 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
void solve(){
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
deque<int> q;
for(int i = 1; i <= k; i++){
while(!q.empty() && a[q.back()] <= a[i])
q.pop_back();
q.push_back(i);
}
int ans = a[q.front()];
for(int i = k+1; i <= n; i++){
if(q.front() == i-k)
q.pop_front();
while(!q.empty() && a[q.back()] <= a[i])
q.pop_back();
q.push_back(i);
ans = (ans*a[q.front()]) % mod;
}
cout << ans;
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: ";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ready for a super simple challenge!
You are given two integers A and B. You will create a line of boys and girls in the following manner:
First A girls, then B boys, then A girls, then B boys, and so on.
You will also be given an integer N. Find the number of girls in the first N people of the row.The first and the only line of input contains 3 integers N, A, B.
Constraints
1 < N, A, B <= 10^18 (1000000000000000000)
A+B <= 10^18Output a singer integer, the number of girls in the first N people in the queue.Sample Input
8 3 4
Sample Output
4
Explanation
The arrangement will look like GGGBBBBG, where G represents girl and B represents boy., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
String[] nab = rd.readLine().split(" ");
long n = Long.parseLong(nab[0]);
long girl = Long.parseLong(nab[1]);
long boy = Long.parseLong(nab[2]);
long total = 0;
if(n>1 && girl>1 && boy>1){
long temp = n/(girl+boy);
total = (girl*temp);
if(n%(girl+boy)<girl)
total+=n%(girl+boy);
else
total+=girl;
System.out.print(total);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ready for a super simple challenge!
You are given two integers A and B. You will create a line of boys and girls in the following manner:
First A girls, then B boys, then A girls, then B boys, and so on.
You will also be given an integer N. Find the number of girls in the first N people of the row.The first and the only line of input contains 3 integers N, A, B.
Constraints
1 < N, A, B <= 10^18 (1000000000000000000)
A+B <= 10^18Output a singer integer, the number of girls in the first N people in the queue.Sample Input
8 3 4
Sample Output
4
Explanation
The arrangement will look like GGGBBBBG, where G represents girl and B represents boy., I have written this Solution Code: n,a,b=map(int,input().split())
if n%(a+b)== 0:
print(n//(a+b)*a)
else:
k=n-(n//(a+b))*(a+b)
if k >= a:
print((n//(a+b))*a+a)
else:
print((n//(a+b))*a+k), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ready for a super simple challenge!
You are given two integers A and B. You will create a line of boys and girls in the following manner:
First A girls, then B boys, then A girls, then B boys, and so on.
You will also be given an integer N. Find the number of girls in the first N people of the row.The first and the only line of input contains 3 integers N, A, B.
Constraints
1 < N, A, B <= 10^18 (1000000000000000000)
A+B <= 10^18Output a singer integer, the number of girls in the first N people in the queue.Sample Input
8 3 4
Sample Output
4
Explanation
The arrangement will look like GGGBBBBG, where G represents girl and B represents boy., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 100005;
// it's swapnil07 ;)
#ifdef SWAPNIL07
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define end_routine()
#endif
signed main()
{
fast
int n, a, b; cin>>n>>a>>b;
int x = a+b;
int y = (n/x);
n -= (y*x);
int ans = y*a;
if(n > a)
ans += a;
else
ans += n;
cout<<ans;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S you have to remove all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, remove them as well. Repeat this untill no adjacent letter in the string is same.
Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.The input data consists of a single string S.
Constraints:
1 <= |S| <= 100000
S contains lowercase english letters only.Print the given string after it is processed. It is guaranteed that the result will contain at least one character.Sample Input
hhoowaaaareyyoouu
Sample Output
wre
Explanation:
First we remove "hh" then "oo" then "aa" then "yy" then "oo" then "uu" and we are left with "wre".
Now we cannot remove anything.
Sample Input:-
abcde
Sample Output:-
abcde
Sample Input:-
abcddcb
Sample Output:-
a, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
StringBuilder s = new StringBuilder();
String text=null;
while ((text = in.readLine ()) != null)
{
s.append(text);
}
int len=s.length();
for(int i=0;i<len-1;i++){
if(s.charAt(i)==s.charAt(i+1)){
int flag=0;
s.delete(i,i+2);
int left=i-1;
len=len-2;
i=i-2;
if(i<0){
i=-1;
}
}
}
System.out.println(s);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S you have to remove all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, remove them as well. Repeat this untill no adjacent letter in the string is same.
Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.The input data consists of a single string S.
Constraints:
1 <= |S| <= 100000
S contains lowercase english letters only.Print the given string after it is processed. It is guaranteed that the result will contain at least one character.Sample Input
hhoowaaaareyyoouu
Sample Output
wre
Explanation:
First we remove "hh" then "oo" then "aa" then "yy" then "oo" then "uu" and we are left with "wre".
Now we cannot remove anything.
Sample Input:-
abcde
Sample Output:-
abcde
Sample Input:-
abcddcb
Sample Output:-
a, I have written this Solution Code: s=input()
l=["aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk","ll","mm","nn","oo","pp","qq","rr","ss","tt","uu","vv","ww","xx","yy","zz"]
while True:
do=False
for i in range(len(l)):
if l[i] in s:
do=True
while l[i] in s:
s=s.replace(l[i],"")
if do==False:
break
print(s), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S you have to remove all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, remove them as well. Repeat this untill no adjacent letter in the string is same.
Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.The input data consists of a single string S.
Constraints:
1 <= |S| <= 100000
S contains lowercase english letters only.Print the given string after it is processed. It is guaranteed that the result will contain at least one character.Sample Input
hhoowaaaareyyoouu
Sample Output
wre
Explanation:
First we remove "hh" then "oo" then "aa" then "yy" then "oo" then "uu" and we are left with "wre".
Now we cannot remove anything.
Sample Input:-
abcde
Sample Output:-
abcde
Sample Input:-
abcddcb
Sample Output:-
a, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main(){
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
string s;
cin>>s;
int len=s.length();
char stk[410000];
int k = 0;
for (int i = 0; i < len; i++)
{
stk[k++] = s[i];
while (k > 1 && stk[k - 1] == stk[k - 2])
k -= 2;
}
for (int i = 0; i < k; i++)
cout << stk[i];
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
bool EqualOrNot(int h1, int h2, int v1,int v2){
if (v2>v1&&(h1-h2)%(v2-v1)==0){
return true;
}
return false;
}
int main(){
int n1,n2,v1,v2;
cin>>n1>>n2>>v1>>v2;
if(EqualOrNot(n1,n2,v1,v2)){
cout<<"Yes";}
else{
cout<<"No";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code: def EqualOrNot(h1,h2,v1,v2):
if (v2>v1 and (h1-h2)%(v2-v1)==0):
return True
else:
return False
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.