Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers that may contain duplicate elements and an integer K, find if there exists a pair of integers (i, j) such that i < j and arr[i]=arr[j] and i and j are exactly k distance apart i.e ( j - i ) = k.The first line of input contains two integers N and K, next line contains N space-separated integers.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = K < = N
1 < = Arr[i] < = 10<sup>9</sup>Print 1 if there exist elements else print 0.Sample Input:
4 3
1 2 2 1
Sample Output:
1
<b>Explanation:- </b>
Pair at index 1, 4 is the required answer so output=1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception{
InputStreamReader br=new InputStreamReader(System.in);
BufferedReader b=new BufferedReader(br);
String s1[]=b.readLine().split(" ");
int n=Integer.parseInt(s1[0]);
int k=Integer.parseInt(s1[1]);
int a[]=new int[n];
HashMap<Integer,Integer> map=new HashMap<>();
String s2[]=b.readLine().split(" ");
int ans=0;
for(int i=0;i<n;i++){
a[i]=Integer.parseInt(s2[i]);
if(map.containsKey(a[i])){
if(i-map.get(a[i])==k){
ans=1;
}
else if(i-map.get(a[i])>k){
map.put(a[i],i);
}
}
else{
map.put(a[i],i);
}
}
for(int i=0;i<n;i++){
}
System.out.println(ans);
}
}, 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 that may contain duplicate elements and an integer K, find if there exists a pair of integers (i, j) such that i < j and arr[i]=arr[j] and i and j are exactly k distance apart i.e ( j - i ) = k.The first line of input contains two integers N and K, next line contains N space-separated integers.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = K < = N
1 < = Arr[i] < = 10<sup>9</sup>Print 1 if there exist elements else print 0.Sample Input:
4 3
1 2 2 1
Sample Output:
1
<b>Explanation:- </b>
Pair at index 1, 4 is the required answer so output=1, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define max1 10000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
bool isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main(){
int n,k;
cin>>n>>k;
ll a[n];
FOR(i,n){
cin>>a[i];}
FOR(i,n-k){
if(a[i]==a[i+k]){out(1);return 0;}
}
out(0);
}
/*
1
4 5
02_20
21212
_121_
__2__
*/
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers that may contain duplicate elements and an integer K, find if there exists a pair of integers (i, j) such that i < j and arr[i]=arr[j] and i and j are exactly k distance apart i.e ( j - i ) = k.The first line of input contains two integers N and K, next line contains N space-separated integers.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = K < = N
1 < = Arr[i] < = 10<sup>9</sup>Print 1 if there exist elements else print 0.Sample Input:
4 3
1 2 2 1
Sample Output:
1
<b>Explanation:- </b>
Pair at index 1, 4 is the required answer so output=1, I have written this Solution Code: N,K = list(map(int,input().split()))
arr = list(map(int,input().split()))
flag = False
for i in range(K,N):
if arr[i-K] == arr[i]:
flag = True
break
if flag:
print("1")
else:
print("0"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given a positive integer K and your task is to print the number of elements in array a[] that are smaller than or equal to K.<b>In case of Java only</b>
<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>smallerElements()</b> that takes the array a[], integer N and integer k as arguments.
<b>Custom Input</b>
The first line of input contains a single integer N.
The second line of input contains N space- separated integers depicting the values of the array.
The third line of input contains a single integer Q, the number of queries.
Each of the next Q lines of input contain a single integer, the value of K.
<b>Constraints:-</b>
1 <= N <= 10<sup>5</sup>
1 <= K, Arr[i] <= 10<sup>12</sup>
1 <= Q <= 10<sup>4</sup>Return the count of elements smaller than or equal to K.Sample Input:-
5
2 5 6 11 15
5
2
4
8
1
16
Sample Output:-
1
1
3
0
5, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int n;
cin>>n;
vector<int> v(n);
FOR(i,n){
cin>>v[i];}
int q;
cin>>q;
int x;
while(q--){
cin>>x;
auto it = upper_bound(v.begin(),v.end(),x);
out(it-v.begin());
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given a positive integer K and your task is to print the number of elements in array a[] that are smaller than or equal to K.<b>In case of Java only</b>
<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>smallerElements()</b> that takes the array a[], integer N and integer k as arguments.
<b>Custom Input</b>
The first line of input contains a single integer N.
The second line of input contains N space- separated integers depicting the values of the array.
The third line of input contains a single integer Q, the number of queries.
Each of the next Q lines of input contain a single integer, the value of K.
<b>Constraints:-</b>
1 <= N <= 10<sup>5</sup>
1 <= K, Arr[i] <= 10<sup>12</sup>
1 <= Q <= 10<sup>4</sup>Return the count of elements smaller than or equal to K.Sample Input:-
5
2 5 6 11 15
5
2
4
8
1
16
Sample Output:-
1
1
3
0
5, I have written this Solution Code: static int smallerElements(int a[], int n, int k){
int l=0;
int h=n-1;
int m;
int ans=n;
while(l<=h){
m=l+h;
m/=2;
if(a[m]<=k){
l=m+1;
}
else{
h=m-1;
ans=m;
}
}
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A contest setter wants to determine the time limits for a given problem. There are n model solutions, and solution k takes tk milliseconds to run on the test data. The contest setter wants the time limit to be an integer number of seconds, and wants the time limit to be at least s times larger than the slowest model solution. Compute the minimum time limit the contest setter can set.The first line of input contains two space-separated integers n and s (1 β€ n β€ 100 and 1 β€ s β€ 20).
The second line of input contains n space-separated integers t1, . . . , tn (1 β€ tk β€ 2000 for all
k = 1, . . . , n).Print, on one line, the minimum time limit (in seconds) as a single integer.sample input
2 5
200 250
sample output
2
Explanation:-
minimum time in millisecond will be 250*5 = 1250ms = 1.25sec
so minimum time in the second will be 2sec
sample input
3 4
47 1032 1107
sample output
5, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader get = new BufferedReader(new InputStreamReader(System.in));
String A[] = get.readLine().trim().split(" ");
int n = Integer.parseInt(A[0]);
int s = Integer.parseInt(A[1]);
String B[] = get.readLine().trim().split(" ");
int max=Integer.parseInt(B[0]);;
for (int i=1; i<n; i++){
int num = Integer.parseInt(B[i]);
if(num>max){
max = num;
}
}
int temp = s*max;
float temp1 = (float)temp/1000;
int result = (int)Math.ceil(temp1);
System.out.println(result);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A contest setter wants to determine the time limits for a given problem. There are n model solutions, and solution k takes tk milliseconds to run on the test data. The contest setter wants the time limit to be an integer number of seconds, and wants the time limit to be at least s times larger than the slowest model solution. Compute the minimum time limit the contest setter can set.The first line of input contains two space-separated integers n and s (1 β€ n β€ 100 and 1 β€ s β€ 20).
The second line of input contains n space-separated integers t1, . . . , tn (1 β€ tk β€ 2000 for all
k = 1, . . . , n).Print, on one line, the minimum time limit (in seconds) as a single integer.sample input
2 5
200 250
sample output
2
Explanation:-
minimum time in millisecond will be 250*5 = 1250ms = 1.25sec
so minimum time in the second will be 2sec
sample input
3 4
47 1032 1107
sample output
5, I have written this Solution Code: import math
b=input().split()
b=int(b[1])/1000
a=input().split()
for i in range(len(a)):
a[i]=int(a[i])
a.sort()
print(math.ceil(b*a.pop())), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A contest setter wants to determine the time limits for a given problem. There are n model solutions, and solution k takes tk milliseconds to run on the test data. The contest setter wants the time limit to be an integer number of seconds, and wants the time limit to be at least s times larger than the slowest model solution. Compute the minimum time limit the contest setter can set.The first line of input contains two space-separated integers n and s (1 β€ n β€ 100 and 1 β€ s β€ 20).
The second line of input contains n space-separated integers t1, . . . , tn (1 β€ tk β€ 2000 for all
k = 1, . . . , n).Print, on one line, the minimum time limit (in seconds) as a single integer.sample input
2 5
200 250
sample output
2
Explanation:-
minimum time in millisecond will be 250*5 = 1250ms = 1.25sec
so minimum time in the second will be 2sec
sample input
3 4
47 1032 1107
sample output
5, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,s;
cin>> n>> s;
int t[n];
int res = 0, ans;
for(int i=1;i<=n;i++){
cin>> t[i];
res = max(res ,t[i]);
}
ans = res*s/1000;
if((res * s)%1000)
{
ans++;
}
cout << ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have N kilograms of fruits with you and M types of polybags to put the fruits into. The holding capacity of the i<sup>th</sup> polybag is p<sub>i</sub>. Find the minimum number of polybags required to carry all N kilograms of fruits.The first line contains two integers N and M.
The second line contains M space-separated integers.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>12</sup>
1 ≤ M ≤ 10<sup>5</sup>
1 ≤ p<sub>i</sub> ≤ 10<sup>8</sup>Print the minimum number of polybags required to carry all N-kilograms of fruits.Sample Input:
10 4
4 9 8 2
Sample Output:
2
<b>Explaination:</b>
We can carry fruits in polybag 1 and polybag 3. This will give us a total capacity of 4 + 8 = 12 kilograms which is more than that required to carry the fruits., 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);
long N = sc.nextLong();
int M = sc.nextInt();
int arr[] = new int[M];
for(int i=0; i<M; i++){
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
int count = 0;
for(int i=arr.length-1; i>=0; i--){
if(N >= 0){
N -= arr[i];
count++;
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have N kilograms of fruits with you and M types of polybags to put the fruits into. The holding capacity of the i<sup>th</sup> polybag is p<sub>i</sub>. Find the minimum number of polybags required to carry all N kilograms of fruits.The first line contains two integers N and M.
The second line contains M space-separated integers.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>12</sup>
1 ≤ M ≤ 10<sup>5</sup>
1 ≤ p<sub>i</sub> ≤ 10<sup>8</sup>Print the minimum number of polybags required to carry all N-kilograms of fruits.Sample Input:
10 4
4 9 8 2
Sample Output:
2
<b>Explaination:</b>
We can carry fruits in polybag 1 and polybag 3. This will give us a total capacity of 4 + 8 = 12 kilograms which is more than that required to carry the fruits., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n, m;
cin >> n >> m;
vector<int> a(m);
for(auto &i : a) cin >> i;
sort(a.rbegin(), a.rend());
int ans = 0, cur = 0;
for(int i = 0; i < m; i++){
ans++;
cur += a[i];
if(cur >= n){
break;
}
}
cout << ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, you are allowed to remove atmost one character from the string. After the removal process print the lexicographically minimal string that can be obtained.
For example, "aaa" is smaller than "aaaa", "abb" is smaller than "abc", "pqr" is smaller than "z".The first line of the input contains one integer N β the length of S.
The second line of the input contains exactly N lowercase Latin letters β the string S.
(2 β€ N β€ 10^5)Print one string β the smallest possible lexicographically string that can be obtained by removing at most one character from the string SInput
3
aaa
Output
aa
Input
5
abcda
Output
abca, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String str = br.readLine().trim();
char max = str.charAt(0);
int idx = 0;
for(int i=1;i<str.length();i++){
char ch = str.charAt(i);
if(max > ch){
idx = i;
break;
}
max = ch;
}
String minstr = "";
if(idx == 0){
minstr = str.substring(0,str.length()-1);
}else if(idx == 1){
minstr = str.substring(idx);
}else{
minstr = str.substring(0,idx-1) + str.substring(idx);
}
System.out.print(minstr);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, you are allowed to remove atmost one character from the string. After the removal process print the lexicographically minimal string that can be obtained.
For example, "aaa" is smaller than "aaaa", "abb" is smaller than "abc", "pqr" is smaller than "z".The first line of the input contains one integer N β the length of S.
The second line of the input contains exactly N lowercase Latin letters β the string S.
(2 β€ N β€ 10^5)Print one string β the smallest possible lexicographically string that can be obtained by removing at most one character from the string SInput
3
aaa
Output
aa
Input
5
abcda
Output
abca, I have written this Solution Code: n=int(input())
s=input()
for i in range(n-1):
if s[i]>s[i+1]:
print(s[0:i]+s[i+1:n])
exit()
print(s[0:n-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, you are allowed to remove atmost one character from the string. After the removal process print the lexicographically minimal string that can be obtained.
For example, "aaa" is smaller than "aaaa", "abb" is smaller than "abc", "pqr" is smaller than "z".The first line of the input contains one integer N β the length of S.
The second line of the input contains exactly N lowercase Latin letters β the string S.
(2 β€ N β€ 10^5)Print one string β the smallest possible lexicographically string that can be obtained by removing at most one character from the string SInput
3
aaa
Output
aa
Input
5
abcda
Output
abca, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int l; cin >> l;
string s; cin >> s;
s += 'A';
bool flag = 0;
for(int i = 0; i < l; i++){
if(flag == 0 && s[i] > s[i+1])
flag = 1;
else
cout << s[i];
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, I have written this Solution Code: n=int(input())
li = list(map(int,input().strip().split()))
for i in range(0,n-2):
if li[i]==li[i+1] and li[i+1]==li[i+2]:
print("Yes",end="")
exit()
print("No",end=""), 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 whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, 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);
bool fl = false;
For(i, 0, n){
cin>>a[i];
if(i>=2){
if(a[i]==a[i-1] && a[i]==a[i-2]){
fl = true;
}
}
}
if(fl){
cout<<"Yes";
}
else
cout<<"No";
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
for(int i=0;i<n-2;i++){
if(a[i]==a[i+1] && a[i+1]==a[i+2]){
System.out.print("Yes");
return;
}
}
System.out.print("No");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: New Year festival of Ying Yang is approaching. There are <b>N</b> spaces available for stalls to be put up. The i<sup>th</sup> stall's price is p<sub>i</sub>. You have X amount of money with you right now and you want to buy <b>atleast 2 stalls</b> from this money. Find whether it is possible. Print "YES" if it is possible, else print "NO", without the quotes.First line of the input contains two integers N, the number of stall spaces and X, the amount of money you have.
The second line of the input contains N space seperated integers.
Constraints:
2 <= N <= 10<sup>5</sup>
1 <= X <= 10<sup>9</sup>
1 <= p<sub>i</sub> <= 10<sup>9</sup>Print "YES" if it is possible for you to buy atleast two spaces in the festival, else print "NO", without the quotes.Sample Input:
5 10
3 6 5 8 11
Sample Input:
YES
Explaination:
You can buy stall no. s 1 and 2 (1- based indexing) to bring the total amount to 3 + 6 = 9, which is less than 10., I have written this Solution Code: n,p=input().split()
arr=list(map(int,input().split()))
arr.sort()
i=0
for j in range(i+1,int(n)):
if arr[i]+arr[j] <= int(p) :
print("YES")
break
i+=1
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: New Year festival of Ying Yang is approaching. There are <b>N</b> spaces available for stalls to be put up. The i<sup>th</sup> stall's price is p<sub>i</sub>. You have X amount of money with you right now and you want to buy <b>atleast 2 stalls</b> from this money. Find whether it is possible. Print "YES" if it is possible, else print "NO", without the quotes.First line of the input contains two integers N, the number of stall spaces and X, the amount of money you have.
The second line of the input contains N space seperated integers.
Constraints:
2 <= N <= 10<sup>5</sup>
1 <= X <= 10<sup>9</sup>
1 <= p<sub>i</sub> <= 10<sup>9</sup>Print "YES" if it is possible for you to buy atleast two spaces in the festival, else print "NO", without the quotes.Sample Input:
5 10
3 6 5 8 11
Sample Input:
YES
Explaination:
You can buy stall no. s 1 and 2 (1- based indexing) to bring the total amount to 3 + 6 = 9, which is less than 10., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using T = pair<int, int>;
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 1e9;
void solve() {
int n, x;
cin >> n >> x;
vector<int> p(n);
for(auto &i : p) cin >> i;
sort(all(p));
cout << ((p[0] + p[1]) <= x ? "YES" : "NO");
}
signed main(){
fast
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
if(i != t) cout << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean 2D matrix (0-based index), find whether there is path from (0,0) to (x,y) and if there is one path, print the minimum no of steps needed to reach it, else print -1 if the destination is not reachable. You may move in only four direction ie up, down, left and right. The path can only be created out of a cell if its value is 1. The first line contains two integers n and m denoting the size of the matrix. Then in the next line are n*m space-separated values of the matrix. The following line after it contains two integers x and y denoting the index of the destination.
Constraints:
1<=n,m<=1000For each test case print in a new line the min no of steps needed to reach the destination.Input:
3 4
1 0 0 0 1 1 0 1 0 1 1 1
2 3
Output
5
Input
3 4
1 1 1 1 0 0 0 1 0 0 0 1
0 3
Output:
3, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
#define qw1 freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define qw2 freopen("input2.txt", "r", stdin); freopen("output2.txt", "w", stdout);
#define qw3 freopen("input3.txt", "r", stdin); freopen("output3.txt", "w", stdout);
#define qw4 freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout);
#define qw5 freopen("input5.txt", "r", stdin); freopen("output5.txt", "w", stdout);
#define qw6 freopen("input6.txt", "r", stdin); freopen("output6.txt", "w", stdout);
#define qw freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
int xa[4]={1,-1,0,0};
int ya[4]={0,0,1,-1};
int n,m;
int check(int x,int y)
{
if(x>=0 && x<n && y>=0 && y<m)
{
return 1;
}else return 0;
}
int vis[1005][1005];
int dist[1005][1005];
int A[1005][1005];
signed main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
{ for(int j=0;j<m;j++)
{cin>>A[i][j];
dist[i][j]=100000000;
vis[i][j]=0;
}
}
multimap<int,pii> ss;
ss.insert(mp(0,mp(0,0)));
dist[0][0]=0;
while(ss.size()>0)
{
auto it=ss.begin()->se;
int a=it.fi,b=it.se;
ss.erase(ss.begin());
if(vis[a][b]==1) continue;
vis[a][b]=1;
for(int i=0;i<4;i++)
{
int x=a+xa[i];
int y=b+ya[i];
if(check(x,y)==1 && dist[x][y]>dist[a][b]+1 && A[x][y]==1)
{
dist[x][y]=dist[a][b]+1;
ss.insert(mp(dist[x][y],mp(x,y)));
}
}
}
int d1,d2;
cin>>d1>>d2;
if(dist[d1][d2]>=10000000) cout<<-1<<endl;
else cout<<dist[d1][d2]<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean 2D matrix (0-based index), find whether there is path from (0,0) to (x,y) and if there is one path, print the minimum no of steps needed to reach it, else print -1 if the destination is not reachable. You may move in only four direction ie up, down, left and right. The path can only be created out of a cell if its value is 1. The first line contains two integers n and m denoting the size of the matrix. Then in the next line are n*m space-separated values of the matrix. The following line after it contains two integers x and y denoting the index of the destination.
Constraints:
1<=n,m<=1000For each test case print in a new line the min no of steps needed to reach the destination.Input:
3 4
1 0 0 0 1 1 0 1 0 1 1 1
2 3
Output
5
Input
3 4
1 1 1 1 0 0 0 1 0 0 0 1
0 3
Output:
3, I have written this Solution Code: import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.io.*;
import java.util.*;
class Main {
private static Reader fr;
private static OutputStream out;
private static final int delta = (int) 1e9 + 7;
private 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[1024];
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();
}
}
public static void main(String args[]) throws IOException {
run();
}
private static void run() throws IOException {
fr = new Reader();
out = new BufferedOutputStream(System.out);
solve();
out.flush();
out.close();
}
static int mod=1000000007;
static int dx=0,dy=0;
static int a=0;
static int minn=Integer.MAX_VALUE;
private static void solve() throws IOException
{
int n=fr.nextInt();
int m=fr.nextInt();
int arr[][]= new int[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
arr[i][j]=fr.nextInt();
}
}
dx=fr.nextInt();
dy=fr.nextInt();
int ans=bfs(arr);
System.out.println(ans);
}
static class Node{
int x,y;
Node(int x,int y){
this.x=x;
this.y=y;
}
}
static int bfs(int arr[][]){
int n=arr.length;
int m=arr[0].length;
Queue<Node> q=new LinkedList<>();
q.add(new Node(0,0));
if(arr[0][0]==0) return -1;
arr[0][0]=0;
int count=0;
while(!q.isEmpty()){
int size=q.size();
for(int i=0;i<size;i++){
Node temp=q.poll();
if(temp.x==dx && temp.y==dy){
return count;
}else{
if((temp.x-1 >= 0 && temp.x-1 < n) && arr[temp.x-1][temp.y] == 1) {
arr[temp.x-1][temp.y]=0;
q.add(new Node(temp.x-1, temp.y));
a++;
}
if((temp.x+1 >= 0 && temp.x+1 < n) && arr[temp.x+1][temp.y] == 1) {
arr[temp.x+1][temp.y]=0;
q.add(new Node(temp.x+1, temp.y));
a++;
}
if((temp.y-1 >= 0 && temp.y-1 < m) && arr[temp.x][temp.y-1] == 1) {
arr[temp.x][temp.y-1]=0;
q.add(new Node(temp.x, temp.y-1));
a++;
}
if((temp.y+1 >= 0 && temp.y+1 < m) && arr[temp.x][temp.y+1] == 1) {
arr[temp.x][temp.y+1]=0;
q.add(new Node(temp.x, temp.y+1));
a++;
}
}
}
count++;
}
return -1;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list consisting of <b>L</b> nodes and given a number <b>N</b>. The task is to find the Nth node from the end of the linked list.First line of input contains number of testcase T. For each testcase, first line of input contains number of nodes in the linked list L and the number N. Next line contains N nodes of linked list.
<b>User Task:</b>
The task is to complete the function <b>getNthFromLast()</b> which takes two arguments: reference to head and N and you need to return Nth from end.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= L <= 10^3
For each testcase, output the data of node which is at Nth distance from end.Input:
2
9 2
1 2 3 4 5 6 7 8 9
4 5
10 5 100 5
Output:
8
-1
Explanation:
Testcase 1: In the first example, there are 9 nodes in linked list and we need to find 2nd node from end. 2nd node from end os 8.
Testcase 2: In the second example, there are 4 nodes in linked list and we need to find 5th from end. Since 'n' is more than number of nodes in linked list, output is -1., I have written this Solution Code: static int getNthFromLast(Node head, int n)
{
int len = 0;
Node temp = head;
while(temp != null) // Traverse temp throught the linked list and find the length
{
temp = temp.next;
len++;
}
if(len < n)
return -1;
//System.out.println(count);
//int r = count - n;
temp = head;
for(int i=1; i<len-n+1; i++) // Traverse the node till the position from begining: length - n +1.
temp = temp.next;
return temp.data;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a 2-D array of binary integers of size NXM. The cell at i<sup>th</sup> row and j<sup>th</sup> column is denoted by (i, j).
The array is called Balanced if every cell of the array having 4 elements has a balanced neighborhood. A neighborhood is balanced if 4 neighbors can be divided into 2 groups with equal size and equal sum.
A cell at (i, j) has 4 neighbors (i-1, j), (i+1, j), (i, j-1), (i, j+1).The first line contains N and M.
Next N lines contain M integers each.
<b>Constraints</b>
2 ≤ N, M ≤ 1000
0 ≤ arr[i][j] ≤ 1Print "YES" if the given array is balanced, otherwise print "NO".Input:
3 4
0 1 0 0
1 1 0 1
0 0 1 1
Output:
NO
Explanation:
neighbors of (1, 1) => {1, 1, 0, 0} => 1+0 = 0+1 => balanced neighborhood
neighbors of (1, 2) => {0, 1, 1, 1} => no way to divide into two groups with equal sum and equal size => unbalanced
No other cell has 4 neighbors., I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
int n=Integer.parseInt(in.next());
int m=Integer.parseInt(in.next());
int a[][] = new int[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++){
a[i][j] = Integer.parseInt(in.next());
}
}
int f=1;
for(int i=1;i+1<n;i++){
for(int j=1;j+1<m;j++){
int sum=a[i+1][j] + a[i-1][j] + a[i][j+1] + a[i][j-1];
if(sum%2 != 0){
f=-1;
break;
}
}
if(f==-1)break;
}
if(f==1)out.print("YES");
else out.print("NO");
out.close();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void println(int i) {
writer.println(i);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: N = int(input())
if N > 5:
print("Greater than 5")
elif(N == 1):
print("one")
elif(N == 2):
print("two")
elif(N == 3):
print("three")
elif(N == 4):
print("four")
elif(N == 5):
print("five"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
String area = conditional(side);
System.out.println(area);
}static String conditional(int n){
if(n==1){return "one";}
else if(n==2){return "two";}
else if(n==3){return "three";}
else if(n==4){return "four";}
else if(n==5){return "five";}
else{
return "Greater than 5";}
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: def compound_interest(principle, rate, time):
Amount = principle * (pow((1 + rate / 100), time))
CI = Amount - principle
print( '%.2f'%CI)
principle,rate,time=map(int, input().split())
compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: function calculateCI(P, R, T)
{
let interest = P * (Math.pow(1.0 + R/100.0, T) - 1);
return interest.toFixed(2);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int p,r,t;
cin>>p>>r>>t;
double rate= (float)r/100;
double amt = (float)p*(pow(1+rate,t));
cout << fixed << setprecision(2) << (amt - p);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s= br.readLine().split(" ");
double[] darr = new double[s.length];
for(int i=0;i<s.length;i++){
darr[i] = Double.parseDouble(s[i]);
}
double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0];
System.out.printf("%.2f",ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T β the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, β the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=0;i<T;i++)
{
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
if(a>b && a>c)
{
System.out.println("Alice");
}
else if(b>a && b>c)
{
System.out.println("Bob");
}
else if(c>a && c>b)
{
System.out.println("Charlie");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T β the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, β the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: #include <bits/stdc++.h>
int main() {
int T = 0;
std::cin >> T;
while (T--) {
int A = 0, B = 0, C = 0;
std::cin >> A >> B >> C;
assert(A != B && B != C && C != A);
if (A > B && A > C) {
std::cout << "Alice" << '\n';
} else if (B > A && B > C) {
std::cout << "Bob" << '\n';
} else {
std::cout << "Charlie" << '\n';
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T β the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, β the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: T = int(input())
for i in range(T):
A,B,C = list(map(int,input().split()))
if A>B and A>C:
print("Alice")
elif B>A and B>C:
print("Bob")
else:
print("Charlie"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code: static int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
def RotationPolicy(A, B):
cnt=0
for i in range (A,B+1):
if(i-1)%2!=0 and (i-1)%3!=0:
cnt=cnt+1
return cnt
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code: function RotationPolicy(a, b) {
// write code here
// do no console.log the answer
// return the output using return keyword
let count = 0
for (let i = a; i <= b; i++) {
if((i-1)%2 !== 0 && (i-1)%3 !==0){
count++
}
}
return count
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: for i in range(int(input())):
n, x = map(int, input().split())
if x >= 10:
print(0)
else:
print((10-x)*(n-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n, x;
cin >> n >> x;
if(x >= 10)
cout << 0 << endl;
else
cout << (10-x)*(n-1) << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
while (T -->0){
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int p = Integer.parseInt(s[1]);
if (p<10)
System.out.println(Math.abs(n-1)*(10-p));
else System.out.println(0);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Hi, it's Monica!
Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle.
Constraints
1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input
3
Sample Output
Yes
Sample Input
10
Sample Output
No, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Cf cf = new Cf();
cf.solve();
}
static class Cf {
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
int mod = (int)1e9+7;
public void solve() {
int t = in.readInt();
if(t>=6) {
out.printLine("No");
}else {
out.printLine("Yes");
}
}
public long findPower(long x,long n) {
long ans = 1;
long nn = n;
while(nn>0) {
if(nn%2==1) {
ans = (ans*x) % mod;
nn-=1;
}else {
x = (x*x)%mod;
nn/=2;
}
}
return ans%mod;
}
public static int log2(int x) {
return (int) (Math.log(x) / Math.log(2));
}
private static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public double readDouble() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, readInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, readInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
private static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
writer.flush();
}
public void printLine(Object... objects) {
print(objects);
writer.println();
writer.flush();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Hi, it's Monica!
Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle.
Constraints
1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input
3
Sample Output
Yes
Sample Input
10
Sample Output
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
template<class C> void mini(C&a4, C b4){a4=min(a4,b4);}
typedef unsigned long long ull;
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define mod 1000000007ll
#define pii pair<int,int>
/////////////
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
if(n<6)
cout<<"Yes";
else
cout<<"No";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Hi, it's Monica!
Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle.
Constraints
1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input
3
Sample Output
Yes
Sample Input
10
Sample Output
No, I have written this Solution Code: n=int(input())
if(n>=6):
print("No")
else:
print("Yes"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: n = int(input())
if (n%4==0 and n%100!=0 or n%400==0):
print("YES")
elif n==0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int n = scanner.nextInt();
LeapYear(n);
}
static void LeapYear(int year){
if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");}
else {
System.out.println("NO");}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<b>User Task</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: def Pattern(N):
print('*')
for i in range (0,N-2):
print('*',end='')
for j in range (0,i+1):
print('^',end='')
print('*')
for i in range (0,N+1):
print('*',end='')
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<b>User Task</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: void Pattern(int N){
cout<<'*'<<endl;
for(int i=0;i<N-2;i++){
cout<<'*';
for(int j=0;j<=i;j++){
cout<<'^';
}
cout<<'*'<<endl;
}
for(int i=0;i<=N;i++){
cout<<'*';
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<b>User Task</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: static void Pattern(int N){
System.out.println('*');
for(int i=0;i<N-2;i++){
System.out.print('*');
for(int j=0;j<=i;j++){
System.out.print('^');
}System.out.println('*');
}
for(int i=0;i<=N;i++){
System.out.print('*');
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<b>User Task</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: void Pattern(int N){
printf("*\n");
for(int i=0;i<N-2;i++){
printf("*");
for(int j=0;j<=i;j++){
printf("^");}printf("*\n");
}
for(int i=0;i<=N;i++){
printf("*");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code:
int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code:
int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code: static int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code: def Phone(N,K,M):
if N*K < M :
return -1
x = M//K
if M%K!=0:
x=x+1
return x, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, your task is to print the string S.You don't have to worry about taking input, you just have to complete the function <b>printString</b>Print the string S.Sample Input 1:-
NewtonSchool
Sample Output 1:-
NewtonSchool
Sample Input 2:-
Hello
Sample Output 2:-
Hello, I have written this Solution Code: static void printString(String stringVariable){
System.out.println(stringVariable);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, your task is to print the string S.You don't have to worry about taking input, you just have to complete the function <b>printString</b>Print the string S.Sample Input 1:-
NewtonSchool
Sample Output 1:-
NewtonSchool
Sample Input 2:-
Hello
Sample Output 2:-
Hello, I have written this Solution Code: S=input()
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, your task is to print the string S.You don't have to worry about taking input, you just have to complete the function <b>printString</b>Print the string S.Sample Input 1:-
NewtonSchool
Sample Output 1:-
NewtonSchool
Sample Input 2:-
Hello
Sample Output 2:-
Hello, I have written this Solution Code: void printString(string s){
cout<<s;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<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>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: def Knight(X,Y):
cnt=0
if(X>2):
if(Y>1):
cnt=cnt+1
if(Y<8):
cnt=cnt+1
if(Y>2):
if(X>1):
cnt=cnt+1
if(X<8):
cnt=cnt+1
if(X<7):
if(Y>1):
cnt=cnt+1
if(Y<8):
cnt=cnt+1
if(Y<7):
if(X>1):
cnt=cnt+1
if(X<8):
cnt=cnt+1
return cnt;
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<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>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: static int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<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>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<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>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code:
int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code:
int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code: static int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code: def Phone(N,K,M):
if N*K < M :
return -1
x = M//K
if M%K!=0:
x=x+1
return x, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:-
Players play in turns
The game ends when all the characters in the string are same, and the player who has the current turn wins.
The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|)
If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S.
Constraints:-
1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:-
0101
Sample Output:-
Sasuke
Explanation:-
First Naruto will delete the character 0 from index 1. string:- 101
Then Sasuke will delete the character 1 from index 1. string 01
It doesn't matter which character Naruto removes now, Sasuke will definitely win.
Sample Input:-
1111
Sample Output:-
Naruto
Explanation:-
All the characters in the string are already same hence Naruto wins, 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 s1=br.readLine();
int N=s1.length();
int index=0;
int count=0;
for(int i=N-2;i>=0;i--)
{
if(s1.charAt(i)!=s1.charAt(i+1))
{
index=i+1;
break;
}
}
if(index==N-1)
{
if(N%2==0)
{
System.out.print("Sasuke");
}
else{
System.out.print("Naruto");
}
}
else if(index==0)
{
System.out.print("Naruto");
}
else{
for(int i=0;i<index;i++)
{
count++;
}
if(count%2==0)
{
System.out.print("Naruto");
}
else{
System.out.print("Sasuke");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:-
Players play in turns
The game ends when all the characters in the string are same, and the player who has the current turn wins.
The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|)
If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S.
Constraints:-
1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:-
0101
Sample Output:-
Sasuke
Explanation:-
First Naruto will delete the character 0 from index 1. string:- 101
Then Sasuke will delete the character 1 from index 1. string 01
It doesn't matter which character Naruto removes now, Sasuke will definitely win.
Sample Input:-
1111
Sample Output:-
Naruto
Explanation:-
All the characters in the string are already same hence Naruto wins, I have written this Solution Code: binary_string = input()
n = len(binary_string)-1
index = n
for i in range(n-1, -1, -1):
if binary_string[i] == binary_string[n]:
index = i
else:
break
if index % 2 == 0:
print("Naruto")
else:
print("Sasuke"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:-
Players play in turns
The game ends when all the characters in the string are same, and the player who has the current turn wins.
The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|)
If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S.
Constraints:-
1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:-
0101
Sample Output:-
Sasuke
Explanation:-
First Naruto will delete the character 0 from index 1. string:- 101
Then Sasuke will delete the character 1 from index 1. string 01
It doesn't matter which character Naruto removes now, Sasuke will definitely win.
Sample Input:-
1111
Sample Output:-
Naruto
Explanation:-
All the characters in the string are already same hence Naruto wins, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 1000000000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int cnt[max1];
signed main(){
string s;
cin>>s;
int cnt=0;
FOR(i,s.length()){
if(s[i]=='0'){cnt++;}
}
if(cnt==s.length() || cnt==0){out("Naruto");return 0;}
if(s.length()%2==0){
out("Sasuke");
}
else{
out("Naruto");
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
function LeapYear(year){
// write code here
// return the output using return keyword
// do not use console.log here
if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) {
return 0;
} else {
return 1
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: year = int(input())
if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
int area = LeapYear(side);
if(area==1){
System.out.println("YES");}
else{
System.out.println("NO");}
}
static int LeapYear(int year){
if(year%400==0){return 1;}
if(year%100 != 0 && year%4==0){return 1;}
else {
return 0;}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: static void pattern(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j + " ");
}
System.out.println();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: function pattern(n) {
// write code herenum
for(let i = 1;i<=n;i++){
let str = ''
for(let k = 1; k <= i;k++){
if(k === 1) {
str += `${k}`
}else{
str += ` ${k}`
}
}
console.log(str)
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: def patternPrinting(n):
for i in range(1,n+1):
for j in range (1,i+1):
print(j,end=' ')
print()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T β the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, β the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=0;i<T;i++)
{
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
if(a>b && a>c)
{
System.out.println("Alice");
}
else if(b>a && b>c)
{
System.out.println("Bob");
}
else if(c>a && c>b)
{
System.out.println("Charlie");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T β the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, β the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: #include <bits/stdc++.h>
int main() {
int T = 0;
std::cin >> T;
while (T--) {
int A = 0, B = 0, C = 0;
std::cin >> A >> B >> C;
assert(A != B && B != C && C != A);
if (A > B && A > C) {
std::cout << "Alice" << '\n';
} else if (B > A && B > C) {
std::cout << "Bob" << '\n';
} else {
std::cout << "Charlie" << '\n';
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T β the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, β the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: T = int(input())
for i in range(T):
A,B,C = list(map(int,input().split()))
if A>B and A>C:
print("Alice")
elif B>A and B>C:
print("Bob")
else:
print("Charlie"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N positive integers written on a blackboard: A<sub>1</sub>,. , A<sub>N</sub>.
Edward can perform the following operation when all integers on the blackboard are even:
Replace each integer X on the blackboard by X divided by 2.
Find the maximum possible number of operations that Edward can perform.The input consists of an integer N and N space separated integers.
N
A<sub>1</sub> A<sub>2</sub>. . A<sub>N</sub>
<b>Constraints</b>
1≤N≤200
1≤A<sub>i</sub>≤10^9Print the maximum possible number of operations that Edward can perform.<b>Sample Input 1</b>
3
8 12 40
<b>Sample Output 1</b>
2
<b>Sample Input 2</b>
4
5 6 8 10
<b>Sample Output 2</b>
0, I have written this Solution Code: #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int minCnt = 1000000000;
for (int i = 0; i < N; i++) {
int A;
cin >> A;
int cnt = 0;
while (A % 2 == 0) {
cnt++;
A /= 2;
}
if (cnt < minCnt) {
minCnt = cnt;
}
}
cout << minCnt << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the upper triangular matrix and the lower triangular matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Upper Triangular:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
_____M<sub>11</sub> M<sub>12</sub>
__________M<sub>22</sub>
Lower Triangular:-
M<sub>00</sub>__________
M<sub>10</sub> M<sub>11</sub>_____
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>The first line of input contains a single integer N, The next N lines of input contains N space- separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of Upper and Lower Triangular Matrix separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
11 9
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
20 19, I have written this Solution Code: N = int(input())
mat =[]
for i in range(N):
List = list(map(int,input().split()))[:N]
mat.append(List)
upMat = 0
lowMat = 0
for i in range(N):
for j in range(N):
if i<=j:
upMat += mat[i][j]
for i in range(len(mat[0])):
for j in range(len(mat[0])):
if j<=i:
lowMat += mat[i][j]
print(upMat,lowMat), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the upper triangular matrix and the lower triangular matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Upper Triangular:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
_____M<sub>11</sub> M<sub>12</sub>
__________M<sub>22</sub>
Lower Triangular:-
M<sub>00</sub>__________
M<sub>10</sub> M<sub>11</sub>_____
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>The first line of input contains a single integer N, The next N lines of input contains N space- separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of Upper and Lower Triangular Matrix separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
11 9
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
20 19, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[][]= new int[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
a[i][j]=sc.nextInt();
}
}
int sum=0,sum1=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(j>=i){sum+=a[i][j];}
if(i>=j){sum1+=a[i][j];}
}
}
System.out.print(sum+" "+sum1);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the upper triangular matrix and the lower triangular matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Upper Triangular:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
_____M<sub>11</sub> M<sub>12</sub>
__________M<sub>22</sub>
Lower Triangular:-
M<sub>00</sub>__________
M<sub>10</sub> M<sub>11</sub>_____
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>The first line of input contains a single integer N, The next N lines of input contains N space- separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of Upper and Lower Triangular Matrix separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
11 9
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
20 19, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int n;
cin>>n;
int a[n][n];
FOR(i,n){
FOR(j,n){
cin>>a[i][j];}}
int sum=0,sum1=0;;
FOR(i,n){
FOR(j,n){
if(j>=i){sum+=a[i][j];}
if(i>=j){sum1+=a[i][j];}
}
}
out1(sum);out(sum1);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the Armstrong numbers which are present between 1 to N.
<b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N.
Constraints:-
1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:-
2
Sample Output:-
1
Sample input:-
4
Sample Output:
1, I have written this Solution Code: import math
n= int(input())
for i in range (1,n+1):
arm=i
summ=0
while(arm!=0):
rem=math.pow(arm%10,3)
summ=summ+rem
arm=math.floor(arm/10)
if summ == i :
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the Armstrong numbers which are present between 1 to N.
<b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N.
Constraints:-
1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:-
2
Sample Output:-
1
Sample input:-
4
Sample Output:
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
bool checkArmstrong(int n)
{
int temp = n, sum = 0;
while(n > 0)
{
int d = n%10;
sum = sum + d*d*d;
n = n/10;
}
if(sum == temp)
return true;
return false;
}
int main()
{
int n;
cin>>n;
for(int i = 1; i <= n; i++)
{
if(checkArmstrong(i) == true)
cout << i << " ";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the Armstrong numbers which are present between 1 to N.
<b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N.
Constraints:-
1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:-
2
Sample Output:-
1
Sample input:-
4
Sample Output:
1, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int digitsum,num,digit;
for(int i=1;i<=n;i++){
digitsum=0;
num=i;
while(num>0){
digit=num%10;
digitsum+=digit*digit*digit;
num/=10;
}
if(digitsum==i){System.out.print(i+" ");}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two numbers n and p. You need to find n raised to the power p.<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>RecursivePower</b> that takes the integer n and p as a parameter.
Constraints:
1 <= T <= 10
1 <= n, p <= 9Return n^p.Sample Input:
3
2 3
9 9
2 9
Sample Output:
8
387420489β¬
512
Explanation:
Test case 2: 387420489 is the value obtained when 9 is raised to the power of 9.
Test case 3: 512 is the value obtained when 2 is raised to the power of 9, I have written this Solution Code:
static int Power(int n,int p)
{
if(p==0)
return 1;
return n*Power(n,p-1);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc =new Scanner(System.in);
int T= sc.nextInt();
for(int i=0;i<T;i++){
int arrsize=sc.nextInt();
int max=0,secmax=0,thirdmax=0,j;
for(int k=0;k<arrsize;k++){
j=sc.nextInt();
if(j>max){
thirdmax=secmax;
secmax=max;
max=j;
}
else if(j>secmax){
thirdmax=secmax;
secmax=j;
}
else if(j>thirdmax){
thirdmax=j;
}
if(k%10000==0){
System.gc();
}
}
System.out.println(max+" "+secmax+" "+thirdmax+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: t=int(input())
while t>0:
t-=1
n=int(input())
l=list(map(int,input().strip().split()))
li=[0,0,0]
for i in l:
x=i
for j in range(0,3):
y=min(x,li[j])
li[j]=max(x,li[j])
x=y
print(li[0],end=" ")
print(li[1],end=" ")
print(li[2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
vector<long> a(n);
long ans[3]={0};
long x,y;
for(int i=0;i<n;i++){
cin>>a[i];
x=a[i];
for(int j=0;j<3;j++){
y=min(x,ans[j]);
ans[j]=max(x,ans[j]);
// cout<<ans[j]<<" ";
x=y;
}
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
if(ans[2]<ans[1]){
swap(ans[1],ans[2]);
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: function maxNumbers(arr,n) {
// write code here
// do not console.log the answer
// return the answer as an array of 3 numbers
return arr.sort((a,b)=>b-a).slice(0,3)
};
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |