Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Arpit Gupta has brought a toy for his valentine. She is playing with that toy which runs for T seconds when winded.If winded when the toy is already running, from that moment it will run for T seconds (not additional T seconds) For example if T is 10 and toy has run for 5 seconds and winded at this moment then in total it will run for 15 seconds.
Arpit's Valentine winds the toy N times.She winds the toy at t[i] seconds after the first time she winds it.How long will the toy run in total?First Line of input contains two integers N and T
Second Line of input contains N integers, list of time Arpit's Valentine has wound the toy at.
Constraints
1 <= N <= 100000
1 <= T <= 1000000000
1 <= t[i] <= 1000000000
t[0] = 0Print a single integer the total time the toy has run.Sample input 1
2 4
0 3
Sample output 1
7
Sample input 2
2 10
0 5
Sample output 2
15
Explanation:
Testcase1:-
at first the toy is winded at 0 it will go till 4 but it again winded at 3 making it go for more 4 seconds
so the total is 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));
String[] str=br.readLine().split(" ");
int n=Integer.parseInt(str[0]);
int t=Integer.parseInt(str[1]);
int[] arr=new int[n];
str=br.readLine().split(" ");
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(str[i]);
}
int sum=0;
for(int i=1;i<n;i++){
int dif=arr[i]-arr[i-1];
if(dif>t){
sum=sum+t;
}else{
sum=sum+dif;
}
}
sum+=t;
System.out.print(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Arpit Gupta has brought a toy for his valentine. She is playing with that toy which runs for T seconds when winded.If winded when the toy is already running, from that moment it will run for T seconds (not additional T seconds) For example if T is 10 and toy has run for 5 seconds and winded at this moment then in total it will run for 15 seconds.
Arpit's Valentine winds the toy N times.She winds the toy at t[i] seconds after the first time she winds it.How long will the toy run in total?First Line of input contains two integers N and T
Second Line of input contains N integers, list of time Arpit's Valentine has wound the toy at.
Constraints
1 <= N <= 100000
1 <= T <= 1000000000
1 <= t[i] <= 1000000000
t[0] = 0Print a single integer the total time the toy has run.Sample input 1
2 4
0 3
Sample output 1
7
Sample input 2
2 10
0 5
Sample output 2
15
Explanation:
Testcase1:-
at first the toy is winded at 0 it will go till 4 but it again winded at 3 making it go for more 4 seconds
so the total is 7, I have written this Solution Code: n , t = [int(x) for x in input().split() ]
l= [int(x) for x in input().split() ]
c = 0
for i in range(len(l)-1):
if l[i+1] - l[i]<=t:
c+=l[i+1] - l[i]
else:
c+=t
c+=t
print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Arpit Gupta has brought a toy for his valentine. She is playing with that toy which runs for T seconds when winded.If winded when the toy is already running, from that moment it will run for T seconds (not additional T seconds) For example if T is 10 and toy has run for 5 seconds and winded at this moment then in total it will run for 15 seconds.
Arpit's Valentine winds the toy N times.She winds the toy at t[i] seconds after the first time she winds it.How long will the toy run in total?First Line of input contains two integers N and T
Second Line of input contains N integers, list of time Arpit's Valentine has wound the toy at.
Constraints
1 <= N <= 100000
1 <= T <= 1000000000
1 <= t[i] <= 1000000000
t[0] = 0Print a single integer the total time the toy has run.Sample input 1
2 4
0 3
Sample output 1
7
Sample input 2
2 10
0 5
Sample output 2
15
Explanation:
Testcase1:-
at first the toy is winded at 0 it will go till 4 but it again winded at 3 making it go for more 4 seconds
so the total is 7, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
long n,t;
cin>>n>>t;
long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
long cur=t;
long ans=t;
for(int i=1;i<n;i++){
ans+=min(a[i]-a[i-1],t);
}
cout<<ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet.
Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number.
Constraints
2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1
2
Sample Output 1
21
Sample Input 2
4
Sample Output
1008
Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
long n = Long.parseLong(rdr.readLine());
if(n==0 || n==1){
return ;
}
if(n==2){
System.out.println(21);
}
else{
StringBuilder str= new StringBuilder();
str.append("1");
for(long i=0;i<n-3;i++){
str.append("0");
}
if(n%6==0){
str.append("02");
System.out.println(str.toString());
}
else if(n%6==1){
str.append("20");
System.out.println(str.toString());
}
else if(n%6==2){
str.append("11");
System.out.println(str.toString());
}
else if(n%6==3){
str.append("05");
System.out.println(str.toString());
}
if(n%6==4){
str.append("08");
System.out.println(str.toString());
return;
}
else if(n%6==5){
str.append("17");
System.out.println(str.toString());
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet.
Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number.
Constraints
2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1
2
Sample Output 1
21
Sample Input 2
4
Sample Output
1008
Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: n = input()
n=int(n)
n1=10**(n-1)
n2=10**(n)
while(n1<n2):
if((n1%3==0) and (n1%7==0)):
print(n1)
break
n1 = n1+1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet.
Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number.
Constraints
2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1
2
Sample Output 1
21
Sample Input 2
4
Sample Output
1008
Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 100005;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
signed main()
{
fast
int n; cin>>n;
if(n==2){
cout<<"21";
return 0;
}
int mod=1;
for(int i=2; i<=n; i++){
mod = (mod*10)%7;
}
int av = 2;
mod = (mod+2)%7;
while(mod != 0){
av += 3;
mod = (mod+3)%7;
}
string sav = to_string(av);
if(sz(sav)==1){
sav.insert(sav.begin(), '0');
}
string ans = "1";
for(int i=0; i<n-3; i++){
ans += '0';
}
ans += sav;
cout<<ans;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find all phone numbers in the given sentenceInput: SentenceOutput: All the phone numbers in the sentenceInput:
My number is 2112378922
Output:
['2112378922']
, I have written this Solution Code: import re
st=input()
pattern="[0-9]{10}\s"
l=re.findall(pattern,st)
for i in range(len(l)):
l[i]=l[i].strip()
print(l)
, 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 containing positive integers. You need to print the elements of an array in increasing order.The first line of the input denotes the number of test cases 'T'. The first line of the test case is the size of the array and the second line consists of array elements.
For Python Users just complete the given function.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
1 ≤ A[i] ≤ 1000For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
<b>Explanation:</b>
Testcase 1: 1 3 4 7 9 are in sorted form.
Testcase 2: For the given input, 1 2 3 4 5 6 7 8 9 10 are in sorted form., 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 t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << 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 size N containing positive integers. You need to print the elements of an array in increasing order.The first line of the input denotes the number of test cases 'T'. The first line of the test case is the size of the array and the second line consists of array elements.
For Python Users just complete the given function.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
1 ≤ A[i] ≤ 1000For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
<b>Explanation:</b>
Testcase 1: 1 3 4 7 9 are in sorted form.
Testcase 2: For the given input, 1 2 3 4 5 6 7 8 9 10 are in sorted form., I have written this Solution Code: // arr is unsorted array
// n is the number of elements in the array
function bubbleSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], of size N containing positive integers. You need to print the elements of an array in increasing order.The first line of the input denotes the number of test cases 'T'. The first line of the test case is the size of the array and the second line consists of array elements.
For Python Users just complete the given function.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
1 ≤ A[i] ≤ 1000For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
<b>Explanation:</b>
Testcase 1: 1 3 4 7 9 are in sorted form.
Testcase 2: For the given input, 1 2 3 4 5 6 7 8 9 10 are in sorted form., I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int temp;
for(int i=1;i<n;i++){
if(a[i]<a[i-1]){
for(int j=i;j>0;j--){
if(a[j]<a[j-1]){
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
else{
break;
}
}
}
}
for(int i=0;i<n;i++){
System.out.print(a[i]+" ");
}
System.out.println();
}
}
}, 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 containing positive integers. You need to print the elements of an array in increasing order.The first line of the input denotes the number of test cases 'T'. The first line of the test case is the size of the array and the second line consists of array elements.
For Python Users just complete the given function.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
1 ≤ A[i] ≤ 1000For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
<b>Explanation:</b>
Testcase 1: 1 3 4 7 9 are in sorted form.
Testcase 2: For the given input, 1 2 3 4 5 6 7 8 9 10 are in sorted form., I have written this Solution Code: def bubbleSort(arr):
arr.sort()
return arr
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement the function <code>ceil</code>, which should take a number which can be a float(decimal)
and return its result as an integer with ceil function applied to it (Use JS In built functions)Function will take a float as inputFunction will return a numberconsole.log(ceil(1.99)) // prints 2
console.log(ceil(2.1)) // prints 3
console.log(ceil(-1.1)) // prints -1, I have written this Solution Code: function ceil(num){
// write code here
// return the output , do not use console.log here
return Math.ceil(num)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement the function <code>ceil</code>, which should take a number which can be a float(decimal)
and return its result as an integer with ceil function applied to it (Use JS In built functions)Function will take a float as inputFunction will return a numberconsole.log(ceil(1.99)) // prints 2
console.log(ceil(2.1)) // prints 3
console.log(ceil(-1.1)) // prints -1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
float a =sc.nextFloat();
int b=(int)(Math.ceil(a));
System.out.println(b);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ralph likes to play with shapes, he chooses a number <b> n</b> of his choice and tries to make a special triangle shape out of it containing n rows.The input contains N as an input.
</b>Constraint:</b>
1 <b>≤</b> N <b>≤</b> 20Print a special triangle pattern of numbers of height N.Input:
5
Output:
<pre>
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
</pre>, I have written this Solution Code: import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();
for (int i= 0; i<= rows-1 ; i++)
{
for (int j=0; j<=i; j++)
{
System.out.print("*"+ " ");
}
System.out.println("");
}
for (int i=rows-1; i>=0; i--)
{
for(int j=0; j <= i-1;j++)
{
System.out.print("*"+ " ");
}
System.out.println("");
}
sc.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have to complete a function that takes two parameters
<b> First parameter:</b> an array which contains sub array in it at multi level
<b>Second parameter: </b>an integer [depth]
Now your task is to return a new array that have its sub array concatenated into it upto the given specified depth given in the parameter.
Note:- Ignore "Generate Expected Output" for this one, since its not a DSA question the function <code>findTheString(array, depth)</code> take two parameters
<b> First Parameter: </b> array which contains sub arrays
<b> Second parameter: </b> <code>depth</code> which is an integer specifying till which depth we want to concatenate sub array elementsthe output will be an array with all sub array elements concatenated into it recursively up to the specified depthconst array=[2,[3,[4]]]
let depth=1
const answer= findTheString(array,depth) //returns an array with 1 nested subarray concatenated
console.log(answer) //[2,3,[4]]
depth = 2
const answer2 = findTheString(array,depth) // returns an array with 2 nested array concatenated
console.log(answer2) // [2,3,4], I have written this Solution Code:
function findTheString(array,depth) {
let flatArray = array.flat(depth);
return flatArray;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer <b>N</b>, you need to typecast this integer to String. If the typecasting is done successfully then we will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".User task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>checkConvertion()</b>, which contains N as a parameter.You need to return the typecasted string value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".Sample Input:
5
Sample Output:
Nice Job
Sample Input:
6
Sample Output:
Nice Job, I have written this Solution Code: def checkConevrtion(a):
return str(a)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer <b>N</b>, you need to typecast this integer to String. If the typecasting is done successfully then we will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".User task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>checkConvertion()</b>, which contains N as a parameter.You need to return the typecasted string value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".Sample Input:
5
Sample Output:
Nice Job
Sample Input:
6
Sample Output:
Nice Job, I have written this Solution Code: static String checkConevrtion(int a)
{
return String.valueOf(a);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array a that contains N integers. All the integers in the array may not be distinct. The number of repetitions of each integer in the array is represented by ri. Your task is to print the integers in the decreasing order of their occurrence in the array.
Note
1. If ri > rj, then ai must be printed before aj.
2. If ri == rj, then among ai and aj whichever has a larger value, is printed first.
Here ri and rj is the number of repetitions of integers ai and aj in the array.The first line of the input contains an integer N.
The second line contains N space- separated integers representing the elements of array a.
<b>Constraints</b>
1<= N <= 1000
1<= ai <= 1000Print the space separated integers in the decreasing order of their occurrence in the array. The output must be printed in a single line.Sample input:
6
1 2 3 3 2 1
Sample Output
3 2 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));
int n = Integer.parseInt(br.readLine());
Map<Integer,Integer> map = new HashMap<>();
String []str = br.readLine().split(" ");
for(int i = 0; i < n; i++){
int e = Integer.parseInt(str[i]);
map.put(e, map.getOrDefault(e,0)+1);
}
List<Map.Entry<Integer,Integer>> list = new ArrayList<>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<Integer,Integer>>(){
public int compare(Map.Entry<Integer,Integer> o1, Map.Entry<Integer,Integer> o2){
if(o1.getValue() == o2.getValue()){
return o2.getKey() - o1.getKey();
}
return o2.getValue() - o1.getValue();
}
});
for(Map.Entry<Integer,Integer> entry: list){
System.out.print(entry.getKey() + " ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array a that contains N integers. All the integers in the array may not be distinct. The number of repetitions of each integer in the array is represented by ri. Your task is to print the integers in the decreasing order of their occurrence in the array.
Note
1. If ri > rj, then ai must be printed before aj.
2. If ri == rj, then among ai and aj whichever has a larger value, is printed first.
Here ri and rj is the number of repetitions of integers ai and aj in the array.The first line of the input contains an integer N.
The second line contains N space- separated integers representing the elements of array a.
<b>Constraints</b>
1<= N <= 1000
1<= ai <= 1000Print the space separated integers in the decreasing order of their occurrence in the array. The output must be printed in a single line.Sample input:
6
1 2 3 3 2 1
Sample Output
3 2 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
bool static comp(pair<int, int> p, pair<int, int> q) {
if (p.second == q.second) {
return p.first > q.first;
}
return p.second > q.second;
}
vector<int> group_Sol(int N, vector<int> Arr) {
unordered_map<int, int> m;
for (auto &it : Arr) {
m[it] += 1;
}
vector<pair<int, int>> v;
for (auto &it : m) {
v.push_back(it);
}
sort(v.begin(), v.end(), comp);
vector<int> res;
for (auto &it : v) {
res.push_back(it.first);
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<int> a(N);
for (int i_a = 0; i_a < N; i_a++) {
cin >> a[i_a];
}
vector<int> out_;
out_ = group_Sol(N, a);
cout << out_[0];
for (int i_out_ = 1; i_out_ < out_.size(); i_out_++) {
cout << " " << out_[i_out_];
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array a that contains N integers. All the integers in the array may not be distinct. The number of repetitions of each integer in the array is represented by ri. Your task is to print the integers in the decreasing order of their occurrence in the array.
Note
1. If ri > rj, then ai must be printed before aj.
2. If ri == rj, then among ai and aj whichever has a larger value, is printed first.
Here ri and rj is the number of repetitions of integers ai and aj in the array.The first line of the input contains an integer N.
The second line contains N space- separated integers representing the elements of array a.
<b>Constraints</b>
1<= N <= 1000
1<= ai <= 1000Print the space separated integers in the decreasing order of their occurrence in the array. The output must be printed in a single line.Sample input:
6
1 2 3 3 2 1
Sample Output
3 2 1, I have written this Solution Code: from collections import defaultdict
import numpy as np
n=int(input())
val=np.array([input().strip().split()],int).flatten()
d=defaultdict(int)
for i in val:
d[i]+=1
a=[]
for i in d:
a.append([d[i],i])
a.sort()
for i in range(len(a)-1,-1,-1):
print(a[i][1],end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a class with the name SumCalculator. The class needs two fields (public variables) with names num1 and num2 both of type int.
Write the following methods (instance methods):
<b>*Method named sum without any parameters, it needs to return the value of num1 + num2.</b>
<b>*Method named sum2 with two parameters a, b, it needs to return the value of a + b.</b>
<b>*Method named fromObject with two parameters of type sumCalculator object named obj1 and obj2, and you have to call sum function for respective object and return sum of both</b>
NOTE: All methods should be defined as public, NOT public static.
NOTE: In total, you have to write 3 methods.
NOTE: Do not add the main method to the solution code.You don't have to take any input, You only have to write class <b>SumCalculator</b>.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Input:
1
Sample Output:
Correct, I have written this Solution Code: class SumCalculator():
def __init__(self,a,b):
self.a=a
self.b=b
def sum(self):
return self.a+self.b
def sum2(self,a,b):
return a+b
def fromObject(self,ob1,ob2):
return ob1.sum+ob2.sum, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a class with the name SumCalculator. The class needs two fields (public variables) with names num1 and num2 both of type int.
Write the following methods (instance methods):
<b>*Method named sum without any parameters, it needs to return the value of num1 + num2.</b>
<b>*Method named sum2 with two parameters a, b, it needs to return the value of a + b.</b>
<b>*Method named fromObject with two parameters of type sumCalculator object named obj1 and obj2, and you have to call sum function for respective object and return sum of both</b>
NOTE: All methods should be defined as public, NOT public static.
NOTE: In total, you have to write 3 methods.
NOTE: Do not add the main method to the solution code.You don't have to take any input, You only have to write class <b>SumCalculator</b>.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Input:
1
Sample Output:
Correct, I have written this Solution Code: class SumCalculator{
public int num1,num2;
SumCalculator(int _num1,int _num2){
num1=_num1;
num2=_num2;
}
public int sum() {
return num1+num2;
}
public int sum2(int a,int b){
return a+b;
}
public int fromObject(SumCalculator obj1,SumCalculator obj2){
return obj1.sum() + obj2.sum();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int n;
cin>>n;
int a[n][n];
FOR(i,n){
FOR(j,n){
cin>>a[i][j];}}
int sum=0,sum1=0;;
FOR(i,n){
sum+=a[i][i];
sum1+=a[n-i-1][i];
}
out1(sum);out(sum1);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String args[])throws Exception {
InputStreamReader inr= new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(inr);
String str=br.readLine();
int row = Integer.parseInt(str);
int col=row;
int [][] arr=new int [row][col];
for(int i=0;i<row;i++){
String line =br.readLine();
String[] elements = line.split(" ");
for(int j=0;j<col;j++){
arr[i][j]= Integer.parseInt(elements[j]);
}
}
int sumPrimary=0;
int sumSecondary=0;
for(int i=0;i<row;i++){
sumPrimary=sumPrimary + arr[i][i];
sumSecondary= sumSecondary + arr[i][row-1-i];
}
System.out.println(sumPrimary+ " " +sumSecondary);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: // mat is the matrix/ 2d array
// the dimensions of array are n * n
function diagonalSum(mat, n) {
// write code here
// console.log the answer as in example
let principal = 0, secondary = 0;
for (let i = 0; i < n; i++) {
principal += mat[i][i];
secondary += mat[i][n - i - 1];
}
console.log(`${principal} ${secondary}`);
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: n = int(input())
sum1 = 0
sum2 = 0
for i in range(n):
a = [int(j) for j in input().split()]
sum1 = sum1+a[i]
sum2 = sum2+a[n-1-i]
print(sum1,sum2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Morgan was opening some boxes when she found one bearing a message “For Morgan, Dad loves you 3000". She wants to open the box but she needs to solve the question to open it. She asks Peter to do that. Help Peter and Morgan solve the question so that they can see what's inside the box.
Given two arrays Arr1 and Arr2 of size N1 and N2. Your task is to find the sum of all elements that are common to both arrays. If there are no common elements the output would be 0.
Note: The arrays may contain duplicate elements. However, you need to sum only unique elements that are common to both arrays.The first line of input contains N1 and N2 separated by a space. The second line contains N1 space separated elements of Arr1. The third line contains N2 space separated elements of Arr2.
Constraints:
1 <= N1, N2 <= 10<sup>6</sup>
1 <= Arr1[i], Arr2[i] <= 1000000000Print the sum of common elements.Sample Input:
5 6
1 2 3 4 5
2 3 4 5 6 7
Sample Output:
14
Explanation:- Common elements = 2, 3, 4 , 5
sum= 2 + 3 + 4 + 5 = 14
Sample Input:-
3 3
1 2 3
4 5 6
Sample Output:-
0, I have written this Solution Code: import java.io.*;
import java.util.*;
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();
int n1 = sc.nextInt();
int n2 = sc.nextInt();
HashSet<Integer> hs = new HashSet<>();
long sum = 0l;
for(int i=0;i<n1;i++){
int curr = sc.nextInt();
hs.add(curr);
}
for(int i=0;i<n2;i++){
int sl = sc.nextInt();
if(hs.contains(sl)){
sum+=sl;
hs.remove(sl);
}
}
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Morgan was opening some boxes when she found one bearing a message “For Morgan, Dad loves you 3000". She wants to open the box but she needs to solve the question to open it. She asks Peter to do that. Help Peter and Morgan solve the question so that they can see what's inside the box.
Given two arrays Arr1 and Arr2 of size N1 and N2. Your task is to find the sum of all elements that are common to both arrays. If there are no common elements the output would be 0.
Note: The arrays may contain duplicate elements. However, you need to sum only unique elements that are common to both arrays.The first line of input contains N1 and N2 separated by a space. The second line contains N1 space separated elements of Arr1. The third line contains N2 space separated elements of Arr2.
Constraints:
1 <= N1, N2 <= 10<sup>6</sup>
1 <= Arr1[i], Arr2[i] <= 1000000000Print the sum of common elements.Sample Input:
5 6
1 2 3 4 5
2 3 4 5 6 7
Sample Output:
14
Explanation:- Common elements = 2, 3, 4 , 5
sum= 2 + 3 + 4 + 5 = 14
Sample Input:-
3 3
1 2 3
4 5 6
Sample Output:-
0, I have written this Solution Code: N1,N2=(map(int,input().split()))
arr1=set(map(int,input().split()))
arr2=set(map(int,input().split()))
arr1=list(arr1)
arr2=list(arr2)
arr1.sort()
arr2.sort()
i=0
j=0
sum1=0
while i<len(arr1) and j<len(arr2):
if arr1[i]==arr2[j]:
sum1+=arr1[i]
i+=1
j+=1
elif arr1[i]>arr2[j]:
j+=1
else:
i+=1
print(sum1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Morgan was opening some boxes when she found one bearing a message “For Morgan, Dad loves you 3000". She wants to open the box but she needs to solve the question to open it. She asks Peter to do that. Help Peter and Morgan solve the question so that they can see what's inside the box.
Given two arrays Arr1 and Arr2 of size N1 and N2. Your task is to find the sum of all elements that are common to both arrays. If there are no common elements the output would be 0.
Note: The arrays may contain duplicate elements. However, you need to sum only unique elements that are common to both arrays.The first line of input contains N1 and N2 separated by a space. The second line contains N1 space separated elements of Arr1. The third line contains N2 space separated elements of Arr2.
Constraints:
1 <= N1, N2 <= 10<sup>6</sup>
1 <= Arr1[i], Arr2[i] <= 1000000000Print the sum of common elements.Sample Input:
5 6
1 2 3 4 5
2 3 4 5 6 7
Sample Output:
14
Explanation:- Common elements = 2, 3, 4 , 5
sum= 2 + 3 + 4 + 5 = 14
Sample Input:-
3 3
1 2 3
4 5 6
Sample Output:-
0, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
#define qw1 freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define qw2 freopen("input2.txt", "r", stdin); freopen("output2.txt", "w", stdout);
#define qw3 freopen("input3.txt", "r", stdin); freopen("output3.txt", "w", stdout);
#define qw4 freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout);
#define qw5 freopen("input5.txt", "r", stdin); freopen("output5.txt", "w", stdout);
#define qw6 freopen("input6.txt", "r", stdin); freopen("output6.txt", "w", stdout);
#define qw freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
signed main()
{
int n,m;
cin>>n>>m;
set<int> ss,yy;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
ss.insert(a);
}
for(int i=0;i<m;i++)
{
int a;
cin>>a;
if(ss.find(a)!=ss.end()) yy.insert(a);
}
int sum=0;
for(auto it:yy)
{
sum+=it;
}
cout<<sum<<endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a chunk of data in the form of string. Your task is to match a given pattern from the data and return the number of times the pattern is matched in the data.
<b>Function Description</b>
Complete the function <b>count_pattern()</b> in the editor below. The function takes 2 parameters in the form of String.
- <b>data</b>
- <b>pattern</b>
Return :
- int : It should return the count of pattern matches in the data
<b>Note :</b> If the input instance is empty string `""`, then it should return "Empty".The first string of the input is data and the second string is pattern.Return the count of pattern matches in the data.Sample Input
abccbea
abc
Sample Output
1
Explanation
One time pattern matches in the data. So it returns 1, I have written this Solution Code: def count_pattern(data, pattern):
check = True
count = 0
if(data == "" or pattern == ""):
count = "Empty"
else:
while(check):
check = False
if(data.__contains__(pattern)):
check = True
count += 1
data = data.replace(pattern, '', 1)
return count
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code:
int mythOrFact(int N){
int prime =1;
int cnt = N+1;
for(int i=2;i<N;i++){
if(N%i==0){cnt+=i;prime=0;}
}
int p = 3*N;
p/=2;
if((cnt<=p && prime==1) || (cnt>p && prime==0) ){return 1;}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code:
int mythOrFact(int N){
int prime =1;
int cnt = N+1;
for(int i=2;i<N;i++){
if(N%i==0){cnt+=i;prime=0;}
}
int p = 3*N;
p/=2;
if((cnt<=p && prime==1) || (cnt>p && prime==0) ){return 1;}
return 0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code: static int mythOrFact(int N){
int prime =1;
int cnt = N+1;
for(int i=2;i<N;i++){
if(N%i==0){cnt+=i;prime=0;}
}
int p = 3*N;
p/=2;
if((cnt<=p && prime==1) || (cnt>p && prime==0) ){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code: def mythOrFact(N):
prime=1
cnt=N+1
for i in range (2,N):
if N%i==0:
prime=0
cnt=cnt+i
x = 3*N
x=x//2
if(cnt <= x and prime==1) or (cnt>x and prime==0):
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a 2X2 square matrix. You need to find the determinant of the matrix.The input contains two-line, each line contain two integers separated by spaces.
Each element of the matrix is from 1 to 100.Output a single integer, the determinant of the matrix.Sample Input
4 5
2 3
Sample Output
2
Sample Input
2 10
10 40
Sample Output
-20, 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[][]arr=new int[2][2];
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
arr[i][j]=sc.nextInt();
}
}
int determinent=(arr[0][0]*arr[1][1])-(arr[1][0]*arr[0][1]);
System.out.print(determinent);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a 2X2 square matrix. You need to find the determinant of the matrix.The input contains two-line, each line contain two integers separated by spaces.
Each element of the matrix is from 1 to 100.Output a single integer, the determinant of the matrix.Sample Input
4 5
2 3
Sample Output
2
Sample Input
2 10
10 40
Sample Output
-20, I have written this Solution Code: arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
lis=[]
a11=arr1[0]
a12=arr1[1]
a21=arr2[0]
a22=arr2[1]
det=(a11*a22)-(a12*a21)
print(det), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a 2X2 square matrix. You need to find the determinant of the matrix.The input contains two-line, each line contain two integers separated by spaces.
Each element of the matrix is from 1 to 100.Output a single integer, the determinant of the matrix.Sample Input
4 5
2 3
Sample Output
2
Sample Input
2 10
10 40
Sample Output
-20, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<a*d-b*c;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a number n. Your task is to print the number of prime numbers before that number.The first line of the number of test cases T.
Next T lines contains the value of N.
<b>Constraints</b>
1 <= T <= 100
1 <= N <= 1000Print the number of primes numbers before that number.Sample Input 1:
3
10
19
4
Sample Output 1:
4
8
2, I have written this Solution Code: n = 1000
arr = [True for i in range(n+1)]
i = 2
while i*i <= n:
if arr[i] == True:
for j in range(i*2, n+1, i):
arr[j] = False
i +=1
arr2 = [0] * (n+1)
for i in range(2,n+1):
if arr[i]:
arr2[i] = arr2[i-1] + 1
else:
arr2[i] = arr2[i-1]
x = int(input())
for i in range(x):
y = int(input())
print(arr2[y]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a number n. Your task is to print the number of prime numbers before that number.The first line of the number of test cases T.
Next T lines contains the value of N.
<b>Constraints</b>
1 <= T <= 100
1 <= N <= 1000Print the number of primes numbers before that number.Sample Input 1:
3
10
19
4
Sample Output 1:
4
8
2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
vector<bool> sieve(int n) {
vector<bool> is_prime(n + 1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (is_prime[i]) {
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
return is_prime;
}
int main() {
vector<bool> prime = sieve(1e5 + 1);
vector<int> prefix(1e5 + 1, 0);
for (int i = 1; i <= 1e5; i++) {
if (prime[i]) {
prefix[i] = prefix[i - 1] + 1;
} else {
prefix[i] = prefix[i - 1];
}
}
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
cout << prefix[n] << "\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You think that integers divisible by K are nice. Given L and R (L<=R), find the number of nice integers from L to R (both inclusive).First Line of input contains three integers L R K
Constraints :
0 <= L <= R <= 1000000000000000000(10^18)
1 <= K <= 1000000000000000000(10^18)Output a single integer which is the number of nice integers from L to R (both inclusive).Sample input 1
1 10 2
Sample output 1
5
Sample intput 2
4 5 3
Sample output 2
0
Explanation:-
Required divisors = 2 4 6 8 10, 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().split(" ");
long l=Long.parseLong(str[0]);
long r=Long.parseLong(str[1]);
long k=Long.parseLong(str[2]);
long count=(r/k)-((l-1)/k);
System.out.print(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You think that integers divisible by K are nice. Given L and R (L<=R), find the number of nice integers from L to R (both inclusive).First Line of input contains three integers L R K
Constraints :
0 <= L <= R <= 1000000000000000000(10^18)
1 <= K <= 1000000000000000000(10^18)Output a single integer which is the number of nice integers from L to R (both inclusive).Sample input 1
1 10 2
Sample output 1
5
Sample intput 2
4 5 3
Sample output 2
0
Explanation:-
Required divisors = 2 4 6 8 10, I have written this Solution Code: l,r,k=[int(x)for x in input().split()]
print(r//k - (l-1)//k), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You think that integers divisible by K are nice. Given L and R (L<=R), find the number of nice integers from L to R (both inclusive).First Line of input contains three integers L R K
Constraints :
0 <= L <= R <= 1000000000000000000(10^18)
1 <= K <= 1000000000000000000(10^18)Output a single integer which is the number of nice integers from L to R (both inclusive).Sample input 1
1 10 2
Sample output 1
5
Sample intput 2
4 5 3
Sample output 2
0
Explanation:-
Required divisors = 2 4 6 8 10, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
unsigned long long x,l,r,k;
cin>>l>>r>>k;
x=l/k;
if(l%k==0){x--;}
cout<<r/k-x;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Since area of rectangle can be slightly easy, you need to calculate the area of the trapezium. You are given the lengths of the parallel sides of the trapezium and its height (distance between the parallel sides).The first and the only line of input contains three integers lengths of parallel sides followed by the height.
Constraints
1 <= side1, side2 <= 100
2 <= height <= 100
height is always divisible by 2Output a single integer, the area of the trapezium.
Sample Input
3 4 2
Sample Output
7
Explanation: The area of the given trapezium is 7., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args)
throws IOException
{
BufferedReader bi = new BufferedReader(
new InputStreamReader(System.in));
int num[] = new int[3];
String[] strNums;
strNums = bi.readLine().split(" ");
for (int i = 0; i < strNums.length; i++) {
num[i] = Integer.parseInt(strNums[i]);
}
int base_1 = num[0];
int base_2 = num[1];
int height = num[2];
int area = ((base_1 + base_2) * height) / 2;
System.out.println(area);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Since area of rectangle can be slightly easy, you need to calculate the area of the trapezium. You are given the lengths of the parallel sides of the trapezium and its height (distance between the parallel sides).The first and the only line of input contains three integers lengths of parallel sides followed by the height.
Constraints
1 <= side1, side2 <= 100
2 <= height <= 100
height is always divisible by 2Output a single integer, the area of the trapezium.
Sample Input
3 4 2
Sample Output
7
Explanation: The area of the given trapezium is 7., I have written this Solution Code: a,b,c = input("").split()
a,b,c = float(a),float(b),float(c)
area = ((a+b)/2)*c
print(int(area)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Since area of rectangle can be slightly easy, you need to calculate the area of the trapezium. You are given the lengths of the parallel sides of the trapezium and its height (distance between the parallel sides).The first and the only line of input contains three integers lengths of parallel sides followed by the height.
Constraints
1 <= side1, side2 <= 100
2 <= height <= 100
height is always divisible by 2Output a single integer, the area of the trapezium.
Sample Input
3 4 2
Sample Output
7
Explanation: The area of the given trapezium is 7., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
int x=(a+b)*c;
x=x/2;
cout<<x;}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the closest prime number to N. If there are multiple print the smaller one.The input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the closest prime to N.Sample Input 1
12
Sample Output 1
11
Explanation: Closest prime to 12 is 11 and 13 smaller of which is 11.
Sample Input 2
17
Sample Output 2
17
Explanation: Closest prime to 17 is 17., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
if(n==1){
System.out.println(2);
}else{
int after = afterPrime(n);
int before = beforePrime(n);
if(before>after){
System.out.println(n+after);
}
else{System.out.println(n-before);}
}
}
public static boolean isPrime(int n)
{
int count=0;
for(int i=2;i*i<n;i++)
{
if(n%i==0)
count++;
}
if(count==0)
return true;
else
return false;
}
public static int beforePrime(int n)
{
int c=0;
while(true)
{
if(isPrime(n))
return c;
else
{
n=n-1;
c++;
}
}
}
public static int afterPrime(int n)
{
int c=0;
while(true)
{
if(isPrime(n))
return c;
else
{
n=n+1;
c++;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the closest prime number to N. If there are multiple print the smaller one.The input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the closest prime to N.Sample Input 1
12
Sample Output 1
11
Explanation: Closest prime to 12 is 11 and 13 smaller of which is 11.
Sample Input 2
17
Sample Output 2
17
Explanation: Closest prime to 17 is 17., I have written this Solution Code: from math import sqrt
def NearPrime(N):
if N >1:
for i in range(2,int(sqrt(N))+1):
if N%i ==0:
return False
break
else: return True
else: return False
N=int(input())
i =0
while NearPrime(N-i)==False and NearPrime(N+i)==False:
i+=1
if NearPrime(N-i) and NearPrime(N+i):print(N-i)
elif NearPrime(N-i):print(N-i)
elif NearPrime(N+i): print(N+i), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the closest prime number to N. If there are multiple print the smaller one.The input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the closest prime to N.Sample Input 1
12
Sample Output 1
11
Explanation: Closest prime to 12 is 11 and 13 smaller of which is 11.
Sample Input 2
17
Sample Output 2
17
Explanation: Closest prime to 17 is 17., 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>
/////////////
bool isPrime(int n){
if(n<=1)
return false;
for(int i=2;i*i<=n;++i)
if(n%i==0)
return false;
return true;
}
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
if(n==1)
cout<<"2";
else{
int v1=n,v2=n;
while(isPrime(v1)==false)
--v1;
while(isPrime(v2)==false)
++v2;
if(v2-n==n-v1)
cout<<v1;
else{
if(v2-n<n-v1)
cout<<v2;
else
cout<<v1;
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: N people are standing in line numbered 1 to N from left to right. Each person wants to know the height of the person to left of him having height less than him. If there are multiple such people he wants to know the height of the person closest to him.
If there is no such person report -1.The first line of input contains N, the size of the array.
The second line of input contains N space-separated integers.
Constraints
2 ≤ N ≤ 100000
0 ≤ Arr[i] ≤ 1000000000 (Height can be zero wierd people :p )The output should contain N space separated integers, the ith integer should be the height reported to ith person (-1 if no person to the left is found whose height is less).Sample Input 1
5
1 2 3 4 5
Sample Output 1
-1 1 2 3 4
Sample Input 2
2
1 1
Sample Output 2
-1 -1, I have written this Solution Code: import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;
public class Main {
final static long MOD = 1000000007;
public static void main(String args[]) {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int n = fs.nextInt();
int[] a = fs.nextIntArray(n);
Stack<Integer> stck = new Stack<>();
for (int i = 0; i < n; i++) {
while (!stck.isEmpty() && stck.peek() >= a[i]) {
stck.pop();
}
if (stck.isEmpty()) {
out.print("-1 ");
stck.push(a[i]);
} else {
out.print(stck.peek() + " ");
stck.push(a[i]);
}
}
out.flush();
out.close();
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
} catch (Exception e) {
e.printStackTrace();
}
}
public String next() {
if (st.hasMoreTokens())
return st.nextToken();
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
String line = "";
try {
line = br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return line;
}
public char nextChar() {
return next().charAt(0);
}
public Integer[] nextIntegerArray(int n) {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[] nextCharArray() {
return nextLine().toCharArray();
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: N people are standing in line numbered 1 to N from left to right. Each person wants to know the height of the person to left of him having height less than him. If there are multiple such people he wants to know the height of the person closest to him.
If there is no such person report -1.The first line of input contains N, the size of the array.
The second line of input contains N space-separated integers.
Constraints
2 ≤ N ≤ 100000
0 ≤ Arr[i] ≤ 1000000000 (Height can be zero wierd people :p )The output should contain N space separated integers, the ith integer should be the height reported to ith person (-1 if no person to the left is found whose height is less).Sample Input 1
5
1 2 3 4 5
Sample Output 1
-1 1 2 3 4
Sample Input 2
2
1 1
Sample Output 2
-1 -1, I have written this Solution Code: import sys
n=int(input())
myList = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
outputList = []
outputList.append(-1);
for i in range(1,len(myList),1):
flag=False
for j in range(i-1,-1,-1):
if myList[j]<myList[i]:
outputList.append(myList[j])
flag=True
break
if flag==False:
outputList.append(-1)
print(*outputList), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: N people are standing in line numbered 1 to N from left to right. Each person wants to know the height of the person to left of him having height less than him. If there are multiple such people he wants to know the height of the person closest to him.
If there is no such person report -1.The first line of input contains N, the size of the array.
The second line of input contains N space-separated integers.
Constraints
2 ≤ N ≤ 100000
0 ≤ Arr[i] ≤ 1000000000 (Height can be zero wierd people :p )The output should contain N space separated integers, the ith integer should be the height reported to ith person (-1 if no person to the left is found whose height is less).Sample Input 1
5
1 2 3 4 5
Sample Output 1
-1 1 2 3 4
Sample Input 2
2
1 1
Sample Output 2
-1 -1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
stack <long long > s;
long long a;
for(int i=0;i<n;i++){
cin>>a;
while(!(s.empty())){
if(s.top()<a){break;}
s.pop();
}
if(s.empty()){cout<<-1<<" ";}
else{cout<<s.top()<<" ";}
s.push(a);
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string A of length N. You have to divide this string into any number of substrings A<sub>1</sub>, A<sub>2</sub>. A<sub>K</sub> such that the concatenation of these strings A<sub>1</sub>, A<sub>2</sub>. A<sub>K</sub> equals A and for every i (1 < i <= K), A<sub>i</sub> is not equal to A<sub>i-1</sub> is satisifed. Find the maximum such integer K which satisfies these conditions.The first line of the input contains a single integer N.
The second line of the input contains a string A of length N.
Constraints:
1 <= N <= 10<sup>5</sup>Print the maximum such integer K which satisfies the above conditions.Sample Input:
xxyyxx
Sample Output:
4
Explaination:
We can divide this string into: xx, y, yx, x
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
const int K = 10;
vector<vector<int>> dp(n + 1, vector<int>(K + 1, -1));
dp[0][0] = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j <= K; j++){
if(dp[i][j] == -1){
continue;
}
for(int k = 1; k <= K && i + k <= n; k++){
if(j != k || s.substr(i - j, j) != s.substr(i, k)){
dp[i + k][k] = max(dp[i + k][k], dp[i][j] + 1);
}
}
}
}
int ans = 0;
for(int j = 0; j <= K; j++){
ans = max(ans, dp[n][j]);
}
cout << ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara wants to be the best programmer in the world but today she is stuck on an easy problem. Help her to solve it.
<b>Problem description:- </b>
Choose an integer N and subtract the sum of digits of the number N from it i. e. if N is 245 then subtract 2+4+5 from it making it 245 - 11 = 234.
Keep on doing this operation until the number becomes 0 (for eg. 25 requires 3 operations to reduce to 0
25 - > 18 - > 9 - > 0).
Given a number N, your task is to print the number of operations required to make the number 0.The first line of input contains a single integer containing the number of test cases T. Next T lines contain a single integer N.
Constraints:-
1 <= T <= 10000
1 <= N <= 1000000For each test case print the number of operations required to make the number 0.Sample Input:-
4
25
8
17
842
Sample Output:-
3
1
2
72
Explanation:-
25 - > 18 - > 9 - > 0
8 - > 0
17 - > 9 - > 0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int[] dp = new int[1000002];
public static void main (String[] args) throws IOException {
int x = 1000000;
int sum = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int i = 1; i <= x; ++i) {
int j = i;
sum = total(j);
dp[i] = dp[i-sum]+1;
}
int t = Integer.parseInt(br.readLine());
while(t-- > 0) {
int count = 0;
int n = Integer.parseInt(br.readLine());
System.out.println(dp[n]);
}
}
static int total(int n) {
int temp = 0;
while(n > 0) {
temp += n%10;
n = n/10;
}
return temp;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara wants to be the best programmer in the world but today she is stuck on an easy problem. Help her to solve it.
<b>Problem description:- </b>
Choose an integer N and subtract the sum of digits of the number N from it i. e. if N is 245 then subtract 2+4+5 from it making it 245 - 11 = 234.
Keep on doing this operation until the number becomes 0 (for eg. 25 requires 3 operations to reduce to 0
25 - > 18 - > 9 - > 0).
Given a number N, your task is to print the number of operations required to make the number 0.The first line of input contains a single integer containing the number of test cases T. Next T lines contain a single integer N.
Constraints:-
1 <= T <= 10000
1 <= N <= 1000000For each test case print the number of operations required to make the number 0.Sample Input:-
4
25
8
17
842
Sample Output:-
3
1
2
72
Explanation:-
25 - > 18 - > 9 - > 0
8 - > 0
17 - > 9 - > 0, I have written this Solution Code: import sys
sys.setrecursionlimit(40000)
dic = {}
def sumi(n):
x = 0
while(n>0):
x += n%10
n //= 10
return x
def Num_of_times(n):
if (n==0):
return 0
if dic.get(n):
count = dic[n]
return count
else:
x = sumi(n)
count = 1+Num_of_times(n-x)
dic[n] = count
return count
arr = []
maxi = 0
for i in range(int(input())):
x = int(input())
maxi = max(maxi,x)
arr.append(x)
maxi_ans = Num_of_times(maxi)
for i in arr:
if i == maxi:
print(maxi_ans)
else:
print(Num_of_times(i)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara wants to be the best programmer in the world but today she is stuck on an easy problem. Help her to solve it.
<b>Problem description:- </b>
Choose an integer N and subtract the sum of digits of the number N from it i. e. if N is 245 then subtract 2+4+5 from it making it 245 - 11 = 234.
Keep on doing this operation until the number becomes 0 (for eg. 25 requires 3 operations to reduce to 0
25 - > 18 - > 9 - > 0).
Given a number N, your task is to print the number of operations required to make the number 0.The first line of input contains a single integer containing the number of test cases T. Next T lines contain a single integer N.
Constraints:-
1 <= T <= 10000
1 <= N <= 1000000For each test case print the number of operations required to make the number 0.Sample Input:-
4
25
8
17
842
Sample Output:-
3
1
2
72
Explanation:-
25 - > 18 - > 9 - > 0
8 - > 0
17 - > 9 - > 0, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define LL long long
int dp[1000001];
void solve() {
int n; cin >> n;
cout << dp[n] << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
for(int i = 1; i <= 1000000; i++) {
int s = 0, j = i;
while(j > 0) {
s += j % 10;
j /= 10;
}
dp[i] = dp[i - s] + 1;
}
int tt; cin >> tt;
while(tt--) solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a one-dimensional sorted array A containing N integers.
You are also given an integer target, find if there exists a pair of elements in the array whose difference is equal to the target.
Approach this problem in O(n).The first line contains a single integer N.
The second line contains N space- separated integer A[i].
The third line contains an integer target.
Constraints
1<=N<=10^5
0<=A[i]<=10^9
0<=target<=10^9Print Yes if pair with given difference exists in our array otherwise print No.Sample Input 1:
5
1 2 7 9 11
5
Sample Output 1:
Yes
Sample Input 2:
5
1 1 8 8 25
0
Sample Output 2:
Yes, 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);
try{
int n = sc.nextInt();
int arr[] = new int[n];
HashMap<Integer, Integer> map =new HashMap<>();
for(int i=0; i<n; i++){
arr[i]=sc.nextInt();
map.put(arr[i], 1);
}
int target = sc.nextInt();
boolean found = false;
for(int i =0; i<n; i++){
if(map.containsKey(arr[i]+target)){
found=true;
break;
}
}
if(found)
System.out.println("Yes");
else
System.out.println("No");
}
catch(Exception e){
System.out.println("No");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a one-dimensional sorted array A containing N integers.
You are also given an integer target, find if there exists a pair of elements in the array whose difference is equal to the target.
Approach this problem in O(n).The first line contains a single integer N.
The second line contains N space- separated integer A[i].
The third line contains an integer target.
Constraints
1<=N<=10^5
0<=A[i]<=10^9
0<=target<=10^9Print Yes if pair with given difference exists in our array otherwise print No.Sample Input 1:
5
1 2 7 9 11
5
Sample Output 1:
Yes
Sample Input 2:
5
1 1 8 8 25
0
Sample Output 2:
Yes, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
bool check(vector<int> A,int target,int n) {
int i=0,j=1,x=0;
while(i<=n && j<=n)
{
x=A[j]-A[i];
if(x==target && i!=j)return 1;
else if(x<target)j++;
else i++;
}
return 0;
}
int main() {
int n,target;
cin>>n;
vector<int>arr(n);
for(int i=0;i<n;i++)cin>>arr[i];
cin>>target;
cout<<(check(arr,target,n)==1 ? "Yes" : "No");
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x.
Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 10^5
1 ≤ arr[i] ≤ 10^18
0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput:
3
7 0
1 2 8 10 11 12 19
7 5
1 2 8 10 11 12 19
7 10
1 2 8 10 11 12 19
Output:
-1
1
3
Explanation:
Testcase 1: No element less than or equal to 0 is found. So output is "-1".
Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing).
Testcase 3: Number less than or equal to 10 is 10 and its index is 3., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static int BS(int arr[],int x,int start,int end){
if( start > end) return start-1;
int mid = start + (end - start)/2;
if(arr[mid]==x) return mid;
if(arr[mid]>x) return BS(arr,x,start,mid-1);
return BS(arr,x,mid+1,end);
}
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
String[] s;
for(;t>0;t--){
s = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int x = Integer.parseInt(s[1]);
s = br.readLine().split(" ");
int[] arr = new int[n];
for(int i=0;i<n;i++)
arr[i] = Integer.parseInt(s[i]);
int res = BS(arr,x,0,arr.length-1);
System.out.println(res);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x.
Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 10^5
1 ≤ arr[i] ≤ 10^18
0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput:
3
7 0
1 2 8 10 11 12 19
7 5
1 2 8 10 11 12 19
7 10
1 2 8 10 11 12 19
Output:
-1
1
3
Explanation:
Testcase 1: No element less than or equal to 0 is found. So output is "-1".
Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing).
Testcase 3: Number less than or equal to 10 is 10 and its index is 3., I have written this Solution Code: def bsearch(arr,e,l,r):
if(r>=l):
mid = l + (r - l)//2
if (arr[mid] == e):
return mid
elif arr[mid] > e:
return bsearch(arr, e,l, mid-1)
else:
return bsearch(arr,e, mid + 1, r)
else:
return r
t=int(input())
for i in range(t):
ip=list(map(int,input().split()))
l=list(map(int,input().split()))
le=ip[0]
e=ip[1]
print(bsearch(sorted(l),e,0,le-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x.
Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 10^5
1 ≤ arr[i] ≤ 10^18
0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput:
3
7 0
1 2 8 10 11 12 19
7 5
1 2 8 10 11 12 19
7 10
1 2 8 10 11 12 19
Output:
-1
1
3
Explanation:
Testcase 1: No element less than or equal to 0 is found. So output is "-1".
Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing).
Testcase 3: Number less than or equal to 10 is 10 and its index is 3., 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 t; cin >> t;
while(t--){
int n, x; cin >> n >> x;
for(int i = 0; i < n; i++)
cin >> a[i];
int l = -1, h = n;
while(l+1 < h){
int m = (l + h) >> 1;
if(a[m] <= x)
l = m;
else
h = m;
}
cout << l << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a function called lucky_sevens which takes an array of integers and returns true if any three consecutive elements sum to 7An array containing numbers.Print true if such triplet exists summing to 7 else print falseSample input:-
[2, 1, 5, 1, 0]
[1, 6]
Sample output:-
true
false
Explanation:-
1+5+1 = 7
no 3 consecutive numbers so false, I have written this Solution Code: function lucky_sevens(arr) {
// if less than 3 elements then this challenge is not possible
if (arr.length < 3) {
console.log(false)
return;
}
// because we know there are at least 3 elements we can
// start the loop at the 3rd element in the array (i=2)
// and check it along with the two previous elements (i-1) and (i-2)
for (let i = 2; i < arr.length; i++) {
if (arr[i] + arr[i-1] + arr[i-2] === 7) {
console.log(true)
return;
}
}
// if loop is finished and no elements summed to 7
console.log(false)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code:
char Race(int A, int B, int C){
if(abs(C-A)==abs(C-B)){return 'D';}
if(abs(C-A)>abs(C-B)){return 'S';}
else{
return 'N';}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code: def Race(A,B,C):
if abs(C-A) ==abs(C-B):
return 'D'
if abs(C-A)>abs(C-B):
return 'S'
return 'N'
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code:
char Race(int A, int B, int C){
if(abs(C-A)==abs(C-B)){return 'D';}
if(abs(C-A)>abs(C-B)){return 'S';}
else{
return 'N';}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code: static char Race(int A,int B,int C){
if(Math.abs(C-A)==Math.abs(C-B)){return 'D';}
if(Math.abs(C-A)>Math.abs(C-B)){return 'S';}
else{
return 'N';}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of numbers. Use appropriate array methods to find all numbers that are greater than 5. Complete the function <code>getNumbersGreaterThan5</code> that accepts an array of integers <code>nums</code> and returns an array of numbers that are greater than 5.An array <code>nums</code> of numbersAn array of the numbers greater than 5 that are present in <code>nums</code>const inputArr = [1,2,3,9,10,7,5,4,3]
const ans = getNumbersGreaterThan5(inputArr)
console.log(ans) // prints [9, 10, 7], I have written this Solution Code: function getNumbersGreaterThan5(nums) {
return nums.filter((num) => num > 5);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
for(int i=0;i<t;i++){
int n = Integer.parseInt(br.readLine());
System.out.println(Ways(n,1));
}
}
static int Ways(int x, int num)
{
int val =(x - num);
if (val == 0)
return 1;
if (val < 0)
return 0;
return Ways(val, num + 1) + Ways(x, num + 1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
long cnt=0;
int j;
void sum(int X,int j) {
if(X==0){cnt++;}
if(X<0)
{return;}
else {
for(int i=j;i<=(X);i++){
X=X-i;
sum(X,i+1);
X=X+i;
}
}
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(n<1){cout<<0<<endl;continue;}
sum(n,1);
cout<<cnt<<endl;
cnt=0;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: // ignore number of testcases
// n is the number as provided in input
function numberOfWays(n) {
// write code here
// do not console.log the answer
// return answer as a number
if(n < 1) return 0;
let cnt = 0;
let j;
function sum(X, j) {
if (X == 0) { cnt++; }
if (X < 0) { return; }
else {
for (let i = j; i <= X; i++) {
X = X - i;
sum(X, i + 1);
X = X + i;
}
}
}
sum(n,1);
return cnt
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: for _ in range(int(input())):
x = int(input())
n = 1
dp = [1] + [0] * x
for i in range(1, x + 1):
u = i ** n
for j in range(x, u - 1, -1):
dp[j] += dp[j - u]
if x==0:
print(0)
else:
print(dp[-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader(){
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1){
if (c == '\n')break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)c = read();
do{
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)return -ret;return ret;
}
public long nextLong() throws IOException{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.'){
while ((c = read()) >= '0' && c <= '9'){
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)buffer[0] = -1;
}
private byte read() throws IOException{
if (bufferPointer == bytesRead)fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException{
if (din == null)return;
din.close();
}
}
public static void main (String[] args) throws IOException{
Reader sc = new Reader();
int m = sc.nextInt();
int n = sc.nextInt();
int[][] arr = new int[m][n];
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
arr[i][j] = sc.nextInt();
}
}
int max_row_index = 0;
int j = n - 1;
for (int i = 0; i < m; i++) {
while (j >= 0 && arr[i][j] == 1) {
j = j - 1;
max_row_index = i;
}
}
System.out.println(max_row_index);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code: r, c = list(map(int, input().split()))
max_count = 0
max_r = 0
for i in range(r):
count = input().count("1")
if count > max_count:
max_count = count
max_r = i
print(max_r), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int a[max1][max1];
signed main()
{
int n,m;
cin>>n>>m;
FOR(i,n){
FOR(j,m){cin>>a[i][j];}}
int cnt=0;
int ans=0;
int res=0;
FOR(i,n){
cnt=0;
FOR(j,m){
if(a[i][j]==1){
cnt++;
}}
if(cnt>res){
res=cnt;
ans=i;
}
}
out(ans);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code: // mat is the matrix/ 2d array
// n,m are dimensions
function max1Row(mat, n, m) {
// write code here
// do not console.log
// return the answer as a number
let j, max_row_index = 0;
j = m - 1;
for (let i = 0; i < n; i++)
{
// Move left until a 0 is found
let flag = false;
// to check whether a row has more 1's than previous
while (j >= 0 && mat[i][j] == 1)
{
j = j - 1; // Update the index of leftmost 1
// seen so far
flag = true;//present row has more 1's than previous
}
// if the present row has more 1's than previous
if (flag)
{
max_row_index = i; // Update max_row_index
}
}
if (max_row_index == 0 && mat[0][m - 1] == 0)
return -1;
return max_row_index;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.The first line of the input contains n ( length of num )
The second line contains the array num.
<b>Constraints</b>
1 ≤ nums. length ≤ 100
-100 ≤ nums[i] ≤ 100Print the sorted arraySample Input
6
1 1 2 2 2 3
Sample Output
3 1 1 2 2 2
Explanation: '
3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String str = br.readLine();
String[] str1 = str.split(" ");
int[] arr = new int[n];
HashMap<Integer,Integer> map = new HashMap<>();
List<Integer> list = new ArrayList<>();
for(int i = 0; i < n; ++i) {
arr[i] = Integer.parseInt(str1[i]);
}
arr = frequencySort(arr);
for(int i : arr) {
System.out.print(i+" ");
}
}
static Map<Integer,Integer>map;
public static int[] frequencySort(int[] nums)
{
map=new HashMap<Integer,Integer>();
for(int i:nums){
if(map.containsKey(i)){
map.put(i,1+map.get(i));
}else{
map.put(i,1);
}
}
Integer[]arr=new Integer[nums.length];
int k=0;
for(int i:nums){
arr[k++]=i;
}
Arrays.sort(arr,new Comp());
k=0;
for(int i:arr){
nums[k++]=i;
}
return nums;
}
}
class Comp implements Comparator<Integer>{
Map<Integer,Integer>map=Main.map;
public int compare(Integer a,Integer b){
if(map.get(a)>map.get(b))return 1;
else if(map.get(b)>map.get(a))return -1;
else{
if(a>b)return -1;
else if(a<b)return 1;
return 0;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.The first line of the input contains n ( length of num )
The second line contains the array num.
<b>Constraints</b>
1 ≤ nums. length ≤ 100
-100 ≤ nums[i] ≤ 100Print the sorted arraySample Input
6
1 1 2 2 2 3
Sample Output
3 1 1 2 2 2
Explanation: '
3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3., I have written this Solution Code: import numpy as np
from collections import defaultdict
d=defaultdict(list)
d_f=defaultdict (int)
n=int(input())
a=np.array([input().strip().split()],int).flatten()
for i in a:
d_f[i]+=1
for i in d_f:
d[d_f[i]].append(i)
d=sorted(d.items())
for i in d:
i[1].sort(reverse=True)
for i in d:
for j in i[1]:
for _ in range(i[0]):
print(j,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.The first line of the input contains n ( length of num )
The second line contains the array num.
<b>Constraints</b>
1 ≤ nums. length ≤ 100
-100 ≤ nums[i] ≤ 100Print the sorted arraySample Input
6
1 1 2 2 2 3
Sample Output
3 1 1 2 2 2
Explanation: '
3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3., I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-10 12:51:16
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
bool static comparator(pair<int, int> m, pair<int, int> n) {
if (m.second == n.second)
return m.first > n.first; // m>n can also be written it will return the same
else
return m.second < n.second;
}
vector<int> frequencySort(vector<int>& nums) {
unordered_map<int, int> mp;
for (auto k : nums)
mp[k]++;
vector<pair<int, int>> v1;
for (auto k : mp)
v1.push_back(k);
sort(v1.begin(), v1.end(), comparator);
vector<int> v;
for (auto k : v1) {
while (k.second != 0) {
v.push_back(k.first);
k.second--;
}
}
return v;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> res = frequencySort(a);
for (auto& it : res) {
cout << it << " ";
}
cout << "\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You will be given an array of several arrays that each contain integers and your goal is to write a function that
will sum up all the numbers in all the arrays. For example, if the input is [[3, 2], [1], [4, 12]] then your
program should output 22 because 3 + 2 + 1 + 4 + 12 = 22An array containing arrays which can contain any number of elements.Sum of all the elements in all of the arrays.Sample input:-
[[3, 2], [1], [4, 12]]
Sample output:-
22
Explanation:-
3 + 2 + 1 + 4 + 12 = 22, I have written this Solution Code: function sum_array(arr) {
// store our final answer
var sum = 0;
// loop through entire array
for (var i = 0; i < arr.length; i++) {
// loop through each inner array
for (var j = 0; j < arr[i].length; j++) {
// add this number to the current final sum
sum += arr[i][j];
}
}
console.log(sum);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader(){
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1){
if (c == '\n')break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)c = read();
do{
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)return -ret;return ret;
}
public long nextLong() throws IOException{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.'){
while ((c = read()) >= '0' && c <= '9'){
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)buffer[0] = -1;
}
private byte read() throws IOException{
if (bufferPointer == bytesRead)fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException{
if (din == null)return;
din.close();
}
}
public static void main (String[] args) throws IOException{
Reader sc = new Reader();
int m = sc.nextInt();
int n = sc.nextInt();
int[][] arr = new int[m][n];
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
arr[i][j] = sc.nextInt();
}
}
int max_row_index = 0;
int j = n - 1;
for (int i = 0; i < m; i++) {
while (j >= 0 && arr[i][j] == 1) {
j = j - 1;
max_row_index = i;
}
}
System.out.println(max_row_index);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code: r, c = list(map(int, input().split()))
max_count = 0
max_r = 0
for i in range(r):
count = input().count("1")
if count > max_count:
max_count = count
max_r = i
print(max_r), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int a[max1][max1];
signed main()
{
int n,m;
cin>>n>>m;
FOR(i,n){
FOR(j,m){cin>>a[i][j];}}
int cnt=0;
int ans=0;
int res=0;
FOR(i,n){
cnt=0;
FOR(j,m){
if(a[i][j]==1){
cnt++;
}}
if(cnt>res){
res=cnt;
ans=i;
}
}
out(ans);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code: // mat is the matrix/ 2d array
// n,m are dimensions
function max1Row(mat, n, m) {
// write code here
// do not console.log
// return the answer as a number
let j, max_row_index = 0;
j = m - 1;
for (let i = 0; i < n; i++)
{
// Move left until a 0 is found
let flag = false;
// to check whether a row has more 1's than previous
while (j >= 0 && mat[i][j] == 1)
{
j = j - 1; // Update the index of leftmost 1
// seen so far
flag = true;//present row has more 1's than previous
}
// if the present row has more 1's than previous
if (flag)
{
max_row_index = i; // Update max_row_index
}
}
if (max_row_index == 0 && mat[0][m - 1] == 0)
return -1;
return max_row_index;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code:
#include <iostream>
using namespace std;
int Dishes(int N, int T){
return T-N;
}
int main(){
int n,k;
scanf("%d%d",&n,&k);
printf("%d",Dishes(n,k));
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the closest prime number to N. If there are multiple print the smaller one.The input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the closest prime to N.Sample Input 1
12
Sample Output 1
11
Explanation: Closest prime to 12 is 11 and 13 smaller of which is 11.
Sample Input 2
17
Sample Output 2
17
Explanation: Closest prime to 17 is 17., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
if(n==1){
System.out.println(2);
}else{
int after = afterPrime(n);
int before = beforePrime(n);
if(before>after){
System.out.println(n+after);
}
else{System.out.println(n-before);}
}
}
public static boolean isPrime(int n)
{
int count=0;
for(int i=2;i*i<n;i++)
{
if(n%i==0)
count++;
}
if(count==0)
return true;
else
return false;
}
public static int beforePrime(int n)
{
int c=0;
while(true)
{
if(isPrime(n))
return c;
else
{
n=n-1;
c++;
}
}
}
public static int afterPrime(int n)
{
int c=0;
while(true)
{
if(isPrime(n))
return c;
else
{
n=n+1;
c++;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the closest prime number to N. If there are multiple print the smaller one.The input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the closest prime to N.Sample Input 1
12
Sample Output 1
11
Explanation: Closest prime to 12 is 11 and 13 smaller of which is 11.
Sample Input 2
17
Sample Output 2
17
Explanation: Closest prime to 17 is 17., I have written this Solution Code: from math import sqrt
def NearPrime(N):
if N >1:
for i in range(2,int(sqrt(N))+1):
if N%i ==0:
return False
break
else: return True
else: return False
N=int(input())
i =0
while NearPrime(N-i)==False and NearPrime(N+i)==False:
i+=1
if NearPrime(N-i) and NearPrime(N+i):print(N-i)
elif NearPrime(N-i):print(N-i)
elif NearPrime(N+i): print(N+i), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the closest prime number to N. If there are multiple print the smaller one.The input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the closest prime to N.Sample Input 1
12
Sample Output 1
11
Explanation: Closest prime to 12 is 11 and 13 smaller of which is 11.
Sample Input 2
17
Sample Output 2
17
Explanation: Closest prime to 17 is 17., 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>
/////////////
bool isPrime(int n){
if(n<=1)
return false;
for(int i=2;i*i<=n;++i)
if(n%i==0)
return false;
return true;
}
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
if(n==1)
cout<<"2";
else{
int v1=n,v2=n;
while(isPrime(v1)==false)
--v1;
while(isPrime(v2)==false)
++v2;
if(v2-n==n-v1)
cout<<v1;
else{
if(v2-n<n-v1)
cout<<v2;
else
cout<<v1;
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, “act” and “tac” are an anagram of each other.Input consists of two strings in lowercase english characters.
Constraints:
1 ≤ |s1|, |s2| ≤ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input
naman
manan
Sample Output
YES
Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s1 = br.readLine();
String s2 = br.readLine();
boolean flag = true;
int[] arr1 = new int[26];
int[] arr2 = new int[26];
for(int i=0; i<s1.length(); i++){
arr1[s1.charAt(i)-97]++;
}
for(int i=0; i<s2.length(); i++){
arr2[s2.charAt(i)-97]++;
}
for(int i=0; i<25; i++){
if(arr1[i]!=arr2[i]){
flag = false;
break;
}
}
if(flag==true)
System.out.print("YES");
else System.out.print("NO");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, “act” and “tac” are an anagram of each other.Input consists of two strings in lowercase english characters.
Constraints:
1 ≤ |s1|, |s2| ≤ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input
naman
manan
Sample Output
YES
Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., I have written this Solution Code: s1 = input().strip()
s2 = input().strip()
dict1 = dict()
dict2 = dict()
for i in s1:
dict1[i] = dict1.get(i, 0) + 1
for j in s2:
dict2[j] = dict2.get(j, 0) + 1
print(("NO", "YES")[dict1 == dict2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, “act” and “tac” are an anagram of each other.Input consists of two strings in lowercase english characters.
Constraints:
1 ≤ |s1|, |s2| ≤ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input
naman
manan
Sample Output
YES
Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
int A[26],B[26];
signed main()
{
string s,p;
cin>>s>>p;
for(int i=0;i<s.size();i++)
{
int y=s[i]-'a';
A[y]++;
}
for(int i=0;i<p.size();i++)
{
int y=p[i]-'a';
B[y]++;
}int ch=1;
for(int i=0;i<26;i++)
{
if(B[i]!=A[i])ch=0;
}
if(ch==1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, “act” and “tac” are an anagram of each other.Input consists of two strings in lowercase english characters.
Constraints:
1 ≤ |s1|, |s2| ≤ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input
naman
manan
Sample Output
YES
Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., I have written this Solution Code: // str1 and str2 are the two input strings
function isAnagram(str1,str2){
// Get lengths of both strings
let n1 = str1.length;
let n2 = str2.length;
// If length of both strings is not same,
// then they cannot be anagram
if (n1 != n2)
return "NO";
str1 = str1.split('')
str2 = str2.split('')
// Sort both strings
str1.sort();
str2.sort()
// Compare sorted strings
for (let i = 0; i < n1; i++)
if (str1[i] != str2[i])
return "NO";
return "YES";
}
, 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 value of the below Equation for the given number.
Equation: -
N
∑ {(X - 1)<sup>3</sup> + 3(X + 1)<sup>2</sup> + 2}
X = 1<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>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 100Return the sum of equation.Sample Input:-
1
Sample Output:-
14
Sample Input:-
2
Sample Output:-
44, I have written this Solution Code: static int equationSum(int n)
{
int sum=n*(n+1);
sum=sum/2;
sum=sum*sum;
sum+=9*((n*(n+1))/2);
sum+=4*(n);
return sum;
}, 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 value of the below Equation for the given number.
Equation: -
N
∑ {(X - 1)<sup>3</sup> + 3(X + 1)<sup>2</sup> + 2}
X = 1<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>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 100Return the sum of equation.Sample Input:-
1
Sample Output:-
14
Sample Input:-
2
Sample Output:-
44, I have written this Solution Code: def equationSum(N) :
re=(N*(N+1))//2
re=re*re
re=re+9*((N*(N+1))//2)
re=re+4*N
return re
, 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 value of the below Equation for the given number.
Equation: -
N
∑ {(X - 1)<sup>3</sup> + 3(X + 1)<sup>2</sup> + 2}
X = 1<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>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 100Return the sum of equation.Sample Input:-
1
Sample Output:-
14
Sample Input:-
2
Sample Output:-
44, I have written this Solution Code: int equationSum(int n){
int sum=n*(n+1);
sum=sum/2;
sum=sum*sum;
sum+=9*((n*(n+1))/2);
sum+=4*(n);
return sum;
}
, 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 value of the below Equation for the given number.
Equation: -
N
∑ {(X - 1)<sup>3</sup> + 3(X + 1)<sup>2</sup> + 2}
X = 1<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>equationSum()</b>, where you will get N as a parameter.
<b>Constraints:</b>
1 <= N <= 100Return the sum of equation.Sample Input:-
1
Sample Output:-
14
Sample Input:-
2
Sample Output:-
44, I have written this Solution Code: int equationSum(int n){
int sum=n*(n+1);
sum=sum/2;
sum=sum*sum;
sum+=9*((n*(n+1))/2);
sum+=4*(n);
return sum;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:-
1. Think of a number X(don't tell Sara)
2. Add A(Given by Sara) to it.
3. Double the sum in your mind.
4. Add an even number B(Given by Sara) to it.
5. Half the amount
6. Subtract the initial number which you had taken from the sum
After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her?
<b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b>
<b>Constraints</b>:-
1 <= A, B <= 1000Print the resulting amountSample Input:-
3 4
Sample Output:-
5
Sample Input:-
8 4
Sample Output:-
10, I have written this Solution Code: void magicTrick(int a, int b){
cout<<a+b/2;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:-
1. Think of a number X(don't tell Sara)
2. Add A(Given by Sara) to it.
3. Double the sum in your mind.
4. Add an even number B(Given by Sara) to it.
5. Half the amount
6. Subtract the initial number which you had taken from the sum
After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her?
<b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b>
<b>Constraints</b>:-
1 <= A, B <= 1000Print the resulting amountSample Input:-
3 4
Sample Output:-
5
Sample Input:-
8 4
Sample Output:-
10, I have written this Solution Code: static void magicTrick(int a, int b){
System.out.println(a + b/2);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:-
1. Think of a number X(don't tell Sara)
2. Add A(Given by Sara) to it.
3. Double the sum in your mind.
4. Add an even number B(Given by Sara) to it.
5. Half the amount
6. Subtract the initial number which you had taken from the sum
After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her?
<b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b>
<b>Constraints</b>:-
1 <= A, B <= 1000Print the resulting amountSample Input:-
3 4
Sample Output:-
5
Sample Input:-
8 4
Sample Output:-
10, I have written this Solution Code: A,B = map(int,input().split(' '))
C = A+B//2
print(C)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.