Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: You are given an array(Arr) of N Distinct integers. You have to find the sum of minimum element of all the subarrays (continous) in that array. See Sample for better understanding.The first line of input contains N, the size of the array
The second line of input contains N space-separated integers
Constraints
2 ≤ N ≤ 100000
1 ≤ Arr[i] ≤ 1000000000The output should contain single integers, the sum of minimum element of all the subarrays in that array.Sample Input
3
1 2 3
Sample Output
10
Explaination
all subarrays [1] [1,2] [1,2,3] [2] [2,3] [3]
Sum of minimums : 1 + 1 + 1 + 2 + 2 + 3 = 10, I have written this Solution Code:
def sumSubarrayMins(A, n):
left, right = [None] * n, [None] * n
s1, s2 = [], []
for i in range(0, n):
cnt = 1
while len(s1) > 0 and s1[-1][0] > A[i]:
cnt += s1[-1][1]
s1.pop()
s1.append([A[i], cnt])
left[i] = cnt
for i in range(n - 1, -1, -1):
cnt = 1
while len(s2) > 0 and s2[-1][0] > A[i]:
cnt += s2[-1][1]
s2.pop()
s2.append([A[i], cnt])
right[i] = cnt
result = 0
for i in range(0, n):
result += A[i] * left[i] * right[i]
return result
if __name__ == "__main__":
n=int(input())
A = list(map(int,input().split()))
print(sumSubarrayMins(A, n))
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array(Arr) of N Distinct integers. You have to find the sum of minimum element of all the subarrays (continous) in that array. See Sample for better understanding.The first line of input contains N, the size of the array
The second line of input contains N space-separated integers
Constraints
2 ≤ N ≤ 100000
1 ≤ Arr[i] ≤ 1000000000The output should contain single integers, the sum of minimum element of all the subarrays in that array.Sample Input
3
1 2 3
Sample Output
10
Explaination
all subarrays [1] [1,2] [1,2,3] [2] [2,3] [3]
Sum of minimums : 1 + 1 + 1 + 2 + 2 + 3 = 10, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
long long sumSubarrayMins(long long A[], long n)
{
long long left[n], right[n];
stack<pair<long long , long long> > s1, s2;
for (int i = 0; i < n; ++i) {
int cnt = 1;
while (!s1.empty() && (s1.top().first) > A[i]) {
cnt += s1.top().second;
s1.pop();
}
s1.push({ A[i], cnt });
left[i] = cnt;
}
// getting number of element larger than A[i] on Right.
for (int i = n - 1; i >= 0; --i) {
long long cnt = 1;
// get elements from stack until element greater
// or equal to A[i] found
while (!s2.empty() && (s2.top().first) >= A[i]) {
cnt += s2.top().second;
s2.pop();
}
s2.push({ A[i], cnt });
right[i] = cnt;
}
long long result = 0;
for (int i = 0; i < n; ++i)
result = (result + A[i] * left[i] * right[i]);
return result;
}
int main()
{
int n;
cin>>n;
long long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
cout << sumSubarrayMins(a, n);
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code: function numberOfDays(n)
{
let ans;
switch(n)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
ans = Number(31);
break;
case 2:
ans = Number(28);
break;
default:
ans = Number(30);
break;
}
return ans;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code:
static void numberofdays(int M){
if(M==4 || M ==6 || M==9 || M==11){System.out.print(30);}
else if(M==2){System.out.print(28);}
else{
System.out.print(31);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String a= br.readLine();
int sum=0;
int n=a.length();
int s=0;
for(int i=0; i<n; i++){
sum=sum+ (a.charAt(i) - '0');
if(i == n-1){
s= (a.charAt(i) - '0');
}
}
if(sum%3==0 && s==0){
System.out.print("Yes");
}else{
System.out.print("No");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-02-10 11:06:49
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int solve(string a) {
int n = a.size();
int sum = 0;
if (a[n - 1] != '0') {
return 0;
}
for (auto &it : a) {
sum += (it - '0');
}
debug(sum % 3);
if (sum % 3 == 0) {
return 1;
}
return 0;
}
int32_t main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
string str;
cin >> str;
int res = solve(str);
if (res) {
cout << "Yes\n";
} else {
cout << "No\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, I have written this Solution Code: A=int(input())
if A%30==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: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: a, b, v = map(int, input().strip().split(" "))
c = abs(a-b)
t = c//v
print(t), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
System.out.print(Time(n,m,k));
}
static int Time(int A, int B, int S){
if(B>A){
return (B-A)/S;
}
return (A-B)/S;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, I have written this Solution Code: import math
n=int(input())
count=0
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
if (n / i == i) :
count=count+1
else:
count=count+2
i = i + 1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
int ans = 0;
for(int i=1; i*i<n; i++){
if(n%i == 0){
ans += 2;
}
}
int nn = sqrt(n);
if(nn*nn == n) {
ans++;
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
long num = sc.nextLong();
System.out.println(possibleValues(num));
}
static int possibleValues(long num)
{
int ans = 0;
for(int i = 1; (long)i*i < num; i++)
{
if(num%i == 0)
ans += 2;
}
int nn = (int)Math.sqrt(num);
if((long)(nn*nn) == num)
ans++;
return ans;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: def getMissingNo(arr, n):
total = (n+1)*(n)//2
sum_of_A = sum(arr)
return total - sum_of_A
N = int(input())
arr = list(map(int,input().split()))
one = getMissingNo(arr,N)
print(one), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n-1];
for(int i=0;i<n-1;i++){
a[i]=sc.nextInt();
}
boolean present = false;
for(int i=1;i<=n;i++){
present=false;
for(int j=0;j<n-1;j++){
if(a[j]==i){present=true;}
}
if(present==false){
System.out.print(i);
return;
}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++){
cin>>a[i];
}
sort(a,a+n-1);
for(int i=1;i<n;i++){
if(i!=a[i-1]){cout<<i<<endl;return 0;}
}
cout<<n;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list consisting of N nodes and an integer K, your task is to delete the Kth node from the end of the linked list<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>deleteElement()</b> that takes head node and K as parameter.
Constraints:
1 <=K<=N<= 1000
1 <=Node.data<= 1000Return the head of the modified linked listInput 1:
5 3
1 2 3 4 5
Output 1:
1 2 4 5
Explanation:
After deleting 3rd node from the end of the linked list, 3 will be deleted and the list will be as 1, 2, 4, 5.
Input 2:-
5 5
8 1 8 3 6
Output 2:-
1 8 3 6 , I have written this Solution Code: public static Node deleteElement(Node head,int k) {
int cnt=0;
Node temp=head;
while(temp!=null){
cnt++;
temp=temp.next;
}
temp=head;
k=cnt-k;
if(k==0){head=head.next; return head;}
temp=head;
cnt=0;
while(cnt!=k-1){
temp=temp.next;
cnt++;
}
temp.next=temp.next.next;
return head;
}, 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 a linked list consisting of N nodes and an integer K, your task is to delete the Kth node from the end of the linked list<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>deleteElement()</b> that takes head node and K as parameter.
Constraints:
1 <=K<=N<= 1000
1 <=Node.data<= 1000Return the head of the modified linked listInput 1:
5 3
1 2 3 4 5
Output 1:
1 2 4 5
Explanation:
After deleting 3rd node from the end of the linked list, 3 will be deleted and the list will be as 1, 2, 4, 5.
Input 2:-
5 5
8 1 8 3 6
Output 2:-
1 8 3 6 , I have written this Solution Code: public static Node deleteElement(Node head,int k) {
int cnt=0;
Node temp=head;
while(temp!=null){
cnt++;
temp=temp.next;
}
temp=head;
k=cnt-k;
if(k==0){head=head.next; return head;}
temp=head;
cnt=0;
while(cnt!=k-1){
temp=temp.next;
cnt++;
}
temp.next=temp.next.next;
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nishu is trying to clean a room, which is divided up into an N by N grid of squares. Each square is initially either clean or dirty. She can sweep her broom over columns of the grid. Her broom is very strange:
if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean.
She wants to sweep some columns of the room to maximize the number of completely clean rows. It is not allowed to sweep over the part of the column, Nishu can only sweep the whole column.
Return the maximum number of rows that she can make completely clean.The first line of the input contains a single integer N.
The next N lines will describe the state of the room. The i- th line will contain a binary string with N characters denoting the state of the i-th row of the room. The j- th character on this line is '1' if the j- th square in the i-th row is clean, and '0' if it is dirty.
Constraints:
1<=N<=100The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.Sample Input 1:
4
0101
1000
1111
0101
Sample output 1:
2
Explanations:
Nishu can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean., I have written this Solution Code: n = int(input())
arr = []
for i in range(n):
string = str(input())
string = string[:4]
arr.append(string)
rows = 0
for i in range(n):
count = 0
for j in range(n):
if arr[i] == arr[j]:
count += 1
rows = max(rows,count)
print(rows), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nishu is trying to clean a room, which is divided up into an N by N grid of squares. Each square is initially either clean or dirty. She can sweep her broom over columns of the grid. Her broom is very strange:
if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean.
She wants to sweep some columns of the room to maximize the number of completely clean rows. It is not allowed to sweep over the part of the column, Nishu can only sweep the whole column.
Return the maximum number of rows that she can make completely clean.The first line of the input contains a single integer N.
The next N lines will describe the state of the room. The i- th line will contain a binary string with N characters denoting the state of the i-th row of the room. The j- th character on this line is '1' if the j- th square in the i-th row is clean, and '0' if it is dirty.
Constraints:
1<=N<=100The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.Sample Input 1:
4
0101
1000
1111
0101
Sample output 1:
2
Explanations:
Nishu can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean., I have written this Solution Code: import java.util.Scanner;
public class Main
{
static String [] ar = new String[105];
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n = sc.nextInt();
for(int i=0;i<n;i++){
ar[i] = sc.next();
}
int ans = 0;
for(int i=0;i<n;i++){
int counter = 0;
for(int j=0;j<n;j++){
if(ar[i].equals(ar[j]))counter++;
}
ans = Math.max(ans, counter);
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, and an integer K your task is to find the lexicographically largest string by removing no more than K characters.The first line of input contains a single string S, and the next line of input contains a single integer K.
<b>Constraints:-</b>
1 <= |S| <= 10<sup>5</sup>
1 <= K <= 10<sup>5</sup>
Note:- String will contain only lowercase English letters.Print the lexicographically largest string possible after removing not more than K characters.Sample Input 1:-
abzccd
4
Sample Output 1:-
zd
Sample Input 2:-
dcba
5
Sample Output 2:-
dcba, 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(){
// freopen("ou.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
string s;
cin>>s;
int k;
cin>>k;
int n = s.length();
queue<int> q[26];
for(int i=0;i<n;i++){
q[s[i]-'a'].push(i);
}
int i=0;
string ans="";
while(i<n){
// out1(i);out(ans);
for(int j=26;j>=0;j--){
while(q[j].size()!=0 && q[j].front()<i){
q[j].pop();
}
if(q[j].size() !=0 && q[j].front()-i<=k){
ans+=(char)((int)'a'+j);
k-=q[j].front()-i;
i=q[j].front()+1;
q[j].pop();
break;
}
}
}
out(ans);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, and an integer K your task is to find the lexicographically largest string by removing no more than K characters.The first line of input contains a single string S, and the next line of input contains a single integer K.
<b>Constraints:-</b>
1 <= |S| <= 10<sup>5</sup>
1 <= K <= 10<sup>5</sup>
Note:- String will contain only lowercase English letters.Print the lexicographically largest string possible after removing not more than K characters.Sample Input 1:-
abzccd
4
Sample Output 1:-
zd
Sample Input 2:-
dcba
5
Sample Output 2:-
dcba, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner inp = new Scanner(System.in);
String str = inp.nextLine();
int n = inp.nextInt();
Stack<Character> st = new Stack<>();
int check = 0;
for(int i = 0 ; i < str.length() ; i++){
if(n > 0){
while(!st.isEmpty() && n > 0 && str.charAt(i) > st.peek()){
st.pop();
n--;
}
st.push(str.charAt(i));
check++;
}
else
continue;
}
String ans = "";
while(!st.isEmpty()){
ans = st.pop() + ans;
}
if(check < str.length()){
ans += str.substring(check, str.length());
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: a, b, v = map(int, input().strip().split(" "))
c = abs(a-b)
t = c//v
print(t), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
System.out.print(Time(n,m,k));
}
static int Time(int A, int B, int S){
if(B>A){
return (B-A)/S;
}
return (A-B)/S;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two positive integers A and B.
Print "First", if A<sup>B</sup> > B<sup>A</sup>.
Print "Second", if A<sup>B</sup> < B<sup>A</sup>.
Otherwise, print "Equal".The only line contains two space-separated integers A and B.
<b>Constraints:</b>
1 ≤ A, B ≤ 4Print a single word – the answer to the problem.Sample Input 1:
1 3
Sample Output 1:
Second
Sample Explanation 1:
As 1<sup>3</sup> < 3<sup>1</sup>, we print "Second".
Sample Input 2:
2 2
Sample Output 2:
Equal
Sample Explanation 2:
As 2<sup>2</sup> = 2<sup>2</sup>, we print "Equal". , 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 s=br.readLine();
String[] arr=s.split(" ");
int a=Integer.parseInt(arr[0]);
int b=Integer.parseInt(arr[1]);
long ab=(long)Math.pow(a,b);
long ba=(long)Math.pow(b,a);
if(ab>ba) System.out.print("First");
else if(ab<ba) System.out.print("Second");
else System.out.print("Equal");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two positive integers A and B.
Print "First", if A<sup>B</sup> > B<sup>A</sup>.
Print "Second", if A<sup>B</sup> < B<sup>A</sup>.
Otherwise, print "Equal".The only line contains two space-separated integers A and B.
<b>Constraints:</b>
1 ≤ A, B ≤ 4Print a single word – the answer to the problem.Sample Input 1:
1 3
Sample Output 1:
Second
Sample Explanation 1:
As 1<sup>3</sup> < 3<sup>1</sup>, we print "Second".
Sample Input 2:
2 2
Sample Output 2:
Equal
Sample Explanation 2:
As 2<sup>2</sup> = 2<sup>2</sup>, we print "Equal". , I have written this Solution Code: a,b=map(int,input().split())
if a**b > b**a:
print("First")
elif a**b <b**a:
print("Second")
else :
print("Equal"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two positive integers A and B.
Print "First", if A<sup>B</sup> > B<sup>A</sup>.
Print "Second", if A<sup>B</sup> < B<sup>A</sup>.
Otherwise, print "Equal".The only line contains two space-separated integers A and B.
<b>Constraints:</b>
1 ≤ A, B ≤ 4Print a single word – the answer to the problem.Sample Input 1:
1 3
Sample Output 1:
Second
Sample Explanation 1:
As 1<sup>3</sup> < 3<sup>1</sup>, we print "Second".
Sample Input 2:
2 2
Sample Output 2:
Equal
Sample Explanation 2:
As 2<sup>2</sup> = 2<sup>2</sup>, we print "Equal". , I have written this Solution Code:
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
long long powm(long long a, long long b,long long mod) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a %mod;
a = a * a %mod;
b >>= 1;
}
return res;
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
if(fopen("input.txt","r"))
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
#endif
int a,b;
cin>>a>>b;
int ans1=1;
for(int i=0;i<b;i++)
ans1*=a;
int ans2=1;
for(int i=0;i<a;i++)
ans2*=b;
if(ans1>ans2)
cout<<"First";
else if(ans1<ans2)
cout<<"Second";
else
cout<<"Equal";
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
int[] arr=new int[5];
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
String[] s=rd.readLine().split(" ");
int sum=0;
for(int i=0;i<5;i++){
arr[i]=Integer.parseInt(s[i]);
sum+=arr[i];
}
int i=0,j=arr.length-1;
boolean isEmergency=false;
while(i<=j)
{
int temp=arr[i];
sum-=arr[i];
if(arr[i]>= sum)
{
isEmergency=true;
break;
}
sum+=temp;
i++;
}
if(isEmergency==false)
{
System.out.println("Stable");
}
else
{
System.out.println("SPD Emergency");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: arr = list(map(int,input().split()))
m = sum(arr)
f=[]
for i in range(len(arr)):
s = sum(arr[:i]+arr[i+1:])
if(arr[i]<s):
f.append(1)
else:
f.append(0)
if(all(f)):
print("Stable")
else:
print("SPD Emergency"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., 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(){
vector<int> vect(5);
int tot = 0;
for(int i=0; i<5; i++){
cin>>vect[i];
tot += vect[i];
}
sort(all(vect));
tot -= vect[4];
if(vect[4] >= tot){
cout<<"SPD Emergency";
}
else{
cout<<"Stable";
}
}
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: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: t=int(input())
while t!=0:
m,n=input().split()
m,n=int(m),int(n)
for i in range(m):
arr=input().strip()
if '1' in arr:
arr='1 '*n
else:
arr='0 '*n
print(arr)
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
int a[N][N];
// Driver code
int main()
{
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
bool b[n];
for(int i=0;i<n;i++){
b[i]=false;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
if(a[i][j]==1){
b[i]=true;
}
}
}
for(int i=0;i<n;i++){
if(b[i]){
for(int j=0;j<m;j++){
cout<<1<<" ";
}}
else{
for(int j=0;j<m;j++){
cout<<0<<" ";
}
}
cout<<endl;
}
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws Exception{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(isr);
int t = Integer.parseInt(bf.readLine());
while (t-- > 0){
String inputs[] = bf.readLine().split(" ");
int m = Integer.parseInt(inputs[0]);
int n = Integer.parseInt(inputs[1]);
String[] matrix = new String[m];
for(int i=0; i<m; i++){
matrix[i] = bf.readLine();
}
StringBuffer ones = new StringBuffer("");
StringBuffer zeros = new StringBuffer("");
for(int i=0; i<n; i++){
ones.append("1 ");
zeros.append("0 ");
}
for(int i=0; i<m; i++){
if(matrix[i].contains("1")){
System.out.println(ones);
}else{
System.out.println(zeros);
}
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, 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 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, 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 n, m;
cin >> n >> m;
cout << __gcd(n, m);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: def hcf(a, b):
if(b == 0):
return a
else:
return hcf(b, a % b)
li= list(map(int,input().strip().split()))
print(hcf(li[0], li[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, 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[] sp = br.readLine().trim().split(" ");
long m = Long.parseLong(sp[0]);
long n = Long.parseLong(sp[1]);
System.out.println(GCDAns(m,n));
}
private static long GCDAns(long m,long n){
if(m==0)return n;
if(n==0)return m;
return GCDAns(n%m,m);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code: static int focal_length(int R, char Mirror)
{
int f=R/2;
if((R%2==1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code:
int focal_length(int R, char Mirror)
{
int f=R/2;
if((R&1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code:
int focal_length(int R, char Mirror)
{
int f=R/2;
if((R&1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code: def focal_length(R,Mirror):
f=R/2;
if(Mirror == ')'):
f=-f
if R%2==1:
f=f-1
return int(f)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: t=int(input())
while t!=0:
m,n=input().split()
m,n=int(m),int(n)
for i in range(m):
arr=input().strip()
if '1' in arr:
arr='1 '*n
else:
arr='0 '*n
print(arr)
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
int a[N][N];
// Driver code
int main()
{
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
bool b[n];
for(int i=0;i<n;i++){
b[i]=false;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
if(a[i][j]==1){
b[i]=true;
}
}
}
for(int i=0;i<n;i++){
if(b[i]){
for(int j=0;j<m;j++){
cout<<1<<" ";
}}
else{
for(int j=0;j<m;j++){
cout<<0<<" ";
}
}
cout<<endl;
}
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws Exception{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(isr);
int t = Integer.parseInt(bf.readLine());
while (t-- > 0){
String inputs[] = bf.readLine().split(" ");
int m = Integer.parseInt(inputs[0]);
int n = Integer.parseInt(inputs[1]);
String[] matrix = new String[m];
for(int i=0; i<m; i++){
matrix[i] = bf.readLine();
}
StringBuffer ones = new StringBuffer("");
StringBuffer zeros = new StringBuffer("");
for(int i=0; i<n; i++){
ones.append("1 ");
zeros.append("0 ");
}
for(int i=0; i<m; i++){
if(matrix[i].contains("1")){
System.out.println(ones);
}else{
System.out.println(zeros);
}
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc =new Scanner(System.in);
int T= sc.nextInt();
for(int i=0;i<T;i++){
int arrsize=sc.nextInt();
int max=0,secmax=0,thirdmax=0,j;
for(int k=0;k<arrsize;k++){
j=sc.nextInt();
if(j>max){
thirdmax=secmax;
secmax=max;
max=j;
}
else if(j>secmax){
thirdmax=secmax;
secmax=j;
}
else if(j>thirdmax){
thirdmax=j;
}
if(k%10000==0){
System.gc();
}
}
System.out.println(max+" "+secmax+" "+thirdmax+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: t=int(input())
while t>0:
t-=1
n=int(input())
l=list(map(int,input().strip().split()))
li=[0,0,0]
for i in l:
x=i
for j in range(0,3):
y=min(x,li[j])
li[j]=max(x,li[j])
x=y
print(li[0],end=" ")
print(li[1],end=" ")
print(li[2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
vector<long> a(n);
long ans[3]={0};
long x,y;
for(int i=0;i<n;i++){
cin>>a[i];
x=a[i];
for(int j=0;j<3;j++){
y=min(x,ans[j]);
ans[j]=max(x,ans[j]);
// cout<<ans[j]<<" ";
x=y;
}
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
if(ans[2]<ans[1]){
swap(ans[1],ans[2]);
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: function maxNumbers(arr,n) {
// write code here
// do not console.log the answer
// return the answer as an array of 3 numbers
return arr.sort((a,b)=>b-a).slice(0,3)
};
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, 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 s=br.readLine().toString();
int n=Integer.parseInt(s);
int ch=0;
if(n>0){
ch=1;
}
else if(n<0) ch=-1;
switch(ch){
case 1: System.out.println("Positive");break;
case 0: System.out.println("Zero");break;
case -1: System.out.println("Negative");break;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: n = input()
if '-' in list(n):
print('Negative')
elif int(n) == 0 :
print('Zero')
else:
print('Positive'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: #include <stdio.h>
int main()
{
int num;
scanf("%d", &num);
switch (num > 0)
{
// Num is positive
case 1:
printf("Positive");
break;
// Num is either negative or zero
case 0:
switch (num < 0)
{
case 1:
printf("Negative");
break;
case 0:
printf("Zero");
break;
}
break;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){
n-=32;
n/=9;
n*=5;
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: Fahrenheit= int(input())
Celsius = int(((Fahrenheit-32)*5)/9 )
print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit)
{
int celsius = ((farhrenheit-32)*5)/9;
System.out.println(celsius);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A (distinct integers) of size N, and you are also given a sum. You need to find if two numbers in A exists that have sum equal to the given sum.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains N denoting the size of the array A and target sum. The second line contains N elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= sum <= 10^5
1 <= A[i] <= 10^4For each testcase, in a new line, print "1"(without quotes) if any pair found, othwerwise print "0"(without quotes) if not found.Sample Input
2
10 14
1 2 3 4 5 6 7 8 9 10
2 10
2 5
Sample Output
1
0
Explanation:
Testcase 1: arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and sum = 14. There is a pair {4, 10} with sum 14.
Testcase 2: arr[] = {2, 5} and sum = 10. There is no pair with sum 10., I have written this Solution Code: import numpy as np
from collections import defaultdict
t=int(input())
def solve():
d=defaultdict(int)
n,s=input().strip().split()
s=int(s)
a=np.array([input().strip().split()],int).flatten()
for i in a:
d[i]+=1
c=0
for i in a:
if(d[s-i]>0 and (s-i)!=i):
c=1
break
print(c)
while(t>0):
solve()
t-=1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A (distinct integers) of size N, and you are also given a sum. You need to find if two numbers in A exists that have sum equal to the given sum.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains N denoting the size of the array A and target sum. The second line contains N elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= sum <= 10^5
1 <= A[i] <= 10^4For each testcase, in a new line, print "1"(without quotes) if any pair found, othwerwise print "0"(without quotes) if not found.Sample Input
2
10 14
1 2 3 4 5 6 7 8 9 10
2 10
2 5
Sample Output
1
0
Explanation:
Testcase 1: arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and sum = 14. There is a pair {4, 10} with sum 14.
Testcase 2: arr[] = {2, 5} and sum = 10. There is no pair with sum 10., 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
signed main()
{
int t;
cin>>t;
while(t>0)
{ t--;
int ch=0;
int n,sum;
cin>>n>>sum;
int A[n];
set<int> ss;
for(int i=0;i<n;i++)
{
cin>>A[i];
if(ss.find(sum-A[i])!=ss.end()) ch=1;
ss.insert(A[i]);
}
cout<<ch<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A (distinct integers) of size N, and you are also given a sum. You need to find if two numbers in A exists that have sum equal to the given sum.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains N denoting the size of the array A and target sum. The second line contains N elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= sum <= 10^5
1 <= A[i] <= 10^4For each testcase, in a new line, print "1"(without quotes) if any pair found, othwerwise print "0"(without quotes) if not found.Sample Input
2
10 14
1 2 3 4 5 6 7 8 9 10
2 10
2 5
Sample Output
1
0
Explanation:
Testcase 1: arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and sum = 14. There is a pair {4, 10} with sum 14.
Testcase 2: arr[] = {2, 5} and sum = 10. There is no pair with sum 10., I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt();
for(int i = 1; i <= testCases; i++)
{
int arrSize = sc.nextInt();
int sum = sc.nextInt();
int arr[] = new int[arrSize];
for(int j = 0; j < arrSize; j++)
arr[j] = sc.nextInt();
System.out.println(pairFound(arr, arrSize, sum));
}
}
static int pairFound(int arr[], int arrSize, int sum)
{
HashSet<Integer> hSet = new HashSet<>();
for(int i = 0; i < arrSize; i++)
{
if(hSet.contains(sum-arr[i]) == true)
return 1;
hSet.add(arr[i]);
}
return 0;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an Array A of N integers. For each i (1 <= i <= N), find the rightmost (largest) index j (1 <= j <= N) such that A<sub>j</sub> >= A<sub>i</sub>.First line of input contains a single integer N.
Second line of input contains N integers, denoting the elements of the array.
Constraints:
1 <= N <= 100000
1 <= A[i] <= 1000000000Print N space separated integers the values of j for each i from 1 to N.Sample Input:
5
5 2 4 3 1
Sample Output:
1 4 3 4 5
, I have written this Solution Code: n = int(input())
l = list(map(int,input().split()))
suffix = [-1]*n
curr = 0
for i in range(n-1,-1,-1):
curr = max(curr,l[i])
suffix[i] = max(l[i],curr)
ans = [i for i in range(n)]
for i in range(n-1):
fi = i+1
li = n-1
while(fi <= li):
mid = fi + (li-fi)//2
if(l[i] <= suffix[mid]):
ans[i] = mid
fi = mid+1
if(l[i] > suffix[mid]):
li = mid-1
for i in ans:
print(i+1,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. For each i (1 <= i <= N), find the rightmost (largest) index j (1 <= j <= N) such that A<sub>j</sub> >= A<sub>i</sub>.First line of input contains a single integer N.
Second line of input contains N integers, denoting the elements of the array.
Constraints:
1 <= N <= 100000
1 <= A[i] <= 1000000000Print N space separated integers the values of j for each i from 1 to N.Sample Input:
5
5 2 4 3 1
Sample Output:
1 4 3 4 5
, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
pair<int,int> p[n];
int ans[n];
for(int i=0;i<n;++i){
cin>>p[i].F;
p[i].S=i;
}
sort(p,p+n);
int ma=0;
for(int i=n-1;i>=0;--i){
ma=max(ma,p[i].S);
ans[p[i].S]=ma;
}
for(int i=0;i<n;++i)
cout<<ans[i]+1<<" ";
#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: Bob has a string S consisting of lowercase English letters. He defines S′ to be the string after removing all "a" characters from S (keeping all other characters in the same order). He then generates a new string T by concatenating S and S′. In other words, T=S+S′.
You are given a string T. Your task is to find some S that Bob could have used to generate T. It can be shown that if an answer exists, it will be unique.The first line contains a single string S.
Constraints:
1<=|S|<=100000Print a string S that could have generated T. It can be shown if an answer exists, it is unique. If no string exists, print ":(" (without double quotes, there is no space between the characters).Sample Input 1:
ababacacbbcc
Sample Output 1:
ababacac
Explanations:
we have s= "ababacac", and s′= "bbcc", and t=s+s′= "ababacacbbcc"., I have written this Solution Code: import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String S = in.next();
StringBuilder sb = new StringBuilder();
for (char c : S.toCharArray()) {
if (c != 'a') {
sb.append(c);
}
}
boolean ok = true;
if (sb.length() % 2 == 0) {
int length = sb.length()/2;
for (int i=0; i<length; i++) {
if (sb.charAt(i) != sb.charAt(i+length)) {
ok = false;
break;
}
}
if (S.lastIndexOf('a') >= S.length() - length) {
ok = false;
}
if (ok) {
System.out.println(S.subSequence(0, S.length() - length));
}
} else {
ok = false;
}
if (!ok) {
System.out.println(":(");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Bob has a string S consisting of lowercase English letters. He defines S′ to be the string after removing all "a" characters from S (keeping all other characters in the same order). He then generates a new string T by concatenating S and S′. In other words, T=S+S′.
You are given a string T. Your task is to find some S that Bob could have used to generate T. It can be shown that if an answer exists, it will be unique.The first line contains a single string S.
Constraints:
1<=|S|<=100000Print a string S that could have generated T. It can be shown if an answer exists, it is unique. If no string exists, print ":(" (without double quotes, there is no space between the characters).Sample Input 1:
ababacacbbcc
Sample Output 1:
ababacac
Explanations:
we have s= "ababacac", and s′= "bbcc", and t=s+s′= "ababacacbbcc"., I have written this Solution Code: inp = input()
inp1 = inp.replace('a','')
l = len(inp1)//2
ind = len(inp)-l
if(inp[0:ind]+inp1[l:] == inp ):
print(inp[0:ind])
else:
print(":("), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
String s[]=bu.readLine().split(" ");
long a=Long.parseLong(s[0]),b=Long.parseLong(s[1]);
if(a>=b) sb.append("Chandler");
else sb.append("Joey");
System.out.print(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., 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 a,b;
cin>>a>>b;
if(a>=b)
cout<<"Chandler";
else
cout<<"Joey";
#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: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: ch,jo=map(int,input().split())
if ch>=jo:
print('Chandler')
else:
print('Joey'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, in one operation you can subtract any odd divisor from the number other than the number itself. You have to find the minimum number of operation needed to convert the number to 1.The input contains a single integer N.
Constraints:-
1 <= N <= 10000Print the minimum number of operations needed to convert the given number to 1.Sample Input:-
10
Sample Output:-
5
Explanation:-
10- >5- >4- >3- >2- >1
Sample Input:-
20
Sample Output:-
7, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int dp[100005];
int solve(int n){
//cout<<n<<" ";
if(dp[n]==-1){
int x=INT_MAX;
int y = sqrt(n);
for(int i=1;i<=y;i++){
if(n%i==0){
if(i&1){
x=min(solve(n-i),x);
}
if(((n/i)&1) && i>1){
x=min(solve(n-n/i),x);
}
}
}
dp[n]=x+1;
}
return dp[n];
}
int main(){
for(int i=0;i<10005;i++){
dp[i]=-1;
}
int n;
cin>>n;
dp[1]=0;
dp[2]=1;
cout<<solve(n)<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, I have written this Solution Code: import math
n=int(input())
count=0
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
if (n / i == i) :
count=count+1
else:
count=count+2
i = i + 1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
int ans = 0;
for(int i=1; i*i<n; i++){
if(n%i == 0){
ans += 2;
}
}
int nn = sqrt(n);
if(nn*nn == n) {
ans++;
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
long num = sc.nextLong();
System.out.println(possibleValues(num));
}
static int possibleValues(long num)
{
int ans = 0;
for(int i = 1; (long)i*i < num; i++)
{
if(num%i == 0)
ans += 2;
}
int nn = (int)Math.sqrt(num);
if((long)(nn*nn) == num)
ans++;
return ans;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: static void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
System.out.print(x+4*j+" ");
}
System.out.println();
x+=6;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: def Pattern(N):
x=0
for i in range (0,N):
for j in range (0,N):
print(x+4*j,end=' ')
print()
x = x+6
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcase = Integer.parseInt(br.readLine());
for(int t=0;t<testcase;t++){
int num = Integer.parseInt(br.readLine().trim());
if(num==1)
System.out.println("No");
else if(num<=3)
System.out.println("Yes");
else{
if((num%2==0)||(num%3==0))
System.out.println("No");
else{
int flag=0;
for(int i=5;i*i<=num;i+=6){
if(((num%i)==0)||(num%(i+2)==0)){
System.out.println("No");
flag=1;
break;
}
}
if(flag==0)
System.out.println("Yes");
}
}
}
}catch (Exception e) {
System.out.println("I caught: " + e);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: t=int(input())
for i in range(t):
number = int(input())
if number > 1:
i=2
while i*i<=number:
if (number % i) == 0:
print("No")
break
i+=1
else:
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n,k;
cin>>n;
long x=sqrt(n);
int cnt=0;
vector<int> v;
for(long long i=2;i<=x;i++){
if(n%i==0){
cout<<"No"<<endl;
goto f;
}}
cout<<"Yes"<<endl;
f:;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of N positive integers and a number K. The task is to find the kth largest element in the array.
Note: DO NOT USE sort() stl.First line of input contains number of testcases. For each testcase, there will be a single line of input containing number of elements in the array and K. Next line contains N elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= arr[i] <= 10^5
1 <= K <= NFor each testcase, print a single line of output containing the kth largest element in the array.Sample Input:
2
5 3
3 5 4 2 9
5 5
4 3 7 6 5
Sample Output:
4
3
Explanation:
Testcase 1: Third largest element in the array is 4.
Testcase 2: Fifth largest element in the array is 3., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
Reader sc = new Reader();
int t = sc.nextInt();
while(t!=0)
{
int n= sc.nextInt();
int k=sc.nextInt();
int arr[]= new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
System.out.println(findKthLargest(arr,k));
t--;
}
}
public static int largestEle(int []arr,int k)
{
PriorityQueue<Integer> pq= new PriorityQueue<>(Collections.reverseOrder ());
for(int i=0;i<arr.length;i++)
{
pq.offer(arr[i]);
}
for(int i=0;i<k-1;i++)
{
pq.poll();
}
return pq.peek();
}
public static int findKthLargest(int[] nums, int k) {
int start = 0, end = nums.length - 1, index = nums.length - k;
while (start < end) {
int pivot = partion(nums, start, end);
if (pivot < index) start = pivot + 1;
else if (pivot > index) end = pivot - 1;
else return nums[pivot];
}
return nums[start];
}
private static int partion(int[] nums, int start, int end) {
int pivot = start, temp;
while (start <= end) {
while (start <= end && nums[start] <= nums[pivot]) start++;
while (start <= end && nums[end] > nums[pivot]) end--;
if (start > end) break;
temp = nums[start];
nums[start] = nums[end];
nums[end] = temp;
}
temp = nums[end];
nums[end] = nums[pivot];
nums[pivot] = temp;
return end;
}
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of N positive integers and a number K. The task is to find the kth largest element in the array.
Note: DO NOT USE sort() stl.First line of input contains number of testcases. For each testcase, there will be a single line of input containing number of elements in the array and K. Next line contains N elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= arr[i] <= 10^5
1 <= K <= NFor each testcase, print a single line of output containing the kth largest element in the array.Sample Input:
2
5 3
3 5 4 2 9
5 5
4 3 7 6 5
Sample Output:
4
3
Explanation:
Testcase 1: Third largest element in the array is 4.
Testcase 2: Fifth largest element in the array is 3., I have written this Solution Code:
t=int(input())
while t>0:
t-=1
n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
print(arr[k-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of N positive integers and a number K. The task is to find the kth largest element in the array.
Note: DO NOT USE sort() stl.First line of input contains number of testcases. For each testcase, there will be a single line of input containing number of elements in the array and K. Next line contains N elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^4
1 <= arr[i] <= 10^5
1 <= K <= NFor each testcase, print a single line of output containing the kth largest element in the array.Sample Input:
2
5 3
3 5 4 2 9
5 5
4 3 7 6 5
Sample Output:
4
3
Explanation:
Testcase 1: Third largest element in the array is 4.
Testcase 2: Fifth largest element in the array is 3., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];}
sort(a,a+n);
cout<<a[n-k]<<endl;
}
}
, 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 the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<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_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
cout<<j<<" ";
}
for(int j=i-1;j>=1;j--){
cout<<j<<" ";
}
cout<<endl;
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
cout<<j<<" ";
}
for(int j=i-1;j>=1;j--){
cout<<j<<" ";
}
cout<<endl;
}
}, 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 the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<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_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code:
void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
for(int j=i-1;j>=1;j--){
printf("%d ",j);
}
printf("\n");
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
for(int j=i-1;j>=1;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 an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<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_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: public static void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j+" ");
}
for(int j=i-1;j>=1;j--){
System.out.print(j+" ");
}
System.out.println();
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
System.out.print(j+" ");
}
for(int j=i-1;j>=1;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 an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<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_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: function patternMaking(N)
{
for(let j=1; j <= 2*N - 1; j++) {
let k;
if(j<= N) {
k = j;
} else {
k = 2*N - j;
}
let res = "";
for(let i=1; i<=2*k-1; i++) {
if(i<=k) {
res += i + " ";
} else {
res += 2*k - i + " ";
}
}
console.log(res);
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<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_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: def pattern_making(n):
for i in range(1, n+1):
for j in range(1, i+1):
print(j,end=" ")
for j in range (1,i):
print(i-j,end=" ")
print("\r")
i=n-1
while i>=1 :
for j in range(1, i+1):
print(j,end=" ")
for j in range (1,i):
print(i-j,end=" ")
print("\r")
i=i-1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String a= br.readLine();
int sum=0;
int n=a.length();
int s=0;
for(int i=0; i<n; i++){
sum=sum+ (a.charAt(i) - '0');
if(i == n-1){
s= (a.charAt(i) - '0');
}
}
if(sum%3==0 && s==0){
System.out.print("Yes");
}else{
System.out.print("No");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-02-10 11:06:49
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int solve(string a) {
int n = a.size();
int sum = 0;
if (a[n - 1] != '0') {
return 0;
}
for (auto &it : a) {
sum += (it - '0');
}
debug(sum % 3);
if (sum % 3 == 0) {
return 1;
}
return 0;
}
int32_t main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
string str;
cin >> str;
int res = solve(str);
if (res) {
cout << "Yes\n";
} else {
cout << "No\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, I have written this Solution Code: A=int(input())
if A%30==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: Complete the function <code>callThisFnBack</code>
Such that it takes a number as the first argument and a function (callback function) as the second argument. You have to pass the first argument of the function <code>callThisFnBack</code> to the callback function and execute the callback function inside the <code>callThisFnBack</code> and return its result.The function will take two arguments, one which is a number and the second which will be a function.Returns the result of the second argument which is the callback function when its argument is the first argument of the function <code>callThisFnBack</code>.const result = callThisFnBack(5, (num)=>{
return num+6
})
console.log(result) // prints 11 because 5+6
const newFn = (number) => {
return number - 5
}
const newResult = callThisFnBack(5,newFn)
console.log(newResult) // prints 0 because 5-5=0, 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 num = sc.nextInt();
int ans = 0;
char operate = sc.next().charAt(0);
switch(operate){
case '+':
ans = num + num;
break;
case '-' :
ans = num - num;
break;
case '*':
ans = num * num;
break;
case '/':
ans = num / num;
break;
}
System.out.print(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the function <code>callThisFnBack</code>
Such that it takes a number as the first argument and a function (callback function) as the second argument. You have to pass the first argument of the function <code>callThisFnBack</code> to the callback function and execute the callback function inside the <code>callThisFnBack</code> and return its result.The function will take two arguments, one which is a number and the second which will be a function.Returns the result of the second argument which is the callback function when its argument is the first argument of the function <code>callThisFnBack</code>.const result = callThisFnBack(5, (num)=>{
return num+6
})
console.log(result) // prints 11 because 5+6
const newFn = (number) => {
return number - 5
}
const newResult = callThisFnBack(5,newFn)
console.log(newResult) // prints 0 because 5-5=0, I have written this Solution Code: function callThisFnBack(number, fn) {
return fn(number)
// return the output using return keyword
// do not console.log it
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S.
Constraints:
1 <= T <= 100
1 <= |S| <= 1000
Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input:
2
Bawdsjogflickquartzvenymph
sdfs
Output:
0
0
Explanation :
Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0.
Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: def ispangram(str):
alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in alphabet:
if char not in str.lower():
return False
return True
N = int(input())
arr = []
for i in range(N):
arr.append(input())
for i in range(N):
if(ispangram(arr[i]) == True):
print(1)
else:
print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S.
Constraints:
1 <= T <= 100
1 <= |S| <= 1000
Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input:
2
Bawdsjogflickquartzvenymph
sdfs
Output:
0
0
Explanation :
Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0.
Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: function pangrams(s) {
// write code here
// do not console.log it
// return 1 or 0
let alphabet = "abcdefghijklmnopqrstuvwxyz";
let regex = /\s/g;
let lowercase = s.toLowerCase().replace(regex, "");
for(let i = 0; i < alphabet.length; i++){
if(lowercase.indexOf(alphabet[i]) === -1){
return 0;
}
}
return 1;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S.
Constraints:
1 <= T <= 100
1 <= |S| <= 1000
Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input:
2
Bawdsjogflickquartzvenymph
sdfs
Output:
0
0
Explanation :
Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0.
Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
String s = sc.next();
int check = 1;
int p =0;
for(char ch = 'a';ch<='z';ch++){
p=0;
for(int i = 0;i<s.length();i++){
if(s.charAt(i)==ch){p=1;}
}
if(p==0){check=0;}
}
System.out.println(check);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S.
Constraints:
1 <= T <= 100
1 <= |S| <= 1000
Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input:
2
Bawdsjogflickquartzvenymph
sdfs
Output:
0
0
Explanation :
Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0.
Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
int A[26],B[26];
signed main()
{
int t;
cin>>t;
string p;
getline(cin,p);
while(t>0)
{
t--;
string s;
getline(cin,s);
int n=s.size();
memset(A,0,sizeof(A));
int ch=1;
for(int i=0;i<n;i++)
{
int x=s[i]-'a';
if(x>=0 && x<26)
{
A[x]++;
}
x=s[i]-'A';
if(x>=0 && x<26)
{
A[x]++;
}
}
for(int i=0;i<26;i++)
{
if(A[i]==0) ch=0;
}
cout<<ch<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code: class Solution {
public static int Rare(int n, int k){
while(n>0){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code: def Rare(N,K):
while N>0:
if(N%10)%K!=0:
return 0
N=N//10
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code:
int Rare(int n, int k){
while(n){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code:
int Rare(int n, int k){
while(n){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.