Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args){
FastReader read = new FastReader();
int a = read.nextInt();
int b = read.nextInt();
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(){
InputStreamReader inr = new InputStreamReader(System.in);
br = new BufferedReader(inr);
}
String next(){
while(st==null || !st.hasMoreElements())
try{
st = new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
long nextLong(){
return Long.parseLong(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split())
print(a+b)
print(a-b)
print(a*b)
print(a//b), 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: #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: There is a row of N shops. Each shop sells A[i] candies. Your friend made an array B of (N-1) integers where B[i] = max(A[i], A[i+1]) for i from 1 to (N-1). You are given array B. You want to generate the array A such that the sum of values of the candies in A is maximum. Find the maximum possible sum of candies of array A.The first line of input contains a single integer N.
The second line of input contains (N-1) integers denoting array B.
<b>Constraints:</b>
2 ≤ N ≤ 10<sup>5</sup>
1 ≤ B[i] ≤ 10<sup>9</sup>Print the maximum possible sum of the candies in array A.Sample Input
4
1 3 4
Sample Output
9
<b>Explanation:</b>
Optimal Array A will be [1, 1, 3, 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 n = sc.nextInt();
long b[] = new long[n-1];
long sum=0;
for(int i=0;i<n-1;i++)
{
b[i] = sc.nextLong();
}
for(int i=0;i<n-2;i++)
{
if(b[i]>b[i+1])
{
sum += b[i+1];
}
else
{
sum += b[i];
}
}
sum += b[n-2];
System.out.println(sum+b[0]);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a row of N shops. Each shop sells A[i] candies. Your friend made an array B of (N-1) integers where B[i] = max(A[i], A[i+1]) for i from 1 to (N-1). You are given array B. You want to generate the array A such that the sum of values of the candies in A is maximum. Find the maximum possible sum of candies of array A.The first line of input contains a single integer N.
The second line of input contains (N-1) integers denoting array B.
<b>Constraints:</b>
2 ≤ N ≤ 10<sup>5</sup>
1 ≤ B[i] ≤ 10<sup>9</sup>Print the maximum possible sum of the candies in array A.Sample Input
4
1 3 4
Sample Output
9
<b>Explanation:</b>
Optimal Array A will be [1, 1, 3, 4], I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
#define rep(i,n) for (int i=0; i<(n); i++)
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
--n;
for(int i=0;i<n;++i){
cin>>a[i];
}
int ans=a[0]+a[n-1];
int v=0;
for(int i=1;i<n;++i){
ans+=min(a[i],a[i-1]);
}
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a row of N shops. Each shop sells A[i] candies. Your friend made an array B of (N-1) integers where B[i] = max(A[i], A[i+1]) for i from 1 to (N-1). You are given array B. You want to generate the array A such that the sum of values of the candies in A is maximum. Find the maximum possible sum of candies of array A.The first line of input contains a single integer N.
The second line of input contains (N-1) integers denoting array B.
<b>Constraints:</b>
2 ≤ N ≤ 10<sup>5</sup>
1 ≤ B[i] ≤ 10<sup>9</sup>Print the maximum possible sum of the candies in array A.Sample Input
4
1 3 4
Sample Output
9
<b>Explanation:</b>
Optimal Array A will be [1, 1, 3, 4], I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
summ=arr[-1]
for i in reversed(range(1,len(arr))):
if arr[i]>arr[i-1]:
summ+=arr[i-1]
else:
summ+=arr[i]
summ+=arr[0]
print(summ), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int[]sort(int n, int a[]){
int i,key;
for(int j=1;j<n;j++){
key=a[j];
i=j-1;
while(i>=0 && a[i]>key){
a[i+1]=a[i];
i=i-1;
}
a[i+1]=key;
}
return a;
}
public static void main (String[] args) throws IOException {
InputStreamReader io = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(io);
int n = Integer.parseInt(br.readLine());
String str = br.readLine();
String stra[] = str.trim().split(" ");
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = Integer.parseInt(stra[i]);
}
a=sort(n,a);
int max=0;
for(int i=0;i<n;i++)
{
if(a[i]+a[n-i-1]>max)
{
max=a[i]+a[n-i-1];
}
}
System.out.println(max);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: n=int(input())
arr=input().split()
for i in range(0,n):
arr[i]=int(arr[i])
arr=sorted(arr,key=int)
start=0
end=n-1
ans=0
while(start<end):
ans=max(ans,arr[end]+arr[start])
start+=1
end-=1
print (ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 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;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
sort(a,a+n);
int ma=0;
for(int i=0;i<n;++i){
ma=max(ma,a[i]+a[n-i-1]);
}
cout<<ma;
#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: 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: 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 number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: #include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define ma 10000001
bool a[ma];
int main()
{
int n;
cin>>n;
for(int i=0;i<=n;i++){
a[i]=false;
}
for(int i=2;i<=n;i++){
if(a[i]==false){
for(int j=i+i;j<=n;j+=i){
a[j]=true;
}
}
}
int cnt=0;
for(int i=2;i<=n;i++){
if(a[i]==false){cnt++;}
}
cout<<cnt;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args)
throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long n = Integer.parseInt(br.readLine());
long i=2,j,count,noOfPrime=0;
if(n<=1)
System.out.println("0");
else{
while(i<=n)
{
count=0;
for(j=2; j<=Math.sqrt(i); j++)
{
if( i%j == 0 ){
count++;
break;
}
}
if(count==0){
noOfPrime++;
}
i++;
}
System.out.println(noOfPrime);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: function numberOfPrimes(N)
{
let arr = new Array(N+1);
for(let i = 0; i <= N; i++)
arr[i] = 0;
for(let i=2; i<= N/2; i++)
{
if(arr[i] === -1)
{
continue;
}
let p = i;
for(let j=2; p*j<= N; j++)
{
arr[p*j] = -1;
}
}
//console.log(arr);
let count = 0;
for(let i=2; i<= N; i++)
{
if(arr[i] === 0)
{
count++;
}
}
//console.log(arr);
return count;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import math
n = int(input())
n=n+1
if n<3:
print(0)
else:
primes=[1]*(n//2)
for i in range(3,int(math.sqrt(n))+1,2):
if primes[i//2]:primes[i*i//2::i]=[0]*((n-i*i-1)//(2*i)+1)
print(sum(primes)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args){
FastReader read = new FastReader();
int a = read.nextInt();
int b = read.nextInt();
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(){
InputStreamReader inr = new InputStreamReader(System.in);
br = new BufferedReader(inr);
}
String next(){
while(st==null || !st.hasMoreElements())
try{
st = new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
long nextLong(){
return Long.parseLong(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split())
print(a+b)
print(a-b)
print(a*b)
print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Being told that an unsorted array contains (n - 1) of n consecutive numbers (where the bounds are defined), find the missing number in O(n) time.
The bounds tell that all the numbers between the lower bound and the upper bound are present in the array except one number which is missing. You have to find that missing number.The function takes three arguments , the first argument is the array of integers, the second argument is the upper bound and the third argument is the lower bound.
All the numbers between the lower and the upper bounds are present in the array (inclusive of both upper and lower bound) except one number which is missing.
Input is provided in the form of an array which would have 3 elements. The first element is the array of integers, the second element is the upper bound and the third element is the lower bound. All three elements are used internally to call the function.
Example: [[1, 4, 3] ,4, 1]
Here, [1,4,3] is the array of integers
4 is the upper bound
1 is the lower boundThe function should print the missing number in the console.const input = [[1, 4, 3] ,4, 1];
const arr = input[0];
const upper_bound = input[1];
const lower_bound = input[2];
findMissingNumber(arr, upper_bound, lower_bound); //prints 2
// Explanation: From numbers 1 to 4, only 2 is missing from the array, I have written this Solution Code:
function findMissingNumber(arrayOfIntegers, upperBound, lowerBound) {
// Iterate through array to find the sum of the numbers
let sumOfIntegers = 0;
for (let i = 0; i < arrayOfIntegers.length; i++) {
sumOfIntegers += arrayOfIntegers[i];
}
// Find theoretical sum of the consecutive numbers using a variation of Gauss Sum.
// Formula: [(N * (N + 1)) / 2] - [(M * (M - 1)) / 2];
// N is the upper bound and M is the lower bound
upperLimitSum = (upperBound * (upperBound + 1)) / 2;
lowerLimitSum = (lowerBound * (lowerBound - 1)) / 2;
theoreticalSum = upperLimitSum - lowerLimitSum;
console.log(theoreticalSum - sumOfIntegers);
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code: def countMultiples(N):
return int(100/N)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code: static int countMultiples(int N)
{
int i = 1, count = 0;
while(i < 101){
if(i % N == 0)
count++;
i++;
}
return count;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code:
int countMultiples(int n){
return (100/n);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code:
int countMultiples(int n){
return (100/n);
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pree says he stole Daenerys' dragons, and would return them to Daenerys only if she can pair the dragons in a peculiar way.
There are N (N is even) dragons, the strength of i<sup>th</sup> dragon is A<sub>i</sub>. She needs to create N/2 pairs of the dragons. The strength of the dragon pair is the sum of the strengths of dragons in the pair. She needs to pair them in such a way that the difference between the strength of dragon pair with maximum strength and the strength of the dragon pair with minimum strength is minimised.
Now, you need to find the minimum difference in strengths if she has paired them correctly.The first line of the input contains an integer N, the number of dragons.
The second line of the input contains N integers, the strengths of the dragons.
Constraints
1 <= N <= 200000 (so many dragons, huh)
1 <= A<sub>i</sub> <= 10<sup>9</sup> for all values of i
N is divisible by 2Output a single integer, the answer to the problem.Sample Input
4
1 2 1 2
Sample Output
0
Explanation
Daenerys pairs 1st and the 2nd dragons together; the 3rd and the 4th dragon together
Sample Input
6
2 3 2 4 5 1
Sample Output
1, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.StringTokenizer;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
};
public static void main(String[] args) {
FastReader sc = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int n=sc.nextInt();
long arr[]=new long[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextLong();
}
Arrays.sort(arr);
long min=Long.MAX_VALUE;
long max=Long.MIN_VALUE;
for(int i=0;i<n/2;i++)
{
min=Math.min(min,arr[n-i-1]+arr[i]);
max=Math.max(max,arr[n-i-1]+arr[i]);
}
System.out.println(max-min);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pree says he stole Daenerys' dragons, and would return them to Daenerys only if she can pair the dragons in a peculiar way.
There are N (N is even) dragons, the strength of i<sup>th</sup> dragon is A<sub>i</sub>. She needs to create N/2 pairs of the dragons. The strength of the dragon pair is the sum of the strengths of dragons in the pair. She needs to pair them in such a way that the difference between the strength of dragon pair with maximum strength and the strength of the dragon pair with minimum strength is minimised.
Now, you need to find the minimum difference in strengths if she has paired them correctly.The first line of the input contains an integer N, the number of dragons.
The second line of the input contains N integers, the strengths of the dragons.
Constraints
1 <= N <= 200000 (so many dragons, huh)
1 <= A<sub>i</sub> <= 10<sup>9</sup> for all values of i
N is divisible by 2Output a single integer, the answer to the problem.Sample Input
4
1 2 1 2
Sample Output
0
Explanation
Daenerys pairs 1st and the 2nd dragons together; the 3rd and the 4th dragon together
Sample Input
6
2 3 2 4 5 1
Sample Output
1, I have written this Solution Code: n = int(input())
bruh = input().strip().split(" ")
for i in range(len(bruh)):
bruh[i] = int(bruh[i])
bruh.sort()
maxSum = 0
minSum = 100000000000000000000
for i in range(len(bruh)//2):
add = bruh[i] + bruh[-(i+1)]
if add > maxSum:
maxSum = add
if add < minSum:
minSum = add
print(maxSum - minSum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pree says he stole Daenerys' dragons, and would return them to Daenerys only if she can pair the dragons in a peculiar way.
There are N (N is even) dragons, the strength of i<sup>th</sup> dragon is A<sub>i</sub>. She needs to create N/2 pairs of the dragons. The strength of the dragon pair is the sum of the strengths of dragons in the pair. She needs to pair them in such a way that the difference between the strength of dragon pair with maximum strength and the strength of the dragon pair with minimum strength is minimised.
Now, you need to find the minimum difference in strengths if she has paired them correctly.The first line of the input contains an integer N, the number of dragons.
The second line of the input contains N integers, the strengths of the dragons.
Constraints
1 <= N <= 200000 (so many dragons, huh)
1 <= A<sub>i</sub> <= 10<sup>9</sup> for all values of i
N is divisible by 2Output a single integer, the answer to the problem.Sample Input
4
1 2 1 2
Sample Output
0
Explanation
Daenerys pairs 1st and the 2nd dragons together; the 3rd and the 4th dragon together
Sample Input
6
2 3 2 4 5 1
Sample Output
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
vector<int> v(n);
For(i, 0, n){
cin>>v[i];
}
sort(all(v));
vector<int> cur;
For(i, 0, n/2){
cur.pb(v[i]+v[n-i-1]);
}
sort(all(cur));
cout<<cur[n/2-1]-cur[0];
}
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 an array <b>A</b> of size <b>N</b>. Find the minimum subsequence size of this array such that the sum of its elements is <b>at least K</b>. If there is no such subsequence possible, print -1.
<b>Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. </b>First line of the input contains two integers N and K.
The second line of input contains N space- seperated integers.
Constraint:
1 <= N <= 10<sup>5</sup>
1 <= K <= 10<sup>14</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print the minimum size of the required subsequence. If there is no such possible subsequence, print -1.Sample Input:
5 17
9 4 7 6 2
Sample Output:
3
Explaination:
We can use the subsequence {4, 7, 6}. Their sum = 4 + 7 + 6 = 17.
We cannot obtain sum 17 in less than 3 subsequence size., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(r);
String line[] = br.readLine().strip().split(" ");
int n = Integer.parseInt(line[0]);
long k = Long.parseLong(line[1]);
int arr[] = new int[n];
line = br.readLine().strip().split(" ");
for(int i=0; i<n; i++){
arr[i] = Integer.parseInt(line[i]);
}
Arrays.sort(arr);
long sum = 0;
int ans = -1;
for(int i=n-1; i>=0; i--){
sum+=arr[i];
if(sum >= k){
ans = n-1-i+1;
break;
}
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size <b>N</b>. Find the minimum subsequence size of this array such that the sum of its elements is <b>at least K</b>. If there is no such subsequence possible, print -1.
<b>Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. </b>First line of the input contains two integers N and K.
The second line of input contains N space- seperated integers.
Constraint:
1 <= N <= 10<sup>5</sup>
1 <= K <= 10<sup>14</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print the minimum size of the required subsequence. If there is no such possible subsequence, print -1.Sample Input:
5 17
9 4 7 6 2
Sample Output:
3
Explaination:
We can use the subsequence {4, 7, 6}. Their sum = 4 + 7 + 6 = 17.
We cannot obtain sum 17 in less than 3 subsequence size., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using T = pair<int, int>;
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 1e9;
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for(auto &i : a) cin >> i;
sort(rall(a));
int cur = 0;
for(int i = 0; i < n; i++){
cur += a[i];
if(cur >= k){
cout << i + 1;
return;
}
}
cout << -1;
}
signed main(){
fast
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
if(i != t) cout << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: def compound_interest(principle, rate, time):
Amount = principle * (pow((1 + rate / 100), time))
CI = Amount - principle
print( '%.2f'%CI)
principle,rate,time=map(int, input().split())
compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: function calculateCI(P, R, T)
{
let interest = P * (Math.pow(1.0 + R/100.0, T) - 1);
return interest.toFixed(2);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int p,r,t;
cin>>p>>r>>t;
double rate= (float)r/100;
double amt = (float)p*(pow(1+rate,t));
cout << fixed << setprecision(2) << (amt - p);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s= br.readLine().split(" ");
double[] darr = new double[s.length];
for(int i=0;i<s.length;i++){
darr[i] = Double.parseDouble(s[i]);
}
double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0];
System.out.printf("%.2f",ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You were gifted an array Arr of N integers for your last birthday. You want to play with that array but the last element of the array is missing. All you remember is that the xor of all the elements of the array was zero. Print the maximum possible value of the last element.First line of input contains N.
Second line of input contains first N-1 elements of the array Arr that you remember.
Constraints
2 <= N <= 100000
0 <= Arr[i] <= 1000000000Print the maximum possible value of the last element.Sample input
5
1 5 1 3
Sample output
6
Explanation :
(1 ^ 5 ^ 1 ^ 3 ^ 6 ) = 0 and 6 is maximum such possible number, 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 n=sc.nextInt();
int []x = new int[n-1];
for(int i=0;i<n-1;i++){
x[i]=sc.nextInt();
}
int a=x[0];
for(int i=1;i<n-1;i++){
a ^= x[i];
}
System.out.println(a);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You were gifted an array Arr of N integers for your last birthday. You want to play with that array but the last element of the array is missing. All you remember is that the xor of all the elements of the array was zero. Print the maximum possible value of the last element.First line of input contains N.
Second line of input contains first N-1 elements of the array Arr that you remember.
Constraints
2 <= N <= 100000
0 <= Arr[i] <= 1000000000Print the maximum possible value of the last element.Sample input
5
1 5 1 3
Sample output
6
Explanation :
(1 ^ 5 ^ 1 ^ 3 ^ 6 ) = 0 and 6 is maximum such possible number, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int x=0;
for(int i=1;i<n;++i)
{
int d;
cin>>d;
x^=d;
}
cout<<x;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a doubly linked list consisting of N nodes and two integers <b>P</b> and <b>K</b>. Your task is to add an element K at the Pth position from the start 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>insertnew()</b>. The description of parameters are mentioned below:
<b>head</b>: head node of the double linked list
<b>K</b>: the element which you have to insert
<b>P</b>: the position at which you have insert
Constraints:
1 <= P <=N <= 1000
1 <=K, Node.data<= 1000
In the sample Input N, P and K are in the order as mentioned below:
<b>N P K</b>Return the head of the modified linked list.Sample Input:-
5 3 2
1 3 2 4 5
Sample Output:-
1 3 2 2 4 5, I have written this Solution Code: public static Node insertnew(Node head, int k,int pos) {
int cnt=1;
if(pos==1){Node temp=new Node(k);
temp.next=head;
head.prev=temp;
return temp;}
Node temp=head;
while(cnt!=pos-1){
temp=temp.next;
cnt++;
}
Node x= new Node(k);
x.next=temp.next;
temp.next.prev=x;
temp.next=x;
x.prev=temp;
return head;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code: static int RotationPolicy(int A, int B){
int cnt=0;
for(int i=A;i<=B;i++){
if((i-1)%2!=0 && (i-1)%3!=0){cnt++;}
}
return cnt;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code:
def RotationPolicy(A, B):
cnt=0
for i in range (A,B+1):
if(i-1)%2!=0 and (i-1)%3!=0:
cnt=cnt+1
return cnt
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach.
On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day.
For example, on:
Day 1 - Both players play,
Day 2 - Neither of them plays,
Day 3 - Only Dom plays,
Day 4 - Only Leach plays,
Day 5 - Only Dom plays,
Day 6 - Neither of them plays,
Day 7 - Both the players play.. and so on.
Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>RotationPolicy()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:-
3 8
Sample Output:-
2
Sample Input:-
1 4
Sample Output:-
1, I have written this Solution Code: function RotationPolicy(a, b) {
// write code here
// do no console.log the answer
// return the output using return keyword
let count = 0
for (let i = a; i <= b; i++) {
if((i-1)%2 !== 0 && (i-1)%3 !==0){
count++
}
}
return count
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a rook is placed at a position (X, Y). Your task is to find the minimum steps Rook will take to go to the position (1, 1).The input contains two integer X and Y.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Print the number of steps rook will take to go to the position (X, Y).Sample Input:-
2 4
Sample Output:-
2
Explanation:-
one of the possible paths is:-
(2, 4) - > (2, 1) - > (1, 1)
Sample Input:-
1 2
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
int X = scan.nextInt();
int Y = scan.nextInt();
if((X == 1) && (Y == 1)){
System.out.println(0);
}
else if((X == 1) || (Y == 1)){
System.out.println(1);
}
else{
System.out.println(2);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a rook is placed at a position (X, Y). Your task is to find the minimum steps Rook will take to go to the position (1, 1).The input contains two integer X and Y.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Print the number of steps rook will take to go to the position (X, Y).Sample Input:-
2 4
Sample Output:-
2
Explanation:-
one of the possible paths is:-
(2, 4) - > (2, 1) - > (1, 1)
Sample Input:-
1 2
Sample Output:-
1, I have written this Solution Code: X, Y = [int(x) for x in input().split()]
if X == 1 and Y == 1:
print(0)
elif X == 1 or Y == 1:
print(1)
else:
print(2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a rook is placed at a position (X, Y). Your task is to find the minimum steps Rook will take to go to the position (1, 1).The input contains two integer X and Y.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Print the number of steps rook will take to go to the position (X, Y).Sample Input:-
2 4
Sample Output:-
2
Explanation:-
one of the possible paths is:-
(2, 4) - > (2, 1) - > (1, 1)
Sample Input:-
1 2
Sample Output:-
1, I have written this Solution Code: #include <iostream>
using namespace std;
int Rook(int X, int Y){
//Enter your code here
if(X==1 && Y==1){return 0;}
if(X==1 || Y==1){return 1;}
return 2;
}
int main(){
int x,y;
scanf("%d%d",&x,&y);
printf("%d",Rook(x,y));
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code:
// X and Y are numbers
// ignore number of testcases variable
function pow(X, Y) {
// write code here
// console.log the output in a single line,like example
console.log(Math.pow(X, Y).toFixed(2))
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: def power(N,K):
return ("{0:.2f}".format(N**K))
T=int(input())
for i in range(T):
X,N = map(float,input().strip().split())
print(power(X,N)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main (String[] args)throws Exception {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0)
{
String str[] = read.readLine().trim().split(" ");
double X = Double.parseDouble(str[0]);
int N = Integer.parseInt(str[1]);
System.out.println(String.format("%.2f", myPow(X, N)));
}
}
public static double myPow(double x, int n) {
if (n == Integer.MIN_VALUE)
n = - (Integer.MAX_VALUE - 1);
if (n == 0)
return 1.0;
else if (n < 0)
return 1 / myPow(x, -n);
else if (n % 2 == 1)
return x * myPow(x, n - 1);
else {
double sqrt = myPow(x, n / 2);
return sqrt * sqrt;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define ld long double
#define int long long int
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define endl '\n'
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
ld power(ld x, ld n){
if(n == 0)
return 1;
else
return x*power(x, n-1);
}
signed main() {
speed;
int t; cin >> t;
while(t--){
double x; int n;
cin >> x >> n;
if(n < 0)
x = 1.0/x, n *= -1;
cout << setprecision(2) << fixed << power(x, n) << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, I have written this Solution Code: n=int(input())
li = list(map(int,input().strip().split()))
for i in range(0,n-2):
if li[i]==li[i+1] and li[i+1]==li[i+2]:
print("Yes",end="")
exit()
print("No",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
vector<int> a(n);
bool fl = false;
For(i, 0, n){
cin>>a[i];
if(i>=2){
if(a[i]==a[i-1] && a[i]==a[i-2]){
fl = true;
}
}
}
if(fl){
cout<<"Yes";
}
else
cout<<"No";
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
for(int i=0;i<n-2;i++){
if(a[i]==a[i+1] && a[i+1]==a[i+2]){
System.out.print("Yes");
return;
}
}
System.out.print("No");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: static void pattern(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j + " ");
}
System.out.println();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: function pattern(n) {
// write code herenum
for(let i = 1;i<=n;i++){
let str = ''
for(let k = 1; k <= i;k++){
if(k === 1) {
str += `${k}`
}else{
str += ` ${k}`
}
}
console.log(str)
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: def patternPrinting(n):
for i in range(1,n+1):
for j in range (1,i+1):
print(j,end=' ')
print()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. A string is called good if it is a prefix of string S. A string is called well if it is of even length and can be divided into two equal sub-strings of equal length. Find number of sub-strings which are both good and well.First line contains a string S.
Constraints
1<=|S|<=100000
String S can contain char (a-z, A-Z), or one digit integers (0-9).Print the answer.Sample Input
aacaacc
Sample Output
2
Explanation
aa, aacaac are two substrings
Sample Input
1111
Sample Output
2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
int count=0;
int mid;
boolean flag=true;
if(str.length() >=2){
for(int i=0,j=1;j<str.length();j+=2){
mid=(j+1)/2;
flag=true;
for(int l=0,m=mid;i<mid && m<j+1;l++,m++){
if(str.charAt(l)!=str.charAt(m)){
flag=false;
break;
}
}
if(flag){
++count;
}
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. A string is called good if it is a prefix of string S. A string is called well if it is of even length and can be divided into two equal sub-strings of equal length. Find number of sub-strings which are both good and well.First line contains a string S.
Constraints
1<=|S|<=100000
String S can contain char (a-z, A-Z), or one digit integers (0-9).Print the answer.Sample Input
aacaacc
Sample Output
2
Explanation
aa, aacaac are two substrings
Sample Input
1111
Sample Output
2, I have written this Solution Code: s=input()
a=''
count=0
for i in range(len(s)//2+1):
a+=s[i]
if a==s[i+1:i+len(a)+1]:
count+=1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. A string is called good if it is a prefix of string S. A string is called well if it is of even length and can be divided into two equal sub-strings of equal length. Find number of sub-strings which are both good and well.First line contains a string S.
Constraints
1<=|S|<=100000
String S can contain char (a-z, A-Z), or one digit integers (0-9).Print the answer.Sample Input
aacaacc
Sample Output
2
Explanation
aa, aacaac are two substrings
Sample Input
1111
Sample Output
2, 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 sz 2000005
int z[sz];
signed main()
{
string s;
cin>>s;
int n=s.size();
int l=0,r=0;
int no=0;
for(int i=1;i<n;i++)
{
if(i<=r) z[i]=min(r-l+1,z[i-l]);
while(i+z[i]<n && s[z[i]]==s[i+z[i]]) z[i]++;
if(i+z[i]-1>r) r=i+z[i]-1,l=i;
if(s[i]!='0' && z[i]>=i && i<=n/2) no++;
}
cout<<no<<endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code:
function mul (x) {
return function (y) { // anonymous function
return function (z) { // anonymous function
console.log(x*y*z);
};
};
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, 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 a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.println(a*b*c);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code: x,y,z= map(int,input().split())
print(x*y*z), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: static void simpleSum(int a, int b, int c){
System.out.println(a+b+c);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: void simpleSum(int a, int b, int c){
cout<<a+b+c;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: x = input()
a, b, c = x.split()
a = int(a)
b = int(b)
c = int(c)
print(a+b+c), 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: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc =new Scanner(System.in);
int T= sc.nextInt();
for(int i=0;i<T;i++){
int arrsize=sc.nextInt();
int max=0,secmax=0,thirdmax=0,j;
for(int k=0;k<arrsize;k++){
j=sc.nextInt();
if(j>max){
thirdmax=secmax;
secmax=max;
max=j;
}
else if(j>secmax){
thirdmax=secmax;
secmax=j;
}
else if(j>thirdmax){
thirdmax=j;
}
if(k%10000==0){
System.gc();
}
}
System.out.println(max+" "+secmax+" "+thirdmax+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: t=int(input())
while t>0:
t-=1
n=int(input())
l=list(map(int,input().strip().split()))
li=[0,0,0]
for i in l:
x=i
for j in range(0,3):
y=min(x,li[j])
li[j]=max(x,li[j])
x=y
print(li[0],end=" ")
print(li[1],end=" ")
print(li[2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
vector<long> a(n);
long ans[3]={0};
long x,y;
for(int i=0;i<n;i++){
cin>>a[i];
x=a[i];
for(int j=0;j<3;j++){
y=min(x,ans[j]);
ans[j]=max(x,ans[j]);
// cout<<ans[j]<<" ";
x=y;
}
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
if(ans[2]<ans[1]){
swap(ans[1],ans[2]);
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: function maxNumbers(arr,n) {
// write code here
// do not console.log the answer
// return the answer as an array of 3 numbers
return arr.sort((a,b)=>b-a).slice(0,3)
};
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N elements. Find the maximum value of GCD(Arr[i], Arr[j]) where i != j.First line of input contains a single integer N.
Second line of input contains N space separated integers, denoting array Arr.
Constraints:
2 <= N <= 100000
1 <= Arr[i] <= 100000Print the maximum value of GCD(Arr[i], Arr[j]) where i != j.Sample Input 1
5
2 4 5 2 2
Sample Output 1
2
Explanation: We can select index 1 and index 4, GCD(2, 2) = 2
Sample Input 2
6
4 3 4 1 6 5
Sample Output 2
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int result(int a[],int n)
{
int maxe =0;
for(int i=0;i<n;i++)
maxe = Math.max(maxe,a[i]);
int count[]=new int[maxe+1];
for(int i=0;i<n;i++)
{
for(int j=1;j<Math.sqrt(a[i]);j++)
{
if(a[i]%j==0)
{
count[j]++;
if (j != a[i] / j)
count[a[i] / j]++;
}
}
}
for(int i=maxe;i>0;i--)
{
if(count[i]>1)
return i;
}
return 1;
}
public static void main (String[] args) throws IOException{
InputStreamReader i = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(i);
int n = Integer.parseInt(br.readLine());
int a[] = new int[n];
String str = br.readLine();
String[] strs = str.trim().split(" ");
for (int j = 0; j < n; j++)
{
a[j] = Integer.parseInt(strs[j]);
}
System.out.println(result(a,n));
}
}, 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 elements. Find the maximum value of GCD(Arr[i], Arr[j]) where i != j.First line of input contains a single integer N.
Second line of input contains N space separated integers, denoting array Arr.
Constraints:
2 <= N <= 100000
1 <= Arr[i] <= 100000Print the maximum value of GCD(Arr[i], Arr[j]) where i != j.Sample Input 1
5
2 4 5 2 2
Sample Output 1
2
Explanation: We can select index 1 and index 4, GCD(2, 2) = 2
Sample Input 2
6
4 3 4 1 6 5
Sample Output 2
4, 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 v[100001]={};
int n;
cin>>n;
for(int i=1;i<=n;++i){
int d;
cin>>d;
for(int j=1;j*j<=d;++j){
if(d%j==0){
v[j]++;
if(j!=d/j)
v[d/j]++;
}
}
}
for(int i=100000;i>=1;--i)
if(v[i]>1){
cout<<i;
return 0;
}
}, 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: 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: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order so she randomly marks X questions true and rest False.
Given the value of X, your task is to tell Sara what will be the minimum marks she can get<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>minimumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the minimum marks she can get.Sample Input:-
X = 3
Sample Output:-
4
Sample Input:-
10
Sample Output:-
10, I have written this Solution Code:
int minimumMarks(int X){
if(X>5){
return 10-2*(10-X);
}
return 10-2*X;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order so she randomly marks X questions true and rest False.
Given the value of X, your task is to tell Sara what will be the minimum marks she can get<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>minimumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the minimum marks she can get.Sample Input:-
X = 3
Sample Output:-
4
Sample Input:-
10
Sample Output:-
10, I have written this Solution Code: def minimumMarks(X):
if X>5:
return 10-2*(10-X)
return 10-2*(X)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order so she randomly marks X questions true and rest False.
Given the value of X, your task is to tell Sara what will be the minimum marks she can get<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>minimumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the minimum marks she can get.Sample Input:-
X = 3
Sample Output:-
4
Sample Input:-
10
Sample Output:-
10, I have written this Solution Code: static int minimumMarks(int X){
if(X>5){
return 10-2*(10-X);
}
return 10-2*X;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order so she randomly marks X questions true and rest False.
Given the value of X, your task is to tell Sara what will be the minimum marks she can get<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>minimumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the minimum marks she can get.Sample Input:-
X = 3
Sample Output:-
4
Sample Input:-
10
Sample Output:-
10, I have written this Solution Code:
int minimumMarks(int X){
if(X>5){
return 10-2*(10-X);
}
return 10-2*X;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: To seek revenge on Midgard, Loki devises a plan to torture the humans by making them take part in one of his silly games. He makes N people sit in a circle. He says he will kill every kth person sitting in the circle, starting from 1st person.
Loki performs his revenge prank until and unless 1 survivor remains.
What is the initial position of the survivor, if the indexing is clockwise?The first line of input contains a single integer T. The next T line of input contains Two space separated integers each containing value of N and k.
<b>Constraints:</b>
1 <= T <= 100
1 <= k, N <= 20Print the initial position of the survivor.Sample Input:
2
3 2
5 3
Sample Output
3
4
Explanation:
Test case 1: There are 3 people so skipping 1 person i.e 1st person 2nd person will be killed in next step 3rd person will be skipped and 1st person will be killed. Thus the safe position is 3.
Test case 2: 2 people i.e 1and 2 are skipped and person 3 will be killed in next step 4 and 5 will be skipped and 1st person will be killed next step 2 and 4 will be skipped and 5th person will be killed next step first 2 will be skipped then 4 will be skipped and so coming back to 2 therefore person 2 will be killed. Thus the safe position is 4., I have written this Solution Code: t=int(input())
while t>0:
n,k=map(int,input().split())
s=set()
remove=0
for i in range(1,n+1):
s.add(i)
i=1
while True:
if len(s)==1:
break
if i in s:
remove+=1
if remove==k:
if i in s:
s.remove(i)
remove=0
i+=1
if i>n:
i=1
print(*s)
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: To seek revenge on Midgard, Loki devises a plan to torture the humans by making them take part in one of his silly games. He makes N people sit in a circle. He says he will kill every kth person sitting in the circle, starting from 1st person.
Loki performs his revenge prank until and unless 1 survivor remains.
What is the initial position of the survivor, if the indexing is clockwise?The first line of input contains a single integer T. The next T line of input contains Two space separated integers each containing value of N and k.
<b>Constraints:</b>
1 <= T <= 100
1 <= k, N <= 20Print the initial position of the survivor.Sample Input:
2
3 2
5 3
Sample Output
3
4
Explanation:
Test case 1: There are 3 people so skipping 1 person i.e 1st person 2nd person will be killed in next step 3rd person will be skipped and 1st person will be killed. Thus the safe position is 3.
Test case 2: 2 people i.e 1and 2 are skipped and person 3 will be killed in next step 4 and 5 will be skipped and 1st person will be killed next step 2 and 4 will be skipped and 5th person will be killed next step first 2 will be skipped then 4 will be skipped and so coming back to 2 therefore person 2 will be killed. Thus the safe position is 4., I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.*;
class Main{
public static void main (String[] args)throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine().trim());
while(t-->0)
{
String str[] = read.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
System.out.println(safe_Position(n,k));
}
}
public static int safe_Position(int n, int k)
{
if (n == 1) //base case
return 1;
else
/* The position returned by safe_Position(n - 1, k) is adjusted because the
recursive call safe_Position(n - 1, k) considers the original position
k%n + 1 as position 1 */
return (safe_Position(n - 1, k) + k-1) % n + 1; //recursion
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring.
For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases.
The first and the only line of each test case contains the string S.
Constraints:
1 ≤ T ≤ 100
1 ≤ length of S ≤ 1000Print length of longest substring having such that all characters are unique .
Sample Input:
2
abababcdefababcdab
gccksfvrgccks
Sample Output:
6
7, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t>0) {
t--;
char [] arr = br.readLine().toCharArray();
int [] hash = new int[256];
int i = 0,j=0,max=0;
while(j != arr.length) {
hash[arr[j]]++;
while (hash[arr[j]] > 1) {
hash[arr[i]]--;
i++;
}
max = Math.max(max, j-i+1);
j++;
}
System.out.println(max);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring.
For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases.
The first and the only line of each test case contains the string S.
Constraints:
1 ≤ T ≤ 100
1 ≤ length of S ≤ 1000Print length of longest substring having such that all characters are unique .
Sample Input:
2
abababcdefababcdab
gccksfvrgccks
Sample Output:
6
7, I have written this Solution Code:
def longestUniqueSubsttr(string):
last_idx = {}
max_len = 0
start_idx = 0
for i in range(0, len(string)):
if string[i] in last_idx:
start_idx = max(start_idx, last_idx[string[i]] + 1)
max_len = max(max_len, i-start_idx + 1)
last_idx[string[i]] = i
return max_len
t=int(input())
while t > 0:
s=input()
print(longestUniqueSubsttr(s))
t -= 1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring.
For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases.
The first and the only line of each test case contains the string S.
Constraints:
1 ≤ T ≤ 100
1 ≤ length of S ≤ 1000Print length of longest substring having such that all characters are unique .
Sample Input:
2
abababcdefababcdab
gccksfvrgccks
Sample Output:
6
7, I have written this Solution Code:
// str is input string
function longestDistinctSubstr(s) {
const mostRecent = new Map(); // Stores the most recent idx
let startIdx = 0, res = 0;
for (let i = 0; i < s.length; i++) {
if (mostRecent.has(s[i]) && mostRecent.get(s[i]) >= startIdx) {
res = Math.max(res, i - startIdx);
startIdx = mostRecent.get(s[i]) + 1;
}
mostRecent.set(s[i], i);
}
return Math.max(res, s.length - startIdx);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring.
For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases.
The first and the only line of each test case contains the string S.
Constraints:
1 ≤ T ≤ 100
1 ≤ length of S ≤ 1000Print length of longest substring having such that all characters are unique .
Sample Input:
2
abababcdefababcdab
gccksfvrgccks
Sample Output:
6
7, I have written this Solution Code: // C++ program to find the length of the longest substring
// without repeating characters
#include <bits/stdc++.h>
using namespace std;
int longestUniqueSubsttr(string str)
{
int n = str.size();
int res = 0; // result
// last index of all characters is initialized
// as -1
vector<int> lastIndex(256, -1);
// Initialize start of current window
int i = 0;
// Move end of current window
for (int j = 0; j < n; j++) {
// Find the last index of str[j]
// Update i (starting index of current window)
// as maximum of current value of i and last
// index plus 1
i = max(i, lastIndex[str[j]] + 1);
// Update result if we get a larger window
res = max(res, j - i + 1);
// Update last index of j.
lastIndex[str[j]] = j;
}
return res;
}
// Driver code
int main()
{
int t;
cin>>t;
while(t>0)
{ t--;
string s;
cin>>s;
int len = longestUniqueSubsttr(s);
cout<<len<<endl;
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A, find the nearest smaller element S[i] for every element A[i] in the array such that the element has an index smaller than i.
More formally,
S[i] for an element A[i] = an element A[j] such that
j is maximum possible AND
j < i AND
A[j] <= A[i]
Elements for which no smaller element exist, consider next smaller element as -1.The first line contains the size of array, n
The next line n elements of the integer array, A[i]
<b>Constraints:</b>
1 <= n <= 10^5
1 <= A[i] <= 10^6Print the integer array S such that S[i] contains nearest smaller number than A[i] such than index of S[i] is less than 'i'. If no such element occurs S[i] should be -1.Input:
5
4 5 2 10 8
Output:
-1 4 -1 2 2
Explanation 1:
index 1: No element less than 4 in left of 4, G[1] = -1
index 2: A[1] is only element less than A[2], G[2] = A[1]
index 3: No element less than 2 in left of 2, G[3] = -1
index 4: A[3] is nearest element which is less than A[4], G[4] = A[3]
index 4: A[3] is nearest element which is less than A[5], G[5] = A[3]
Input:
5
1 2 3 4 5
Output:
-1 1 2 3 4, I have written this Solution Code: size = int(input())
arr = list(map(int,input().split()))
tempArr = arr.copy()
def nearLeast(pos):
for i in range(pos-1,-1,-1):
if(tempArr[i]<=tempArr[pos]):
return tempArr[i]
return -1
for i in range(size):
if(i==0):
arr[0] = -1
else:
arr[i] = nearLeast(i)
print(*arr), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A, find the nearest smaller element S[i] for every element A[i] in the array such that the element has an index smaller than i.
More formally,
S[i] for an element A[i] = an element A[j] such that
j is maximum possible AND
j < i AND
A[j] <= A[i]
Elements for which no smaller element exist, consider next smaller element as -1.The first line contains the size of array, n
The next line n elements of the integer array, A[i]
<b>Constraints:</b>
1 <= n <= 10^5
1 <= A[i] <= 10^6Print the integer array S such that S[i] contains nearest smaller number than A[i] such than index of S[i] is less than 'i'. If no such element occurs S[i] should be -1.Input:
5
4 5 2 10 8
Output:
-1 4 -1 2 2
Explanation 1:
index 1: No element less than 4 in left of 4, G[1] = -1
index 2: A[1] is only element less than A[2], G[2] = A[1]
index 3: No element less than 2 in left of 2, G[3] = -1
index 4: A[3] is nearest element which is less than A[4], G[4] = A[3]
index 4: A[3] is nearest element which is less than A[5], G[5] = A[3]
Input:
5
1 2 3 4 5
Output:
-1 1 2 3 4, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int n; cin >> n;
stack<int> s;
for(int i = 1; i <= n; i++){
cin >> a[i];
while(!s.empty() && a[s.top()] > a[i])
s.pop();
if(s.empty())
cout << -1 << " ";
else
cout << a[s.top()] << " ";
s.push(i);
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A, find the nearest smaller element S[i] for every element A[i] in the array such that the element has an index smaller than i.
More formally,
S[i] for an element A[i] = an element A[j] such that
j is maximum possible AND
j < i AND
A[j] <= A[i]
Elements for which no smaller element exist, consider next smaller element as -1.The first line contains the size of array, n
The next line n elements of the integer array, A[i]
<b>Constraints:</b>
1 <= n <= 10^5
1 <= A[i] <= 10^6Print the integer array S such that S[i] contains nearest smaller number than A[i] such than index of S[i] is less than 'i'. If no such element occurs S[i] should be -1.Input:
5
4 5 2 10 8
Output:
-1 4 -1 2 2
Explanation 1:
index 1: No element less than 4 in left of 4, G[1] = -1
index 2: A[1] is only element less than A[2], G[2] = A[1]
index 3: No element less than 2 in left of 2, G[3] = -1
index 4: A[3] is nearest element which is less than A[4], G[4] = A[3]
index 4: A[3] is nearest element which is less than A[5], G[5] = A[3]
Input:
5
1 2 3 4 5
Output:
-1 1 2 3 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);
int arrSize = sc.nextInt();
int arr[] = new int[arrSize];
for(int i = 0; i < arrSize; i++)
arr[i] = sc.nextInt();
nearSmaller(arr, arrSize);
}
static void nearSmaller(int arr[], int arrSize)
{
Stack<Integer> s = new Stack<>();
for(int i = 0; i < arrSize; i++)
{
while(!s.empty() == true && arr[s.peek()] > arr[i])
s.pop();
if(s.empty() == true)
System.out.print(-1 +" ");
else
System.out.print(arr[s.peek()]+" ");
s.push(i);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: int LastDigit(int N){
return N%10;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: static int LastDigit(int N){
return N%10;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: int LastDigit(int N){
return N%10;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: def LastDigit(N):
return N%10, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code:
int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.