Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int t; cin >> t;
while(t--){
vector<int> v;
int n, x; cin >> n >> x;
for(int i = 1; i <= n; i++){
int p; cin >> p;
if(p == x)
v.push_back(i-1);
}
if(v.size() == 0)
cout << "Not found\n";
else{
for(auto i: v)
cout << 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 integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, I have written this Solution Code: def position(n,arr,x):
res = []
cnt = 0
for i in arr:
if(i == x):
res.append(cnt)
cnt += 1
return res
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main (String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t =Integer.parseInt(read.readLine());
while(t-- > 0)
{
String str[] = read.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
int x = Integer.parseInt(str[1]);
int arr[] = new int[n];
str = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
findPositions(arr, n, x);
}
}
static void findPositions(int arr[], int n, int x)
{
boolean flag = false;
StringBuffer sb = new StringBuffer();
for(int i = 0; i < n; i++)
{
if(arr[i] == x)
{
sb.append(i + " ");
flag = true;
}
}
if(flag ==true)
System.out.println(sb.toString());
else System.out.println("Not found");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B and C. Your task is to calculate the number of integers which are factors of atleast two given numbers.<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>CommonFactors()</b> that takes the integers A, B and C as parameters.
<b>Constraints:</b>
1 <= A, B, C <= 100000Return the count of common factors.Sample Input:-
3 6 12
Sample Output:-
4
Explanation:- 1, 2, 3, 6 are the required factors
Sample Input:-
1 2 3
Sample Output:-
1, I have written this Solution Code:
int commonFactors(int A,int B,int C){
int cnt=0;
for(int i=1;i<=A;i++){
if(A%i==0){
if(B%i==0 || C%i==0){cnt++;}
}
}
for(int i=1;i<=B;i++){
if(B%i==0){
if(A%i!=0 && C%i==0){cnt++;}
}
}
return cnt;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B and C. Your task is to calculate the number of integers which are factors of atleast two given numbers.<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>CommonFactors()</b> that takes the integers A, B and C as parameters.
<b>Constraints:</b>
1 <= A, B, C <= 100000Return the count of common factors.Sample Input:-
3 6 12
Sample Output:-
4
Explanation:- 1, 2, 3, 6 are the required factors
Sample Input:-
1 2 3
Sample Output:-
1, I have written this Solution Code:
static int commonFactors(int A,int B,int C){
int cnt=0;
for(int i=1;i<=A;i++){
if(A%i==0){
if(B%i==0 || C%i==0){cnt++;}
}
}
for(int i=1;i<=B;i++){
if(B%i==0){
if(A%i!=0 && C%i==0){cnt++;}
}
}
return cnt;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B and C. Your task is to calculate the number of integers which are factors of atleast two given numbers.<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>CommonFactors()</b> that takes the integers A, B and C as parameters.
<b>Constraints:</b>
1 <= A, B, C <= 100000Return the count of common factors.Sample Input:-
3 6 12
Sample Output:-
4
Explanation:- 1, 2, 3, 6 are the required factors
Sample Input:-
1 2 3
Sample Output:-
1, I have written this Solution Code:
int commonFactors(int A,int B,int C){
int cnt=0;
for(int i=1;i<=A;i++){
if(A%i==0){
if(B%i==0 || C%i==0){cnt++;}
}
}
for(int i=1;i<=B;i++){
if(B%i==0){
if(A%i!=0 && C%i==0){cnt++;}
}
}
return cnt;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B and C. Your task is to calculate the number of integers which are factors of atleast two given numbers.<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>CommonFactors()</b> that takes the integers A, B and C as parameters.
<b>Constraints:</b>
1 <= A, B, C <= 100000Return the count of common factors.Sample Input:-
3 6 12
Sample Output:-
4
Explanation:- 1, 2, 3, 6 are the required factors
Sample Input:-
1 2 3
Sample Output:-
1, I have written this Solution Code: def CommonFactors(A,B,C):
cnt=0
for i in range (1,A+1):
if(A%i==0):
if(B%i==0) or (C%i==0):
cnt=cnt+1
for i in range (1,B+1):
if(B%i==0):
if(A%i!=0) and (C%i==0):
cnt = cnt +1
return cnt
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
def checkSpecial_M_Visor(N,M) :
# Final result of summation of divisors
i=2;
count=0
while i<=N :
if(N%i==0):
count=count+1
i=i+2
if(count == M):
return "Yes"
return "No"
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
static String checkSpecial_M_Visor(int N, int M)
{
int temp=0;
for(int i = 2; i <=N; i+=2)
{
if(N%i==0)
temp++;
}
if(temp==M)
return "Yes";
else return "No";
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
string checkSpecial_M_Visor(int N,int M){
int count=0;
for(int i=2;i<=N;i+=2){
if(N%i==0){
count++;
}
}
if(count==M){return "Yes";}
return "No";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code: const char* checkSpecial_M_Visor(int N,int M){
int count=0;
for(int i=2;i<=N;i+=2){
if(N%i==0){
count++;
}
}
char* ans;
if(count==M){return "Yes";}
return "No";
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code: def OccurenceOfX(N,X):
cnt=0
for i in range(1, N+1):
if(X%i==0 and X/i<=N):
cnt=cnt+1
return cnt, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code:
int OccurenceOfX(int N,long X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code:
int OccurenceOfX(int N,long X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}
int main()
{
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code: public static int OccurenceOfX(int N,int X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: Sara is trying a new type of game in which she can jump in either the left direction or in the right direction. Also after each jump the range of her jump increases by 1 unit. i.e if starts from 1 in the next jump she has to jump 2 units then 3 units and so on.
Given the number of jumps as N, the range of the first jump to be 1. What will be the minimum distance Sara can be at from the starting point.<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>minDistanceCoveredBySara()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 1000Return the minimum distance Sara can be at from the starting point.Sample Input:-
3
Sample Output:-
0
Explanation:-
First jump:- right
Second jump:- right
Third jump:- left
Total distance covered = 1+2-3 = 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: int minDistanceCoveredBySara(int N){
if(N%4==1 || N%4==2){return 1;}
return 0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new type of game in which she can jump in either the left direction or in the right direction. Also after each jump the range of her jump increases by 1 unit. i.e if starts from 1 in the next jump she has to jump 2 units then 3 units and so on.
Given the number of jumps as N, the range of the first jump to be 1. What will be the minimum distance Sara can be at from the starting point.<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>minDistanceCoveredBySara()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 1000Return the minimum distance Sara can be at from the starting point.Sample Input:-
3
Sample Output:-
0
Explanation:-
First jump:- right
Second jump:- right
Third jump:- left
Total distance covered = 1+2-3 = 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: int minDistanceCoveredBySara(int N){
if(N%4==1 || N%4==2){return 1;}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new type of game in which she can jump in either the left direction or in the right direction. Also after each jump the range of her jump increases by 1 unit. i.e if starts from 1 in the next jump she has to jump 2 units then 3 units and so on.
Given the number of jumps as N, the range of the first jump to be 1. What will be the minimum distance Sara can be at from the starting point.<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>minDistanceCoveredBySara()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 1000Return the minimum distance Sara can be at from the starting point.Sample Input:-
3
Sample Output:-
0
Explanation:-
First jump:- right
Second jump:- right
Third jump:- left
Total distance covered = 1+2-3 = 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: def minDistanceCoveredBySara(N):
if N%4==1 or N%4==2:
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new type of game in which she can jump in either the left direction or in the right direction. Also after each jump the range of her jump increases by 1 unit. i.e if starts from 1 in the next jump she has to jump 2 units then 3 units and so on.
Given the number of jumps as N, the range of the first jump to be 1. What will be the minimum distance Sara can be at from the starting point.<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>minDistanceCoveredBySara()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 1000Return the minimum distance Sara can be at from the starting point.Sample Input:-
3
Sample Output:-
0
Explanation:-
First jump:- right
Second jump:- right
Third jump:- left
Total distance covered = 1+2-3 = 0
Sample Input:-
5
Sample Output:-
1, I have written this Solution Code: static int minDistanceCoveredBySara(int N){
if(N%4==1 || N%4==2){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a stack of integers and N queries. Your task is to perform these operations:-
<b>push:-</b>this operation will add an element to your current stack.
<b>pop:-</b>remove the element that is on top
<b>top:-</b>print the element which is currently on top of stack
<b>Note:-</b>if the stack is already empty then the pop operation will do nothing and 0 will be printed as a top element of the stack if it is empty.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>push()</b>:- that takes the stack and the integer to be added as a parameter.
<b>pop()</b>:- that takes the stack as parameter.
<b>top()</b> :- that takes the stack as parameter.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>3</sup>You don't need to print anything else other than in <b>top</b> function in which you require to print the topmost element of your stack in a new line, if the stack is empty you just need to print 0.Input:
7
push 1
push 2
top
pop
top
pop
top
Output:
2
1
0
, I have written this Solution Code:
public static void push (Stack < Integer > st, int x)
{
st.push (x);
}
// Function to pop element from stack
public static void pop (Stack < Integer > st)
{
if (st.isEmpty () == false)
{
int x = st.pop ();
}
}
// Function to return top of stack
public static void top(Stack < Integer > st)
{
int x = 0;
if (st.isEmpty () == false)
{
x = st.peek ();
}
System.out.println (x);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string s, find the first non-repeating character in the string and return its index. If it does not exist, return -1.First line of the input contains the string s.
<b>Constraints</b>
1<= s. length <= 100000Print the index of the first non- repeating character in a stringInput
s = "newtonschool"
Output
1
Explanation
"e" is the first non- repeating character in a string, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
System.out.print(nonRepeatChar(s));
}
static int nonRepeatChar(String s){
char count[] = new char[256];
for(int i=0; i< s.length(); i++){
count[s.charAt(i)]++;
}
for (int i=0; i<s.length(); i++) {
if (count[s.charAt(i)]==1){
return i;
}
}
return -1;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string s, find the first non-repeating character in the string and return its index. If it does not exist, return -1.First line of the input contains the string s.
<b>Constraints</b>
1<= s. length <= 100000Print the index of the first non- repeating character in a stringInput
s = "newtonschool"
Output
1
Explanation
"e" is the first non- repeating character in a string, I have written this Solution Code: from collections import defaultdict
s=input()
d=defaultdict(int)
for i in s:
d[i]+=1
ans=-1
for i in range(len(s)):
if(d[s[i]]==1):
ans=i
break
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string s, find the first non-repeating character in the string and return its index. If it does not exist, return -1.First line of the input contains the string s.
<b>Constraints</b>
1<= s. length <= 100000Print the index of the first non- repeating character in a stringInput
s = "newtonschool"
Output
1
Explanation
"e" is the first non- repeating character in a string, 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
int firstUniqChar(string s) {
map<char, int> charCount;
int len = s.length();
for (int i = 0; i < len; i++) {
charCount[s[i]]++;
}
for (int i = 0; i < len; i++) {
if (charCount[s[i]] == 1)
return i;
}
return -1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string str;
cin>>str;
cout<<firstUniqChar(str)<<"\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 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));
int N = Integer.parseInt(br.readLine());
double arr[] = new double[N];
String str[] = br.readLine().trim().split(" ");
for(int i=0;i<N;i++)
arr[i]=Integer.parseInt(str[i]);
double resistance=0;
int equResistance=0;
for(int i=0;i<N;i++)
arr[i]=Integer.parseInt(str[i]);
for(int i=0;i<N;i++)
{
resistance=resistance+(1/arr[i]);
}
equResistance = (int)Math.floor((1/resistance));
System.out.println(equResistance);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: r = input("")
r = int(r)
n = input("").split()
resistance=0.0
for i in range(0,r):
resistor = float(n[i])
resistance = resistance + (1/resistor)
print(int(1/resistance)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n; cin >> n;
double s = 0;
for(int i = 1; i <= n; i++){
double p; cin >> p;
s = s + (1/p);
}
s = 1/s;
cout << floor(s);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, You have to find if the binary representation of N can be rearranged to form a palindrome.Input contains a single integer N.
Constraints:-
1 <<= N <= 1000000000Print "YES" if the binary representation of N can be rearranged to form a palindrome, else print "NO".Sample Input:-
6
Sample Output:-
YES
Explanation:-
The binary representation of 6 = 110 which can be rearranged as 101
Sample Input:-
14
Sample Output:-
NO, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static boolean oddeven(int cntzero,int cntone){
if(cntzero%2==0 && cntone%2!=0 || cntzero%2!=0 && cntone%2==0)
{
return true;
}
if(cntzero%2==0 && cntone==cntzero){
return true;
}
return false;
}
public static boolean Binary(int n){
int cntzero=0;
int cntone=0;
while(n!=0){
if(n%2==1){
cntone++;
}
else{
cntzero++;
}
n=n/2;
}
return oddeven(cntzero,cntone);
}
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(Binary(n)==true){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, You have to find if the binary representation of N can be rearranged to form a palindrome.Input contains a single integer N.
Constraints:-
1 <<= N <= 1000000000Print "YES" if the binary representation of N can be rearranged to form a palindrome, else print "NO".Sample Input:-
6
Sample Output:-
YES
Explanation:-
The binary representation of 6 = 110 which can be rearranged as 101
Sample Input:-
14
Sample Output:-
NO, I have written this Solution Code: n=int(input())
s=bin(n)
r=s.replace('0b','')
ans=''.join(sorted(r))
if len(r)%2!=0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, You have to find if the binary representation of N can be rearranged to form a palindrome.Input contains a single integer N.
Constraints:-
1 <<= N <= 1000000000Print "YES" if the binary representation of N can be rearranged to form a palindrome, else print "NO".Sample Input:-
6
Sample Output:-
YES
Explanation:-
The binary representation of 6 = 110 which can be rearranged as 101
Sample Input:-
14
Sample Output:-
NO, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n,x=2;
cin>>n;
int cnt1=0,cnt2=0;
while(n>0){
if(n&1){
cnt1++;
}
else{
cnt2++;
}
n/=2;
}
if(cnt1%2==0 || cnt2%2==0){
cout<<"YES";
}
else{
cout<<"NO";}
//cout<<cnt1<<" "<<cnt2;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted doubly linked list containing n nodes. Your task is to remove duplicate nodes from the given list.
Example 1:
Input
1<->2<->2-<->3<->3<->4
Output:
1<->2<->3<->4
Example 2:
Input
1<->1<->1<->1
Output
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>deleteDuplicates()</b> that takes head node as parameter.
Constraints:
1 <=N <= 10000
1 <= Node. data<= 2*10000Return the head of the modified list.Sample Input:-
6
1 2 2 3 3 4
Sample Output:-
1 2 3 4
Sample Input:-
4
1 1 1 1
Sample Output:-
1, I have written this Solution Code: public static Node deleteDuplicates(Node head)
{
/* if list is empty */
if (head== null)
return head;
Node current = head;
while (current.next != null)
{
/* Compare current node with next node */
if (current.val == current.next.val)
/* delete the node pointed to by
' current->next' */
deleteNode(head, current.next);
/* else simply move to the next node */
else
current = current.next;
}
return head;
}
/* Function to delete a node in a Doubly Linked List.
head_ref --> pointer to head node pointer.
del --> pointer to node to be deleted. */
public static void deleteNode(Node head, Node del)
{
/* base case */
if(head==null || del==null)
{
return ;
}
/* If node to be deleted is head node */
if(head==del)
{
head=del.next;
}
/* Change next only if node to be deleted
is NOT the last node */
if(del.next!=null)
{
del.next.prev=del.prev;
}
/* Change prev only if node to be deleted
is NOT the first node */
if (del.prev != null)
del.prev.next = del.next;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M.
Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K.
Next line contains N integers denoting the elements of arr[]
<b>Constraints:</b>
1 <= N <= 100000
1 <= arr[i] <= 100000
1 <= K <= 100000000Print a single integer the value of smallest number MSample Input:
4 6
2 3 4 9
Sample Output:
4
Explanation:
When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6
When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K.
Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int k = Integer.parseInt(s[1]);
String str[] = br.readLine().split(" ");
int[] arr = new int[n];
for(int i=0;i<n;i++){
arr[i] = Integer.parseInt(str[i]);
}
System.out.print(minDivisor(arr,n,k));
}
static int minDivisor(int arr[],int N, int limit) {
int low = 0, high = 1000000000;
while (low < high)
{
int mid = (low + high) / 2;
int sum = 0;
for(int i = 0; i < N; i++)
{
sum += Math.ceil((double) arr[i] / (double) mid);
}
if(sum <= limit){
high = mid;
}
else{
low = mid + 1;
}
}
return low;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M.
Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K.
Next line contains N integers denoting the elements of arr[]
<b>Constraints:</b>
1 <= N <= 100000
1 <= arr[i] <= 100000
1 <= K <= 100000000Print a single integer the value of smallest number MSample Input:
4 6
2 3 4 9
Sample Output:
4
Explanation:
When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6
When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K.
Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: from math import ceil
def kSum(arr, n, k):
low = 0
high = 10 ** 9
while (low < high):
mid = (low + high) // 2
sum = 0
for i in range(int(n)):
sum += ceil( int(arr[i]) / mid)
if (sum <= int(k)):
high = mid
else:
low = mid + 1
return low
n, k =input().split()
arr = input().split()
print( kSum(arr, n, k) ), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M.
Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K.
Next line contains N integers denoting the elements of arr[]
<b>Constraints:</b>
1 <= N <= 100000
1 <= arr[i] <= 100000
1 <= K <= 100000000Print a single integer the value of smallest number MSample Input:
4 6
2 3 4 9
Sample Output:
4
Explanation:
When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6
When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K.
Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define ll 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 = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N], n, k;
bool f(int x){
int sum = 0;
for(int i = 1; i <= n; i++)
sum += (a[i]-1)/x + 1;
return (sum <= k);
}
void solve(){
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
int l = 0, h = N;
while(l+1 < h){
int m = (l + h) >> 1;
if(f(m))
h = m;
else
l = m;
}
cout << h;
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
} , In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For an integer N, your task is to calculate sum of first N natural numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to worry about input. You just have to complete the function <b>sum()</b> which takes the integer N as a parameter.
Constraints:
1 <= N < = 100000000Print the sum of first N natural numbers.Sample Input:-
5
Sample Output:-
15
Sample Input:-
3
Sample Output:-
6, I have written this Solution Code:
static void sum(int N){
long x=N;
x=x*(x+1);
x=x/2;
System.out.print(x);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number N.
<b>Note: </b>
The Factorial of a number is the product of an integer and all the integers below it;
e.g. factorial four ( 4! ) is equal to 24 (4*3*2*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 <i>Factorial()</i> which contains the given number N.
<b>Constraints:</b>
1 <= N <= 15
Return the factorial of the given number.Sample Input:-
5
Sample Output:-
120
Sample Input:-
3
Sample Output:-
6, I have written this Solution Code: def factorial(n):
if(n == 1):
return 1
return n * factorial(n-1)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number N.
<b>Note: </b>
The Factorial of a number is the product of an integer and all the integers below it;
e.g. factorial four ( 4! ) is equal to 24 (4*3*2*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 <i>Factorial()</i> which contains the given number N.
<b>Constraints:</b>
1 <= N <= 15
Return the factorial of the given number.Sample Input:-
5
Sample Output:-
120
Sample Input:-
3
Sample Output:-
6, I have written this Solution Code: static int Factorial(int N)
{
if(N==0){
return 1;}
return N*Factorial(N-1);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number N.
<b>Note: </b>
The Factorial of a number is the product of an integer and all the integers below it;
e.g. factorial four ( 4! ) is equal to 24 (4*3*2*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 <i>Factorial()</i> which contains the given number N.
<b>Constraints:</b>
1 <= N <= 15
Return the factorial of the given number.Sample Input:-
5
Sample Output:-
120
Sample Input:-
3
Sample Output:-
6, I have written this Solution Code: // n is the input number
function factorial(n) {
// write code here
// do not console.log
// return the answer as a number
if (n == 1 ) return 1;
return n * factorial(n-1)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pino is super fond of candies. Today she has A chocolate candies, B orange candies, and C unknown candies. You are also given the happiness she gets after eating a particular candy.
She wants to have exactly X chocolate candies and Y orange candies. She can transform an unknown candy into a candy of any type (chocolate or orange).
Find the maximum happiness she can attain.The first line of input contains 5 integers X, Y, A, B, and C.
The second line contains an A integer corresponding to the happiness of the various chocolate candies.
The third line contains B integers corresponding to the happiness of the various orange candies.
The fourth line contains C integers corresponding to the happiness of the various unknown candies.
<b>Constraints:-</b>
1 <= A, B, C <= 100000
1 <= X <= A
1 <= Y <= B
1 <= happiness of any candy <= 1000000000 (10^9)Output a single integer, the maximum happiness Pino can achieve by eating the candies.Sample Input 1:-
1 2 2 2 1
2 4
5 1
3
Sample Output 1:-
12
Sample Input 2:-
2 2 2 2 2
8 6
9 1
2 1
Sample Output 2:-
25
<b>Explanation:-</b>
Pino eats the 2nd chocolate candy (happiness=4), then eats the 1st orange candy (happiness=4+5=9), then transforms the first unknown candy to orange candy and eats it (happiness=9+3=12), I have written this Solution Code: X, Y, A, B, C = [int(i) for i in input().split()]
t = X + Y
a = sorted([int(i) for i in input().split()])
b = sorted([int(i) for i in input().split()])
c = [int(i) for i in input().split()]
o = []
for i in range(A-1,-1,-1):
if (X) == 0:
break
else:
X -= 1
o.append(a[i])
for i in range(B-1,-1,-1):
if (Y) == 0:
break
else:
Y -= 1
o.append(b[i])
o.extend(c)
s = 0
o.sort()
for i in range(len(o)-1,-1,-1):
if t == 0:
break
else:
t -= 1
s += o[i]
print(s), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pino is super fond of candies. Today she has A chocolate candies, B orange candies, and C unknown candies. You are also given the happiness she gets after eating a particular candy.
She wants to have exactly X chocolate candies and Y orange candies. She can transform an unknown candy into a candy of any type (chocolate or orange).
Find the maximum happiness she can attain.The first line of input contains 5 integers X, Y, A, B, and C.
The second line contains an A integer corresponding to the happiness of the various chocolate candies.
The third line contains B integers corresponding to the happiness of the various orange candies.
The fourth line contains C integers corresponding to the happiness of the various unknown candies.
<b>Constraints:-</b>
1 <= A, B, C <= 100000
1 <= X <= A
1 <= Y <= B
1 <= happiness of any candy <= 1000000000 (10^9)Output a single integer, the maximum happiness Pino can achieve by eating the candies.Sample Input 1:-
1 2 2 2 1
2 4
5 1
3
Sample Output 1:-
12
Sample Input 2:-
2 2 2 2 2
8 6
9 1
2 1
Sample Output 2:-
25
<b>Explanation:-</b>
Pino eats the 2nd chocolate candy (happiness=4), then eats the 1st orange candy (happiness=4+5=9), then transforms the first unknown candy to orange candy and eats it (happiness=9+3=12), 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
int red[N], grn[N], col[N];
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int x, y, a, b, c; cin>>x>>y>>a>>b>>c;
For(i, 0, a){
cin>>red[i];
}
For(i, 0, b){
cin>>grn[i];
}
For(i, 0, c){
cin>>col[i];
}
vector<int> vect;
sort(red, red+a); sort(grn, grn+b);
reverse(red, red+a); reverse(grn, grn+b);
For(i, 0, x){
vect.pb(red[i]);
}
For(i, 0, y){
vect.pb(grn[i]);
}
For(i, 0, c){
vect.pb(col[i]);
}
sort(all(vect));
reverse(all(vect));
int ans = 0;
For(i, 0, x+y){
ans+=vect[i];
}
cout<<ans;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pino is super fond of candies. Today she has A chocolate candies, B orange candies, and C unknown candies. You are also given the happiness she gets after eating a particular candy.
She wants to have exactly X chocolate candies and Y orange candies. She can transform an unknown candy into a candy of any type (chocolate or orange).
Find the maximum happiness she can attain.The first line of input contains 5 integers X, Y, A, B, and C.
The second line contains an A integer corresponding to the happiness of the various chocolate candies.
The third line contains B integers corresponding to the happiness of the various orange candies.
The fourth line contains C integers corresponding to the happiness of the various unknown candies.
<b>Constraints:-</b>
1 <= A, B, C <= 100000
1 <= X <= A
1 <= Y <= B
1 <= happiness of any candy <= 1000000000 (10^9)Output a single integer, the maximum happiness Pino can achieve by eating the candies.Sample Input 1:-
1 2 2 2 1
2 4
5 1
3
Sample Output 1:-
12
Sample Input 2:-
2 2 2 2 2
8 6
9 1
2 1
Sample Output 2:-
25
<b>Explanation:-</b>
Pino eats the 2nd chocolate candy (happiness=4), then eats the 1st orange candy (happiness=4+5=9), then transforms the first unknown candy to orange candy and eats it (happiness=9+3=12), I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String str[] = read.readLine().split(" ");
int X = Integer.parseInt(str[0]);
int Y = Integer.parseInt(str[1]);
int A = Integer.parseInt(str[2]);
int B = Integer.parseInt(str[3]);
int C = Integer.parseInt(str[4]);
int arr[] = new int[X+Y+C];
int arrA[] = new int[A];
int arrB[] = new int[B];
int arrC[] = new int[C];
String strA[] = read.readLine().split(" ");
for(int k = 0; k < A; k++) {
arrA[k] = Integer.parseInt(strA[k]);
}
Arrays.sort(arrA);
String strB[] = read.readLine().split(" ");
for(int p = 0; p < B; p++) {
arrB[p] = Integer.parseInt(strB[p]);
}
Arrays.sort(arrB);
String strC[] = read.readLine().split(" ");
for(int q = 0; q < C; q++) {
arrC[q] = Integer.parseInt(strC[q]);
}
Arrays.sort(arrC);
System.arraycopy(arrA, arrA.length - X, arr, 0, X);
System.arraycopy(arrB, arrB.length - Y, arr, X, Y);
System.arraycopy(arrC, 0, arr, X+Y, C);
Arrays.sort(arr);
long happiness = 0;
int lastIndex = arr.length - 1;
int candies = 0;
for(int z = lastIndex; z >= 0; z--) {
happiness += arr[z];
candies++;
if(candies == X + Y) {
break;
}
}
System.out.print(happiness);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers and an integer K, your task is to calculate the count of pairs whose sum is divisible by K.The first line of input contains two integers N and K, the next line contains N space-separated integers depicting values of an array.
Constraints:-
1 < = N < = 100000
1 < = Arr[i] <= 100000
1 <= K <= 100000Print the count of required pairs.Sample Input
5 4
1 2 3 4 5
Sample Output
2
Sample Input
5 3
1 2 3 4 5
Sample Output
4
Explanation:-
In Sample 2,
(1 5), (1 2), (2 4), and (4 5) are the required pairs, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static long subarraysDivByK(int[] A, int k)
{
long ans =0 ;
int rem;
int[] freq = new int[k];
for(int i=0;i<A.length;i++)
{
rem = A[i]%k;
ans += freq[(k - rem)% k] ;
freq[rem]++;
}
return ans;
}
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().split(" ");
String[] input = br.readLine().split(" ");
int n = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
int [] a = new int [n];
for(int i=0; i<n; i++)
a[i] = Integer.parseInt(input[i]);
System.out.println(subarraysDivByK(a, k));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers and an integer K, your task is to calculate the count of pairs whose sum is divisible by K.The first line of input contains two integers N and K, the next line contains N space-separated integers depicting values of an array.
Constraints:-
1 < = N < = 100000
1 < = Arr[i] <= 100000
1 <= K <= 100000Print the count of required pairs.Sample Input
5 4
1 2 3 4 5
Sample Output
2
Sample Input
5 3
1 2 3 4 5
Sample Output
4
Explanation:-
In Sample 2,
(1 5), (1 2), (2 4), and (4 5) are the required pairs, I have written this Solution Code: def countKdivPairs(A, n, K):
freq = [0] * K
for i in range(n):
freq[A[i] % K]+= 1
sum = freq[0] * (freq[0] - 1) / 2;
i = 1
while(i <= K//2 and i != (K - i) ):
sum += freq[i] * freq[K-i]
i+= 1
if( K % 2 == 0 ):
sum += (freq[K//2] * (freq[K//2]-1)/2);
return int(sum)
a,b=input().split()
a=int(a)
b=int(b)
arr=input().split()
for i in range(0,a):
arr[i]=int(arr[i])
print (countKdivPairs(arr,a, b)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers and an integer K, your task is to calculate the count of pairs whose sum is divisible by K.The first line of input contains two integers N and K, the next line contains N space-separated integers depicting values of an array.
Constraints:-
1 < = N < = 100000
1 < = Arr[i] <= 100000
1 <= K <= 100000Print the count of required pairs.Sample Input
5 4
1 2 3 4 5
Sample Output
2
Sample Input
5 3
1 2 3 4 5
Sample Output
4
Explanation:-
In Sample 2,
(1 5), (1 2), (2 4), and (4 5) are the required pairs, 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 MOD 1000000007
#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
fast();
int n;
cin>>n;
int a;
int k;
cin>>k;
int fre[k];
FOR(i,k){
fre[i]=0;}
FOR(i,n){
cin>>a;
fre[a%k]++;
}
int ans=(fre[0]*(fre[0]-1))/2;
for(int i=1;i<=(k-1)/2;i++){
ans+=fre[i]*fre[k-i];
}
if(k%2==0){
ans+=(fre[k/2]*(fre[k/2]-1))/2;
}
out(ans);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Monkey patching is a dynamic technique in Python by which you can modify the behavior of an existing class or module.
Given a class in which even and odd function is defined however they got reversed, your task is to correct them by using Monkey patching.
<b>Note</b>:- Object is already defined for the class you have to perform your operations on the given object only.<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>monkeyPatching()</b> that takes no parameter.You don't need to print anything you just need to complete the given function.Sample Input:-
3
Sample Output:-
The number is odd
Sample Input:-
4
Sample Output:-
The number is even, I have written this Solution Code:
def res1():
print("The number is odd")
def res2():
print("The number is even")
def monkeyPatching():
Monkey.Even=res2
Monkey.Odd=res1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 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));
int N = Integer.parseInt(br.readLine());
double arr[] = new double[N];
String str[] = br.readLine().trim().split(" ");
for(int i=0;i<N;i++)
arr[i]=Integer.parseInt(str[i]);
double resistance=0;
int equResistance=0;
for(int i=0;i<N;i++)
arr[i]=Integer.parseInt(str[i]);
for(int i=0;i<N;i++)
{
resistance=resistance+(1/arr[i]);
}
equResistance = (int)Math.floor((1/resistance));
System.out.println(equResistance);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: r = input("")
r = int(r)
n = input("").split()
resistance=0.0
for i in range(0,r):
resistor = float(n[i])
resistance = resistance + (1/resistor)
print(int(1/resistance)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n; cin >> n;
double s = 0;
for(int i = 1; i <= n; i++){
double p; cin >> p;
s = s + (1/p);
}
s = 1/s;
cout << floor(s);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Print the number of connected components using scipy csgraph1st line: Number of nodes
Next n lines: Adjacency matrixNumber of componetsInput:
3
0 1 2
1 0 0
2 0 0
Output:
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
mat = new ArrayList<>();
for(int i=0; i<n; i++) mat.add(new ArrayList<>());
for(int i=0;i<n;i++){
for(int j =0; j < n; j++) {
int x = sc.nextInt();
if(x != 0) {
mat.get(i).add(j);
mat.get(j).add(i);
}
}
}
boolean vis[] = new boolean[n];
int cc = 0;
for(int i=0; i<n; i++){
if(!vis[i]){
dfs(i,vis);
cc++;
}
}
System.out.print(cc);
}
static ArrayList<ArrayList<Integer>> mat;
static void dfs(int ind, boolean[] vis) {
if(vis[ind]) return;
vis[ind] = true;
for(int x: mat.get(ind)){
if(!vis[x]) dfs(x,vis);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Print the number of connected components using scipy csgraph1st line: Number of nodes
Next n lines: Adjacency matrixNumber of componetsInput:
3
0 1 2
1 0 0
2 0 0
Output:
1, I have written this Solution Code: import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
n=int(input())
arr=np.array([input().strip().split() for _ in range(n)],int)
newarr = csr_matrix(arr)
print(connected_components(newarr)[0]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to check whether the given number is prime or notThe input contains a single integer N.
Constraints:-
1 <= N <= 100000000000Print "YES" If the given number is prime else print "NO".Sample Input:-
2
Sample Output:-
YES
Sample Input:-
4
Sample Output:-
NO, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
int p=(int)Math.sqrt(n);
for(int i=2;i<=p;i++){
if(n%i==0){System.out.print("NO");return;}
}
System.out.print("YES");
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to check whether the given number is prime or notThe input contains a single integer N.
Constraints:-
1 <= N <= 100000000000Print "YES" If the given number is prime else print "NO".Sample Input:-
2
Sample Output:-
YES
Sample Input:-
4
Sample Output:-
NO, I have written this Solution Code: import math
def isprime(A):
if A == 1:
return False
sqrt = int(math.sqrt(A))
for i in range(2,sqrt+1):
if A%i == 0:
return False
return True
inp = int(input())
if isprime(inp):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to check whether the given number is prime or notThe input contains a single integer N.
Constraints:-
1 <= N <= 100000000000Print "YES" If the given number is prime else print "NO".Sample Input:-
2
Sample Output:-
YES
Sample Input:-
4
Sample Output:-
NO, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
long n;
cin>>n;
long x = sqrt(n);
for(int i=2;i<=x;i++){
if(n%i==0){cout<<"NO";return 0;}
}
cout<<"YES";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You must be familiar with various types of operators. One of the most commonly used operators in any language are increment and decrement operators. Given two numbers X and Y. Your task is to print the value of X decremented by 1 and value of Y after incremented by 1.The first line of the input contains two integers X and Y.
<b>Constraints:</b>
1 ≤ X, Y ≤ 10000You need to perform the task as mentioned in the question, and finally, print the result separated by a space.Sample Input 1:
4 5
Sample Output 1:
3 6
Sample Input 2:
5 6
Sample Output 2:
4 7, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
x--;
y++;
System.out.print(x);
System.out.print(" ");
System.out.print(y);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You must be familiar with various types of operators. One of the most commonly used operators in any language are increment and decrement operators. Given two numbers X and Y. Your task is to print the value of X decremented by 1 and value of Y after incremented by 1.The first line of the input contains two integers X and Y.
<b>Constraints:</b>
1 ≤ X, Y ≤ 10000You need to perform the task as mentioned in the question, and finally, print the result separated by a space.Sample Input 1:
4 5
Sample Output 1:
3 6
Sample Input 2:
5 6
Sample Output 2:
4 7, I have written this Solution Code: def incremental_decremental(x, y):
x -= 1
y += 1
print(x, y, end =' ')
def main():
input1 = input().split()
x = int(input1[0])
y = int(input1[1])
#z = int(input1[2])
incremental_decremental(x, y)
if __name__ == '__main__':
main(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
def checkSpecial_M_Visor(N,M) :
# Final result of summation of divisors
i=2;
count=0
while i<=N :
if(N%i==0):
count=count+1
i=i+2
if(count == M):
return "Yes"
return "No"
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
static String checkSpecial_M_Visor(int N, int M)
{
int temp=0;
for(int i = 2; i <=N; i+=2)
{
if(N%i==0)
temp++;
}
if(temp==M)
return "Yes";
else return "No";
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
string checkSpecial_M_Visor(int N,int M){
int count=0;
for(int i=2;i<=N;i+=2){
if(N%i==0){
count++;
}
}
if(count==M){return "Yes";}
return "No";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code: const char* checkSpecial_M_Visor(int N,int M){
int count=0;
for(int i=2;i<=N;i+=2){
if(N%i==0){
count++;
}
}
char* ans;
if(count==M){return "Yes";}
return "No";
}
, 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 non-negative integers. You have to move all 0's to the end of array while maintaining the relative order of the non-zero elements.
Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.The first line of input line contains T, denoting the number of testcases. Each test cases contains 2 lines. First-line contains N, size of array. Second-line contains elements of array separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^5
<b>Sum of N over all testcases does not exceed 10^6</b>
For each testcase you need to print the updated array.Sample Input:
2
5
0 1 0 3 12
8
0 0 0 0 1 2 3 4
Sample Output:
1 3 12 0 0
1 2 3 4 0 0 0 0, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t;
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 j=-1;
for(int i=0;i<n;i++){
if(a[i]==0 && j==-1){
j=i;
}
if(j!=-1 && a[i]!=0){
a[j]=a[i];
a[i]=0;
j++;
}
}
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 non-negative integers. You have to move all 0's to the end of array while maintaining the relative order of the non-zero elements.
Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.The first line of input line contains T, denoting the number of testcases. Each test cases contains 2 lines. First-line contains N, size of array. Second-line contains elements of array separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^5
<b>Sum of N over all testcases does not exceed 10^6</b>
For each testcase you need to print the updated array.Sample Input:
2
5
0 1 0 3 12
8
0 0 0 0 1 2 3 4
Sample Output:
1 3 12 0 0
1 2 3 4 0 0 0 0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,k;
cin>>n;
int a[n];
int cnt=0;
for(int i=0;i<n;i++){
cin>>a[i];\
if(a[i]==0){cnt++;}
}
for(int i=0;i<n;i++){
if(a[i]!=0){
cout<<a[i]<<" ";
}
}
while(cnt--){
cout<<0<<" ";
}
cout<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are A Bacterias.
Each time Jerry shouts, the bacterias multiply by K times.
In order to have B or more slimes, at least how many times does Jerry need to shout?Input is given from Standard Input in the following format:
A B K
<b>Constraints</b>
1≤A≤B≤10^9
2≤K≤10^9
All values in input are integers.Print the answer.<b>Sample Input 1</b>
1 4 2
<b>Sample Output 1</b>
2
<b>Sample Input 2</b>
7 7 10
<b>Sample Output 2</b>
0
<b>Sample Input 3</b>
31 415926 5
<b>Sample Output 3</b>
6
(In first case, after the first shout Jerry will have 2 bacteria and after the second shout, he will have 4(2*2) bacteria., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define subnb true
#define Lnb true
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ll a, b, k;
cin >> a >> b >> k;
int res = 0;
while(a < b) {
a *= k;
res++;
}
cout << res << '\n';
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rohit's uncle gives him D chocolates for up to N days, He already has C chocolates with him if he eats one chocolate a day how many chocolates will he have at the end of N days?<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>Chocolates()</b> that takes integers D, N and C as parameters.
Constraints:-
1 <= D <= 100
1 <= N <= 100
1 <= C <= 100Return the number of chocolates at the end of N daysSample Input:-
5 5 5
Sample Output:-
25
Explanation:-
At the end of the First day:- 5 + 5 - 1 = 9
At the end of the Second day:- 9 + 5 - 1 = 13
At the end of the Third day:- 13 + 5 - 1 = 17
At the end of the Fourth day:- 17 + 5 - 1 = 21
At the end of the Fifth day:- 21 + 5 - 1 = 25
Sample Input:-
1 2 3
Sample Output:-
3, I have written this Solution Code:
int Chocolates(int D, int N, int C){
return N*(D-1)+C;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rohit's uncle gives him D chocolates for up to N days, He already has C chocolates with him if he eats one chocolate a day how many chocolates will he have at the end of N days?<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>Chocolates()</b> that takes integers D, N and C as parameters.
Constraints:-
1 <= D <= 100
1 <= N <= 100
1 <= C <= 100Return the number of chocolates at the end of N daysSample Input:-
5 5 5
Sample Output:-
25
Explanation:-
At the end of the First day:- 5 + 5 - 1 = 9
At the end of the Second day:- 9 + 5 - 1 = 13
At the end of the Third day:- 13 + 5 - 1 = 17
At the end of the Fourth day:- 17 + 5 - 1 = 21
At the end of the Fifth day:- 21 + 5 - 1 = 25
Sample Input:-
1 2 3
Sample Output:-
3, I have written this Solution Code: def Chocolates(D,N,C):
return N*(D-1) + C
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rohit's uncle gives him D chocolates for up to N days, He already has C chocolates with him if he eats one chocolate a day how many chocolates will he have at the end of N days?<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>Chocolates()</b> that takes integers D, N and C as parameters.
Constraints:-
1 <= D <= 100
1 <= N <= 100
1 <= C <= 100Return the number of chocolates at the end of N daysSample Input:-
5 5 5
Sample Output:-
25
Explanation:-
At the end of the First day:- 5 + 5 - 1 = 9
At the end of the Second day:- 9 + 5 - 1 = 13
At the end of the Third day:- 13 + 5 - 1 = 17
At the end of the Fourth day:- 17 + 5 - 1 = 21
At the end of the Fifth day:- 21 + 5 - 1 = 25
Sample Input:-
1 2 3
Sample Output:-
3, I have written this Solution Code:
int Chocolates(int D, int N, int C){
return N*(D-1)+C;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rohit's uncle gives him D chocolates for up to N days, He already has C chocolates with him if he eats one chocolate a day how many chocolates will he have at the end of N days?<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>Chocolates()</b> that takes integers D, N and C as parameters.
Constraints:-
1 <= D <= 100
1 <= N <= 100
1 <= C <= 100Return the number of chocolates at the end of N daysSample Input:-
5 5 5
Sample Output:-
25
Explanation:-
At the end of the First day:- 5 + 5 - 1 = 9
At the end of the Second day:- 9 + 5 - 1 = 13
At the end of the Third day:- 13 + 5 - 1 = 17
At the end of the Fourth day:- 17 + 5 - 1 = 21
At the end of the Fifth day:- 21 + 5 - 1 = 25
Sample Input:-
1 2 3
Sample Output:-
3, I have written this Solution Code:
static int Chocolates(int D, int N, int C){
return N*(D-1)+C;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: int Probability(int A,int B){
int x=1;
for(int i=2;i<=A;i++){
if(A%i==0 && B%i==0){
x=i;
}
}
A=A/x;
B=B/x;
return A+B;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: int Probability(int A,int B){
int x=1;
for(int i=2;i<=A;i++){
if(A%i==0 && B%i==0){
x=i;
}
}
A=A/x;
B=B/x;
return A+B;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: static int Probability(int A,int B){
int x=1;
for(int i=2;i<=A;i++){
if(A%i==0 && B%i==0){
x=i;
}
}
A=A/x;
B=B/x;
return A+B;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: def Probability(A,B):
x=1
for i in range (2,A+1):
if (A%i==0) and (B%i==0):
x=i
A=A//x
B=B//x
return A+B
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S.
Constraints
1 <= |S| <= 100000
S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input
ABAAABBBAA
Sample Output
3
Explanation: Substring from character 3-5 is the longest consisting of As only.
Sample Input
AAAA
Sample Output
4, 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 st = br.readLine();
int len = 0;
int c=0;
for(int i=0;i<st.length();i++){
if(st.charAt(i)=='A'){
c++;
len = Math.max(len,c);
}else{
c=0;
}
}
System.out.println(len);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S.
Constraints
1 <= |S| <= 100000
S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input
ABAAABBBAA
Sample Output
3
Explanation: Substring from character 3-5 is the longest consisting of As only.
Sample Input
AAAA
Sample Output
4, I have written this Solution Code: S=input()
max=0
flag=0
for i in range(0,len(S)):
if(S[i]=='A' or S[i]=='B'):
if(S[i]=='A'):
flag+=1
if(flag>max):
max=flag
else:
flag=0
print(max), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S.
Constraints
1 <= |S| <= 100000
S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input
ABAAABBBAA
Sample Output
3
Explanation: Substring from character 3-5 is the longest consisting of As only.
Sample Input
AAAA
Sample Output
4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
string s; cin>>s;
int ct = 0;
int ans = 0;
for(char c: s){
if(c == 'A')
ct++;
else
ct=0;
ans = max(ans, ct);
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String [] str=br.readLine().trim().split(" ");
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=Integer.parseInt(str[i]);
}
Arrays.sort(a);
int size=a[n-1]+1;
int c[]=new int[size];
for(int i=0;i<size;i++) c[i]=0;
for(int i=0;i<n;i++) c[a[i]]++;
int max=0,freq=c[1];
for(int i=2;i<size;i++){
if(freq<=c[i]){
freq=c[i];
max=i;
}
}
System.out.println(max);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: n = int(input())
a = [int(x) for x in input().split()]
freq = {}
for x in a:
if x not in freq:
freq[x] = 1
else:
freq[x] += 1
mx = max(freq.values())
rf = sorted(freq)
for i in range(len(rf) - 1, -1, -1):
if freq[rf[i]] == mx:
print(rf[i])
break, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int n; cin >> n;
for(int i = 1; i <= n; i++){
int p; cin >> p;
a[p]++;
}
int mx = 0, id = -1;
for(int i = 1; i <= 100; i++){
if(a[i] >= mx)
mx = a[i], id = i;
}
cout << id;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string of length N, count the number of vowels present at even places.First line of input contains a single integer N. Second line contains a string of size N.
Constraints:-
1 <= N <= 100000
Note:- String will contain only lowercase english letterPrint the number of vowels present at the even placesSample Input:-
12
newtonschool
Sample Output:-
2
Sample Input:-
5
basid
Sample Output:-
2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
String name = reader.readLine();
String s=reader.readLine();
long c=0;
for(int i=1;i<s.length();i=i+2){
if(s.charAt(i)=='a'||s.charAt(i)=='e'||s.charAt(i)=='i'||s.charAt(i)=='o'||s.charAt(i)=='u')
c++;
}
System.out.println(c);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string of length N, count the number of vowels present at even places.First line of input contains a single integer N. Second line contains a string of size N.
Constraints:-
1 <= N <= 100000
Note:- String will contain only lowercase english letterPrint the number of vowels present at the even placesSample Input:-
12
newtonschool
Sample Output:-
2
Sample Input:-
5
basid
Sample Output:-
2, I have written this Solution Code: def check(c):
if c=='a' or c=='e' or c=='i' or c=='o' or c=='u':
return True
else:
return False
n=int(input())
s=input()
j=0
cnt=0
ans=0
for i in range(0,n):
j=i+1
if j%2==0:
if check(s[i]):
#=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u':
cnt+=1
print(cnt)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string of length N, count the number of vowels present at even places.First line of input contains a single integer N. Second line contains a string of size N.
Constraints:-
1 <= N <= 100000
Note:- String will contain only lowercase english letterPrint the number of vowels present at the even placesSample Input:-
12
newtonschool
Sample Output:-
2
Sample Input:-
5
basid
Sample Output:-
2, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
bool check(char c){
if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u'){return true;}
else{
return false;
}
}
int main() {
int n; cin>>n;
string s;
cin>>s;
int j=0;
int cnt=0;
int ans=0;
for(int i=0;i<n;i++){
if(i&1){
if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u'){
cnt++;
}}
}
cout<<cnt;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list, the task is to move all 0’s to the front of the linked list. The order of all another element except 0 should be same after rearrangement.
Note: Avoid use of any type of Java Collection frameworks.
Note: For custom input/output, enter the list in reverse order, and the output will come in right order.<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>moveZeroes()</b> that takes head node as parameter.
Constraints:
1 <= T <= 100
1 <= N <= 100000
0<=Node.data<=100000
Note:- Sum of all test cases doesn't exceed 10^5
Return the head of the modified linked list.Input:
2
10
0 4 0 5 0 2 1 0 1 0
7
1 1 2 3 0 0 0
Output:
0 0 0 0 0 4 5 2 1 1
0 0 0 1 1 2 3
Explanation:
Testcase 1:
Original list was 0->4->0->5->0->2->1->0->1->0->NULL.
After processing list becomes 0->0->0->0->0->4->5->2->1->1->NULL.
Testcase 2:
Original list was 1->1->2->3->0->0->0->NULL.
After processing list becomes 0->0->0->1->1->2->3->NULL., I have written this Solution Code: static public Node moveZeroes(Node head){
ArrayList<Integer> a=new ArrayList<>();
int c=0;
while(head!=null){
if(head.data==0){
c++;
}
else{
a.add(head.data);
}
head=head.next;
}
head=null;
for(int i=a.size()-1;i>=0;i--){
if(head==null){
head=new Node(a.get(i));
}
else{
Node temp=new Node(a.get(i));
temp.next=head;
head=temp;
}
}
while(c-->0){
Node temp=new Node(0);
temp.next=head;
head=temp;
}
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: int Probability(int A,int B){
int x=1;
for(int i=2;i<=A;i++){
if(A%i==0 && B%i==0){
x=i;
}
}
A=A/x;
B=B/x;
return A+B;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: int Probability(int A,int B){
int x=1;
for(int i=2;i<=A;i++){
if(A%i==0 && B%i==0){
x=i;
}
}
A=A/x;
B=B/x;
return A+B;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: static int Probability(int A,int B){
int x=1;
for(int i=2;i<=A;i++){
if(A%i==0 && B%i==0){
x=i;
}
}
A=A/x;
B=B/x;
return A+B;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: def Probability(A,B):
x=1
for i in range (2,A+1):
if (A%i==0) and (B%i==0):
x=i
A=A//x
B=B//x
return A+B
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program that creates an N*N matrix. Fill each cell with the sum of row number and column number (based on 0 indexes, ie indices begin from base 0), take its transpose and print it.
Where the transpose of a matrix is a new matrix whose rows and the columns are interchanged to that of original matrix.Input contains a single integer N.
Constraints:-
1<=N<=500Print the NxN matrix.Sample input
2
Sample output
0 1
1 2
Explanation:-
0+0 0+1
1+0 1+1
Sample Input:-
3
Sample Output:-
0 1 2
1 2 3
2 3 4
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[][] a=new int[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(i+j + " ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program that creates an N*N matrix. Fill each cell with the sum of row number and column number (based on 0 indexes, ie indices begin from base 0), take its transpose and print it.
Where the transpose of a matrix is a new matrix whose rows and the columns are interchanged to that of original matrix.Input contains a single integer N.
Constraints:-
1<=N<=500Print the NxN matrix.Sample input
2
Sample output
0 1
1 2
Explanation:-
0+0 0+1
1+0 1+1
Sample Input:-
3
Sample Output:-
0 1 2
1 2 3
2 3 4
, I have written this Solution Code: n=int(input())
for i in range(n):
for j in range(n):
print(i+ j,end=' ')
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program that creates an N*N matrix. Fill each cell with the sum of row number and column number (based on 0 indexes, ie indices begin from base 0), take its transpose and print it.
Where the transpose of a matrix is a new matrix whose rows and the columns are interchanged to that of original matrix.Input contains a single integer N.
Constraints:-
1<=N<=500Print the NxN matrix.Sample input
2
Sample output
0 1
1 2
Explanation:-
0+0 0+1
1+0 1+1
Sample Input:-
3
Sample Output:-
0 1 2
1 2 3
2 3 4
, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
arr[i][j]=i+j;
}}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<arr[i][j]<<" ";
}
cout<<endl;}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Get and update data using python OOPs using getter and setter method1st line: Student name and Student age
2nd line: Number of operations n
Next n lines: string like g or s.If the string if g print the name and age of the studentInput:
Jessica 15
5
g
s 12
g
s 13
g
Output:
Jessica 15
Jessica 12
Jessica 13, I have written this Solution Code: class Student:
def __init__(self,name,age):
self.name=name
self.__age=age
def get_age(self):
print(self.name,self.__age)
def set_age(self,number):
self.__age=number
name,age=input().strip().split()
s1=Student(name,age)
n=int(input())
for i in range(n):
a=input().strip().split()
if(a[0]=="g"):
s1.get_age()
else:
s1.set_age(a[1])
, 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: 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: 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: Numbers are awesome, larger numbers are more awesome!
Given an array A of size N, you need to find the maximum sum that can be obtained from the elements of the array (the selected elements need not be contiguous). You may even decide to take no element to get a sum of 0.The first line of the input contains the size of the array.
The next line contains N (white-space separated) integers denoting the elements of the array.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>4</sup>
-10<sup>7</sup> ≤ A[i] ≤10<sup>7</sup>For each test case, output one integer representing the maximum value of the sum that can be obtained using the various elements of the array.Input 1:
5
1 2 1 -1 1
output 1:
5
input 2:
5
0 0 -1 0 0
output 2:
0
<b>Explanation 1:</b>
In order to maximize the sum among [ 1 2 1 -1 1], we need to only consider [ 1 2 1 1] and neglect the [-1]., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n; cin >> n;
int sum = 0;
for(int i = 1; i <= n; i++){
int p; cin >> p;
if(p > 0)
sum += p;
}
cout << sum;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Numbers are awesome, larger numbers are more awesome!
Given an array A of size N, you need to find the maximum sum that can be obtained from the elements of the array (the selected elements need not be contiguous). You may even decide to take no element to get a sum of 0.The first line of the input contains the size of the array.
The next line contains N (white-space separated) integers denoting the elements of the array.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>4</sup>
-10<sup>7</sup> ≤ A[i] ≤10<sup>7</sup>For each test case, output one integer representing the maximum value of the sum that can be obtained using the various elements of the array.Input 1:
5
1 2 1 -1 1
output 1:
5
input 2:
5
0 0 -1 0 0
output 2:
0
<b>Explanation 1:</b>
In order to maximize the sum among [ 1 2 1 -1 1], we need to only consider [ 1 2 1 1] and neglect the [-1]., I have written this Solution Code: n=int(input())
li = list(map(int,input().strip().split()))
sum=0
for i in li:
if i>0:
sum+=i
print(sum), 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.