Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given an array of N integers, your task is to find the maximum value of the sum of its subarray modulo M, i. e., find the sum of each subarray mod M and print the maximum value of this after modulo operation.The first line of input contains two space-separated integers N and M, the next line of input contains N space-separated integers depicting value of the array.
<b>Constraints:-</b>
1 < = N < = 100000
1 < = M < = 10000000000
1 < = Arr[i] < = 10000000000Print the maximum value of sum modulo m.Sample Input:-
5 13
6 6 11 15 2
Sample Output:-
12
Explanation:
[6, 6] is subarray is maximum sum modulo 13
Sample Input:-
3 15
1 2 3
Sample Output:-
6
Explanation:
Max sum occurs when we take the whole array, I have written this Solution Code: import bisect
def maximumSum(coll, m):
n = len(coll)
maxSum, prefixSum = 0, 0
sortedPrefixes = []
for endIndex in range(n):
prefixSum = (prefixSum + coll[endIndex]) % m
maxSum = max(maxSum, prefixSum)
startIndex = bisect.bisect_right(sortedPrefixes, prefixSum)
if startIndex < len(sortedPrefixes):
maxSum = max(maxSum, prefixSum - sortedPrefixes[startIndex] + m)
bisect.insort(sortedPrefixes, prefixSum)
return maxSum
a,b=map(int,input().split())
c=list(map(int,input().split()))
print(maximumSum(c,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, your task is to find the maximum value of the sum of its subarray modulo M, i. e., find the sum of each subarray mod M and print the maximum value of this after modulo operation.The first line of input contains two space-separated integers N and M, the next line of input contains N space-separated integers depicting value of the array.
<b>Constraints:-</b>
1 < = N < = 100000
1 < = M < = 10000000000
1 < = Arr[i] < = 10000000000Print the maximum value of sum modulo m.Sample Input:-
5 13
6 6 11 15 2
Sample Output:-
12
Explanation:
[6, 6] is subarray is maximum sum modulo 13
Sample Input:-
3 15
1 2 3
Sample Output:-
6
Explanation:
Max sum occurs when we take the whole array, I have written this Solution Code: #include<bits/stdc++.h>
#define int long long
using namespace std;
// Return the maximum sum subarray mod m.
int maxSubarray(int arr[], int n, int m)
{
int x, prefix = 0, maxim = 0;
set<int> S;
S.insert(0);
// Traversing the array.
for (int i = 0; i < n; i++)
{
// Finding prefix sum.
prefix = (prefix + arr[i])%m;
// Finding maximum of prefix sum.
maxim = max(maxim, prefix);
// Finding iterator pointing to the first
// element that is not less than value
// "prefix + 1", i.e., greater than or
// equal to this value.
auto it = S.lower_bound(prefix+1);
if (it != S.end())
maxim = max(maxim, prefix - (*it) + m );
// Inserting prefix in the set.
S.insert(prefix);
}
return maxim;
}
// Driver Program
signed main()
{
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
cout << maxSubarray(a, n, m) << endl;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B.
The next two lines contain the input of arrays A and B.
<b>Constraints</b>
1 ≤ n, m ≤ 1000
-10<sup>6</sup> ≤ A[i], B[i] ≤ 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input :
2 1
1 3
2
Sample Output :
2.00, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.util.Arrays;
class Main {
public static double getMedia(long[]a,long[]b){
if(a.length>b.length){
long[]temp;
temp=a;
a=b;b=temp;
}
int lo=0;
int hi=a.length;
int tl=a.length+b.length;
while(lo<=hi){
int al=(lo+hi)/2;
int bl=((tl+1)/2)-al;
long alm1=(al==0)? Long.MIN_VALUE:a[al-1];
long alf=(al==a.length)? Long.MAX_VALUE:a[al];
long blm1=(bl==0)? Long.MIN_VALUE:b[bl-1];
long blf=(bl==b.length)? Long.MAX_VALUE:b[bl];
if(alm1<=blf && blm1<=alf){
double median = 0.0;
if(tl%2==0){
long lmax=Math.max(alm1,blm1);
long rmin=Math.min(alf,blf);
median=(lmax+rmin)/2.0;
return median;
}else{
long lmax=Math.max(alm1,blm1);
median=lmax;
return median;
}
}
else if(alm1>blf){
hi=al-1;
}else if(blm1>alf){
lo=al+1;
}
}
return 0;
}
public static void main (String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().split(" ");
int n=Integer.parseInt(str[0]);
int m=Integer.parseInt(str[1]);
long[] a=new long[n];
long[] b=new long[m];
str=br.readLine().split(" ");
for(int i=0;i<n;i++){
a[i]=Long.parseLong(str[i]);
}
str=br.readLine().split(" ");
for(int i=0;i<m;i++){
b[i]=Long.parseLong(str[i]);
}
System.out.format("%.2f",getMedia(a,b));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B.
The next two lines contain the input of arrays A and B.
<b>Constraints</b>
1 ≤ n, m ≤ 1000
-10<sup>6</sup> ≤ A[i], B[i] ≤ 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input :
2 1
1 3
2
Sample Output :
2.00, I have written this Solution Code: def getMedian(arr1, arr2, n, m):
i=j=0
sort=[]
while i<n and j<m:
if arr1[i] < arr2[j]:
sort.append(arr1[i])
i+=1
else:
sort.append(arr2[j])
j+=1
while i<n:
sort.append(arr1[i])
i+=1
while j<m:
sort.append(arr2[j])
j+=1
if (n+m)%2==1:
ind=(len(sort)//2)+1
num=sort[ind-1]
else:
mid=len(sort)//2
num=(sort[mid-1]+sort[mid])/2
return num
n, m= input().split()
n, m= int(n),int(m)
ar1=list(map(int, input().split()))
ar2=list(map(int, input().split()))
print("%.2f" %getMedian(ar1, ar2, n, m)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted arrays A and B of size n and m respectively, return the median of the two sorted arrays.The first line of input contains n, m the length of arrays A and B.
The next two lines contain the input of arrays A and B.
<b>Constraints</b>
1 ≤ n, m ≤ 1000
-10<sup>6</sup> ≤ A[i], B[i] ≤ 10<sup>6</sup>Print the median of two sorted arrays upto two decimal places.Sample Input :
2 1
1 3
2
Sample Output :
2.00, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-02-02 14:05:28
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
if (nums2.size() < nums1.size())
return findMedianSortedArrays(nums2, nums1);
int n1 = nums1.size();
int n2 = nums2.size();
int lo = 0, hi = n1;
while (lo <= hi) {
int cut1 = (lo + hi) / 2;
int cut2 = (n1 + n2 + 1) / 2 - cut1;
int left1 = cut1 == 0 ? INT_MIN : nums1[cut1 - 1];
int left2 = cut2 == 0 ? INT_MIN : nums2[cut2 - 1];
int right1 = cut1 == n1 ? INT_MAX : nums1[cut1];
int right2 = cut2 == n2 ? INT_MAX : nums2[cut2];
if (left1 <= right2 && left2 <= right1) {
if ((n1 + n2) % 2 == 0)
return (max(left1, left2) + min(right1, right2)) / 2.0;
else
return max(left1, left2);
} else if (left1 > right2) {
hi = cut1 - 1;
} else
lo = cut1 + 1;
}
return 0.0;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
printf("%0.2f", findMedianSortedArrays(a, b));
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 your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: def firstTwo(N):
while(N>99):
N=N//10
return (N%10)*10 + N//10
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: static int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the Main class. Implement the getArea() and getPerimeter() methods for the child classes Parallelogram, Rhombus, Rectangle, and Square having Abstract class Quadrilateral as a parent class.
Do not change the name of any classThe first line of input contains side1, side2 and height of the parallelogram
The second line of input contains side and height of rhombus
The third line of input contains length and height of the rectangle
The fourth line of input contains side of square
If the length of any side or height for any shape is negative, then print <b><i>Length of a side cannot be negative. Please Enter a positive integer.</b></i>"Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea()
"Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea()
"Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea()
"Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea()
Sample Input 1:
1.0 2.0 3.0
7.0 5.0
4.0 2.0
6.0
Sample Output 2:
Perimeter of Parallelogram is 6.0 and Area of Parallelogram is 3.0
Perimeter of Rhombus is 28.0 and Area of Rhombus is 35.0
Perimeter of Rectangle is 12.0 and Area of Rectangle is 8.0
Perimeter of Square is 24.0 and Area of Square is 36.0
Sample Input 2:
3.0 9.0 7.0
6.0 4.0
-1.0 5.0
8.0
Sample Output 2:
Length of a side cannot be negative. Please Enter a positive integer
, I have written this Solution Code: from abc import ABC, abstractmethod
class Quadrilateral(ABC):
def __init__(self, side1, side2, side3, side4):
self.side1, self.side2, self.side3, self.side4 = side1, side2, side3, side4
@abstractmethod
def getArea(self):
pass
def getPerimeter(self):
return (self.side1+self.side2+self.side3+self.side4)
class Parallelogram(Quadrilateral):
def __init__(self, side1, side2, height):
super().__init__(side1, side2, side1, side2)
self.heightPerpendicularToSide1 = height
def getArea(self):
return self.side1*self.heightPerpendicularToSide1
class Rhombus(Parallelogram):
def __init__(self, side, height):
super().__init__(side, side, height)
class Rectangle(Parallelogram):
def __init__(self, length, breadth):
super().__init__(length, breadth, breadth)
class Square(Rhombus):
def __init__(self, side):
super().__init__(side, side)
def main():
# Parallelogram
side1, side2, height = map(float, input().split())
# side1 = float(input())
# side2 = float(input())
# height = float(input())
parallelogram = Parallelogram(side1, side2, height)
# Rhombus
side, heightOfRhombus = map(float, input().split())
# side = float(input())
# heightOfRhombus = float(input())
rhombus = Rhombus(side, heightOfRhombus)
# Rectangle
length, breadth = map(float, input().split())
# length = float(input())
# breadth = float(input())
rectangle = Rectangle(length, breadth)
# Square
sideOfSquare = float(input())
square = Square(sideOfSquare)
if(side1 < 0 or side2 < 0 or heightOfRhombus < 0 or height < 0 or side < 0 or length < 0 or breadth < 0 or sideOfSquare < 0):
print("Length of a side cannot be negative. Please Enter a positive integer")
return
print("Perimeter of Parallelogram is",
parallelogram.getPerimeter(), "and Area of Parallelogram is", parallelogram.getArea())
print("Perimeter of Rhombus is",
rhombus.getPerimeter(), "and Area of Rhombus is", rhombus.getArea())
print("Perimeter of Rectangle is",
rectangle.getPerimeter(), "and Area of Rectangle is", rectangle.getArea())
print("Perimeter of Square is",
square.getPerimeter(), "and Area of Square is", square.getArea())
if __name__ == "__main__":
main()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the Main class. Implement the getArea() and getPerimeter() methods for the child classes Parallelogram, Rhombus, Rectangle, and Square having Abstract class Quadrilateral as a parent class.
Do not change the name of any classThe first line of input contains side1, side2 and height of the parallelogram
The second line of input contains side and height of rhombus
The third line of input contains length and height of the rectangle
The fourth line of input contains side of square
If the length of any side or height for any shape is negative, then print <b><i>Length of a side cannot be negative. Please Enter a positive integer.</b></i>"Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea()
"Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea()
"Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea()
"Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea()
Sample Input 1:
1.0 2.0 3.0
7.0 5.0
4.0 2.0
6.0
Sample Output 2:
Perimeter of Parallelogram is 6.0 and Area of Parallelogram is 3.0
Perimeter of Rhombus is 28.0 and Area of Rhombus is 35.0
Perimeter of Rectangle is 12.0 and Area of Rectangle is 8.0
Perimeter of Square is 24.0 and Area of Square is 36.0
Sample Input 2:
3.0 9.0 7.0
6.0 4.0
-1.0 5.0
8.0
Sample Output 2:
Length of a side cannot be negative. Please Enter a positive integer
, I have written this Solution Code: //Do not change the name of the class
import java.util.*;
// Do not edit the Quadrilateral class
abstract class Quadrilateral {
double side1;
double side2;
double side3;
double side4;
public Quadrilateral(double side1, double side2, double side3, double side4) {
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
this.side4 = side4;
}
protected abstract double getArea();
protected double getPerimeter() {
return (side1+side2+side3+side4);
}
}
class Parallelogram extends Quadrilateral {
double heightPerpendicularToSide1;
public Parallelogram(double side1, double side2, double height) {
super(side1, side2, side1, side2);
this.heightPerpendicularToSide1 = height;
}
public double getArea() {
return side1*heightPerpendicularToSide1;
}
}
class Rhombus extends Parallelogram {
public Rhombus(double side, double height) {
super(side, side, height);
}
}
class Rectangle extends Parallelogram {
public Rectangle(double length, double breadth) {
super(length, breadth, breadth);
}
}
class Square extends Rhombus {
public Square(double side) {
super(side, side);
}
}
// Do not edit the Main class
class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//Parallelogram
double side1 = scan.nextDouble();
double side2 = scan.nextDouble();
double height = scan.nextDouble();
Parallelogram parallelogram = new Parallelogram(side1, side2, height);
//Rhombus
double side = scan.nextDouble();
double heightOfRhombus = scan.nextDouble();
Rhombus rhombus = new Rhombus(side, heightOfRhombus);
//Rectangle
double length = scan.nextDouble();
double breadth = scan.nextDouble();
Rectangle rectangle = new Rectangle(length, breadth);
//Square
double sideOfSquare = scan.nextDouble();
Square square = new Square(sideOfSquare);
if(side1<0 || side2<0 || heightOfRhombus<0 || height<0 || side<0 || length<0 || breadth<0 || sideOfSquare<0){
System.out.println("Length of a side cannot be negative. Please Enter a positive integer");
return;
}
System.out.println("Perimeter of Parallelogram is " + parallelogram.getPerimeter() +" and Area of Parallelogram is " + parallelogram.getArea());
System.out.println("Perimeter of Rhombus is " + rhombus.getPerimeter() +" and Area of Rhombus is " + rhombus.getArea());
System.out.println("Perimeter of Rectangle is " + rectangle.getPerimeter() +" and Area of Rectangle is " + rectangle.getArea());
System.out.println("Perimeter of Square is " + square.getPerimeter()+ " and Area of Square is " + square.getArea());
scan.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException
{
InputStreamReader pk = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(pk);
String[] strNums;
int num[] = new int[4];
strNums = in.readLine().split(" ");
for (int i = 0; i < strNums.length; i++) {
num[i] = Integer.parseInt(strNums[i]);
}
if((num[0]<(num[1]+num[2])) || (num[0]<(num[1]*num[3])))
System.out.println("1");
else
System.out.println("0");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: a = []
a = list(map(int, input().split()))
if a[1]+a[2] > a[0] or a[1]*a[3] > a[0]:
defeat = 1
else:
defeat = 0
print(defeat), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <sys/resource.h>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout);
#define out(x) cout << ((x) ? "Yes\n" : "No\n")
#define sz(x) x.size()
#define start_clock() auto start_time = std::chrono::high_resolution_clock::now();
#define measure() auto end_time = std::chrono::high_resolution_clock::now(); cerr << (end_time - start_time)/std::chrono::milliseconds(1) << "ms" << endl;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifdef LOCALY
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
// DEBUG FUNCTIONS END
// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // FOR RANDOM NUMBER GENERATION
ll mod_exp(ll a, ll b, ll c)
{
ll res=1; a=a%c;
while(b>0)
{
if(b%2==1)
res=(res*a)%c;
b/=2;
a=(a*a)%c;
}
return res;
}
ll mymod(ll a,ll b)
{
return (((a = a%b) < 0) ? a + b : a);
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
g++; //this line was added just to remove compiler warning
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct Graph
{
vector<vector<int>> adj;
Graph(int n)
{
adj.resize(n+1);
}
void add_edge(int a, int b, bool directed = false)
{
adj[a].pb(b);
if(!directed) adj[b].pb(a);
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll M, Y, R, G;
cin >> M >> Y >> R >> G;
ll maxm = Y;
maxm = max(maxm, Y+R);
maxm = max(maxm, Y*G);
cout << (M < maxm) << "\n";
return 0;
}
/*
1. Check borderline constraints. Can a variable you are dividing by be 0?
2. Use ll while using bitshifts
3. Do not erase from set while iterating it
4. Initialise everything
5. Read the task carefully, is something unique, sorted, adjacent, guaranteed??
6. DO NOT use if(!mp[x]) if you want to iterate the map later
7. Are you using i in all loops? Are the i's conflicting?
*/
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long x;
BigInteger sum = new BigInteger("0");
for(int i=0;i<n;i++){
x=sc.nextLong();
sum= sum.add(BigInteger.valueOf(x));
}
sum=sum.divide(BigInteger.valueOf(n));
System.out.print(sum);
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, 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, cur = 0, rem = 0;
cin >> n;
for(int i = 1; i <= n; i++){
int p; cin >> p;
cur += (p + rem)/n;
rem = (p + rem)%n;
}
cout << cur;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, I have written this Solution Code: n = int(input())
a =list
a=list(map(int,input().split()))
sum=0
for i in range (0,n):
sum=sum+a[i]
print(int(sum//n))
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We define "EVEN" array as an array whose sum of elements is even. Similarly, we define "ODD" array as an array whose sum of elements is odd. Given an array A of N integers, find whether the given array is ODD or EVEN.The first line of the input contains a single integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print "EVEN" if the given array is an even array, else print "ODD", without the quotes.Sample Input:
5
4 6 3 7 2
Sample Output:
EVEN, 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 arr[] = new int[N];
for(int i=0; i<N; i++){
arr[i]= sc.nextInt();
}
int sum =0;
for(int i=0; i<N; i++){
sum+=arr[i];
}
if(sum%2 == 0){
System.out.println("EVEN");
}else{
System.out.println("ODD");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We define "EVEN" array as an array whose sum of elements is even. Similarly, we define "ODD" array as an array whose sum of elements is odd. Given an array A of N integers, find whether the given array is ODD or EVEN.The first line of the input contains a single integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print "EVEN" if the given array is an even array, else print "ODD", without the quotes.Sample Input:
5
4 6 3 7 2
Sample Output:
EVEN, I have written this Solution Code: n = int(input())
temp = input().split(' ')
nums = []
for i in range(0,n):
nums.append(int(temp[i]))
sums = 0
for i in nums:
sums+=i
if sums%2==0:
print("EVEN")
else:
print("ODD"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We define "EVEN" array as an array whose sum of elements is even. Similarly, we define "ODD" array as an array whose sum of elements is odd. Given an array A of N integers, find whether the given array is ODD or EVEN.The first line of the input contains a single integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print "EVEN" if the given array is an even array, else print "ODD", without the quotes.Sample Input:
5
4 6 3 7 2
Sample Output:
EVEN, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin >> n;
vector<int> a(n);
for(auto &i : a) cin >> i;
int sum = 0;
for(int i = 0; i < n; i++){
sum += a[i];
}
cout << (sum % 2 ? "ODD" : "EVEN");
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and an integer K, Your task is to multiply the first leftmost digit of the number to the number itself. You have to repeat this process K times.
For eg:- if N=3 and K=5 then:
3 * 3 = 9
9 * 9 = 81
81 * 8 = 648
648 * 6 = 3888
3888 * 3 = 11664<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>KOperations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 100
1 <= K <= 10^9Return the Number after K operations
<b>Note:</b> It is guaranteed that the output will always be less than 10^17.Sample Input:-
3 5
Sample Output:-
11664
Explanation:- See problem statement for explanation.
Sample Input:-
22 2
Sample Output:-
176, I have written this Solution Code:
long long KOperations(long long N, long long K){
long long p;
while(K--){
p=N;
while(p>=10){
p=p/10;
}
if(p==1){return N;}
N*=p;
}
return N;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and an integer K, Your task is to multiply the first leftmost digit of the number to the number itself. You have to repeat this process K times.
For eg:- if N=3 and K=5 then:
3 * 3 = 9
9 * 9 = 81
81 * 8 = 648
648 * 6 = 3888
3888 * 3 = 11664<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>KOperations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 100
1 <= K <= 10^9Return the Number after K operations
<b>Note:</b> It is guaranteed that the output will always be less than 10^17.Sample Input:-
3 5
Sample Output:-
11664
Explanation:- See problem statement for explanation.
Sample Input:-
22 2
Sample Output:-
176, I have written this Solution Code:
long long int KOperations(long long N, long long K){
long long int p;
while(K--){
p=N;
while(p>=10){
p=p/10;
}
if(p==1){return N;}
N*=p;
}
return N;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and an integer K, Your task is to multiply the first leftmost digit of the number to the number itself. You have to repeat this process K times.
For eg:- if N=3 and K=5 then:
3 * 3 = 9
9 * 9 = 81
81 * 8 = 648
648 * 6 = 3888
3888 * 3 = 11664<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>KOperations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 100
1 <= K <= 10^9Return the Number after K operations
<b>Note:</b> It is guaranteed that the output will always be less than 10^17.Sample Input:-
3 5
Sample Output:-
11664
Explanation:- See problem statement for explanation.
Sample Input:-
22 2
Sample Output:-
176, I have written this Solution Code: public static long KOperations(long N, long K){
long p=N;
while(K-->0){
p=N;
while(p>=10){
p=p/10;
}
if(p==1){return N;}
N=N*p;
}
return N;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and an integer K, Your task is to multiply the first leftmost digit of the number to the number itself. You have to repeat this process K times.
For eg:- if N=3 and K=5 then:
3 * 3 = 9
9 * 9 = 81
81 * 8 = 648
648 * 6 = 3888
3888 * 3 = 11664<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>KOperations()</b> that takes the integer N as parameter.
<b>Constraints:</b>
1 <= N <= 100
1 <= K <= 10^9Return the Number after K operations
<b>Note:</b> It is guaranteed that the output will always be less than 10^17.Sample Input:-
3 5
Sample Output:-
11664
Explanation:- See problem statement for explanation.
Sample Input:-
22 2
Sample Output:-
176, I have written this Solution Code:
def KOperations(N,K) :
# Final result of summation of divisors
while K>0 :
p=N
while(p>=10):
p=p/10
if(int(p)==1):
return N;
N=N*int(p)
K=K-1
return N;
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine().toString();
int n=Integer.parseInt(s);
int ch=0;
if(n>0){
ch=1;
}
else if(n<0) ch=-1;
switch(ch){
case 1: System.out.println("Positive");break;
case 0: System.out.println("Zero");break;
case -1: System.out.println("Negative");break;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: n = input()
if '-' in list(n):
print('Negative')
elif int(n) == 0 :
print('Zero')
else:
print('Positive'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: #include <stdio.h>
int main()
{
int num;
scanf("%d", &num);
switch (num > 0)
{
// Num is positive
case 1:
printf("Positive");
break;
// Num is either negative or zero
case 0:
switch (num < 0)
{
case 1:
printf("Negative");
break;
case 0:
printf("Zero");
break;
}
break;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rohit loves vowels and he likes a string if it contains all the vowels atleast once.
You are given a String S of length N integers. Find minimum length substring of S which contains all vowels atleast once (it may contain other characters too).The first line contains string length and the second line contains the string.
Constraints
1 <= N <= 100000
String contains lowercase english alphabetsThe output should contain only one integer which is the length of minimum length substring containing all vowels. If no such substring exists print -1.Sample input 1:
7
aeiddou
Sample output 1:
7
Sample input 2:
7
daeioud
Sample output 2:
5
Sample input 3:
7
daeiodd
Sample output 3:
-1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static int nextI(String str,int i)
{
char c=str.charAt(i);
return 0;
}
public static boolean vowel(char c)
{
if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u') return true;
else return false;
}
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();
if(n<5)
{
System.out.print(-1);
return;
}
int i=0;
while(i<n && !vowel(str.charAt(i))) ++i;
if(i==n)
{
System.out.print(-1);
return;
}
int min,max;
int len=n;
boolean found=false;
int index,l;
while(i<n)
{
max=-1;
min=n;
if(str.charAt(i)!='a')
{
index=str.indexOf('a',i+1);
if(index==-1) break;
if(index>max) max=index;
if(index<min) min=index;
}
if(str.charAt(i)!='e')
{
index=str.indexOf('e',i+1);
if(index==-1) break;
if(index>max) max=index;
if(index<min) min=index;
}
if(str.charAt(i)!='i')
{
index=str.indexOf('i',i+1);
if(index==-1) break;
if(index>max) max=index;
if(index<min) min=index;
}
if(str.charAt(i)!='o')
{
index=str.indexOf('o',i+1);
if(index==-1) break;
if(index>max) max=index;
if(index<min) min=index;
}
if(str.charAt(i)!='u')
{
index=str.indexOf('u',i+1);
if(index==-1) break;
if(index>max) max=index;
if(index<min) min=index;
}
l=max-i+1;
found=true;
if(l<len) len=l;
index=str.indexOf(str.charAt(i),i+1);
if(index==-1) break;
if(index<min) min=index;
i=min;
}
System.out.print((found)?len:-1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rohit loves vowels and he likes a string if it contains all the vowels atleast once.
You are given a String S of length N integers. Find minimum length substring of S which contains all vowels atleast once (it may contain other characters too).The first line contains string length and the second line contains the string.
Constraints
1 <= N <= 100000
String contains lowercase english alphabetsThe output should contain only one integer which is the length of minimum length substring containing all vowels. If no such substring exists print -1.Sample input 1:
7
aeiddou
Sample output 1:
7
Sample input 2:
7
daeioud
Sample output 2:
5
Sample input 3:
7
daeiodd
Sample output 3:
-1, I have written this Solution Code: t=input()
t=int(t)
x=input()
x=x[::-1]
start=0
a=0
e=0
i=0
o=0
u=0
l=[]
n=len(x)
j=0
value=100000
while(j<n):
if(x[j]=='a'):
a+=1
l.append(x[j])
elif x[j]=='e':
e+=1
l.append(x[j])
elif x[j]=='i':
i+=1
l.append(x[j])
elif x[j]=='o':
o+=1
l.append(x[j])
elif x[j]=='u':
u+=1
l.append(x[j])
while(a>=1 and e>=1 and i>=1 and o>=1 and u>=1):
if(value>(j-start+1)):
value=j-start+1
if(x[start]=='a'):
a-=1
elif(x[start]=='e'):
e-=1
elif(x[start]=='i'):
i-=1
elif(x[start]=='o'):
o-=1
elif(x[start]=='u'):
u-=1
if(l):
l.pop(0)
start=start+1
j+=1
if(value==100000):
print("-1")
else:
print (value), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rohit loves vowels and he likes a string if it contains all the vowels atleast once.
You are given a String S of length N integers. Find minimum length substring of S which contains all vowels atleast once (it may contain other characters too).The first line contains string length and the second line contains the string.
Constraints
1 <= N <= 100000
String contains lowercase english alphabetsThe output should contain only one integer which is the length of minimum length substring containing all vowels. If no such substring exists print -1.Sample input 1:
7
aeiddou
Sample output 1:
7
Sample input 2:
7
daeioud
Sample output 2:
5
Sample input 3:
7
daeiodd
Sample output 3:
-1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
t=1;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
map<char,int> m;
m['a']=0;
m['e']=0;
m['i']=0;
m['o']=0;
m['u']=0;
int cnt=0, ans=INT_MAX,j=0;
for(int i=0;i<n;i++){
if(m.find(s[i])!=m.end()){
if(m[s[i]]==0){cnt++;}
m[s[i]]++;
}
if(cnt==5){
ans=min(ans,i-j+1);
while(1){
if(m.find(s[j])!=m.end()){m[s[j]]--;
if(m[s[j]]==0){j++;
break;}
}
j++;
ans=min(ans,i-j+1);
}
cnt--;
}
}
if(ans==INT_MAX){cout<<-1;return 0;}
cout<<ans<<endl;}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N, with all values as non-negative integers. Bodega asked you whether it is possible to partition the array into exactly K non-empty subarrays such that the sum of values of each subarray is equal. If it is possible print "Yes", otherwise print "No".
Note:
Every element of the array should belong to exactly one subarray in the partition.The first line consists of two space-separated integers N and K respectively.
The second line consists of N space-separated integers β A<sub>1</sub>, A<sub>2</sub>, ... A<sub>N</sub>.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 20
0 ≤ A<sub>i</sub> ≤ 10<sup>6</sup>
There exists at least one non-zero element in array A.Print a single word "Yes" if the array can be partitioned into K equal sum parts, otherwise print "No".
Note:
The quotation marks are only for clarity, you should not print them in output.
The output is case-sensitive.Sample Input 1:
5 2
2 2 1 2 2
Sample Output 1:
No
Sample Input 2:
10 3
3 0 1 2 0 0 6 0 1 5
Sample Output 2:
Yes
Explanation:
The array can be partitioned as {3, 0, 1, 2, 0, 0}, {6}, {0, 1, 5}., I have written this Solution Code: import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve(int TC) {
int n = ni(), k = ni();
long sum = 0L, tempSum = 0;
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
sum += a[i];
}
if (sum % k != 0) {
pn("No");
return;
}
long req = sum / (long) k;
for (int i : a) {
tempSum += i;
if (tempSum == req) {
tempSum = 0;
} else if (tempSum > req) {
pn("No");
return;
}
}
pn(tempSum == 0 ? "Yes" : "No");
}
boolean TestCases = false;
public static void main(String[] args) throws Exception {
new Main().run();
}
void hold(boolean b) throws Exception {
if (!b) throw new Exception("Hold right there, Sparky!");
}
static void dbg(Object... o) {
System.err.println(Arrays.deepToString(o));
}
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
int T = TestCases ? ni() : 1;
for (int t = 1; t <= T; t++) solve(t);
out.flush();
if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");
}
void p(Object o) {
out.print(o);
}
void pn(Object o) {
out.println(o);
}
void pni(Object o) {
out.println(o);
out.flush();
}
int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
double nd() {
return Double.parseDouble(ns());
}
char nc() {
return (char) skip();
}
int BUF_SIZE = 1024 * 8;
byte[] inbuf = new byte[BUF_SIZE];
int lenbuf = 0, ptrbuf = 0;
int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
void tr(Object... o) {
if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N, with all values as non-negative integers. Bodega asked you whether it is possible to partition the array into exactly K non-empty subarrays such that the sum of values of each subarray is equal. If it is possible print "Yes", otherwise print "No".
Note:
Every element of the array should belong to exactly one subarray in the partition.The first line consists of two space-separated integers N and K respectively.
The second line consists of N space-separated integers β A<sub>1</sub>, A<sub>2</sub>, ... A<sub>N</sub>.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 20
0 ≤ A<sub>i</sub> ≤ 10<sup>6</sup>
There exists at least one non-zero element in array A.Print a single word "Yes" if the array can be partitioned into K equal sum parts, otherwise print "No".
Note:
The quotation marks are only for clarity, you should not print them in output.
The output is case-sensitive.Sample Input 1:
5 2
2 2 1 2 2
Sample Output 1:
No
Sample Input 2:
10 3
3 0 1 2 0 0 6 0 1 5
Sample Output 2:
Yes
Explanation:
The array can be partitioned as {3, 0, 1, 2, 0, 0}, {6}, {0, 1, 5}., I have written this Solution Code:
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
long long powm(long long a, long long b,long long mod) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a %mod;
a = a * a %mod;
b >>= 1;
}
return res;
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
if(fopen("input.txt","r"))
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
#endif
int n,k;
cin>>n>>k;
int a[n];
int sum=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
if(sum%k)
cout<<"No";
else
{
int tot=0;
int cur=0;
sum/=k;
for(int i=0;i<n;i++)
{
cur+=a[i];
if(cur==sum)
{
tot++;
cur=0;
}
}
if(cur==0 && tot==k)
cout<<"Yes";
else
cout<<"No";
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N, with all values as non-negative integers. Bodega asked you whether it is possible to partition the array into exactly K non-empty subarrays such that the sum of values of each subarray is equal. If it is possible print "Yes", otherwise print "No".
Note:
Every element of the array should belong to exactly one subarray in the partition.The first line consists of two space-separated integers N and K respectively.
The second line consists of N space-separated integers β A<sub>1</sub>, A<sub>2</sub>, ... A<sub>N</sub>.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 20
0 ≤ A<sub>i</sub> ≤ 10<sup>6</sup>
There exists at least one non-zero element in array A.Print a single word "Yes" if the array can be partitioned into K equal sum parts, otherwise print "No".
Note:
The quotation marks are only for clarity, you should not print them in output.
The output is case-sensitive.Sample Input 1:
5 2
2 2 1 2 2
Sample Output 1:
No
Sample Input 2:
10 3
3 0 1 2 0 0 6 0 1 5
Sample Output 2:
Yes
Explanation:
The array can be partitioned as {3, 0, 1, 2, 0, 0}, {6}, {0, 1, 5}., I have written this Solution Code: N,K=map(int,input().split())
S=0
a=input().split()
for i in a:
S+=int(i)
if S%K!=0:
print('No')
else:
su=0
count=0
asd=S/K
for i in range(N):
su+=int(a[i])
if su==asd:
count+=1
su=0
if count==K:
print('Yes')
else:
print('No'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Your task is to implement a stack using an array and perform given queries
<b>Note</b>: Description of each query is given in the <b>input and output format</b>User task:
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 integer to be added and the maximum size of the array as a parameter.
<b>pop()</b>:- that takes no parameter.
<b>top()</b> :- that takes no parameter.
Constraints:
1 <= N(number of queries) <= 10<sup>3</sup>During a <b>pop</b> operation if the stack is empty you need to print "<b>Stack underflow</b>",
during <b>push</b> operation, if the maximum size of the array is reached you need to print "<b>Stack overflow</b>", <br> during <b>top</b> operation, you need to print the element which is at the top
if the stack is empty you need to print "<b>Empty stack</b>".
<b>Note</b>:- Each message or element is to be printed on a new line
Sample Input:-
6 3
pop
push 3
push 2
push 4
push 6
top
Sample Output:-
Stack underflow
Stack overflow
4
Explanation:-
Here maximum size of the array is 3, so element 6 can not be added to stack
Sample input:-
8 4
push 2
top
push 4
top
push 6
top
push 8
top
Sample Output:-
2
4
6
8
, I have written this Solution Code: void push(int x,int k)
{
if (top >= k-1) {
System.out.println("Stack overflow");
}
else {
a[++top] = x;
}
}
void pop()
{
if (top < 0) {
System.out.println("Stack underflow");
}
else {
int x = a[top--];
}
}
void top()
{
if (top < 0) {
System.out.println("Empty stack");
}
else {
int x = a[top];
System.out.println(x);
}
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) {
FastReader sc= new FastReader();
String str= sc.nextLine();
String a="Apple";
if(a.equals(str)){
System.out.println("Gravity");
}
else{
System.out.println("Space");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
//-----------------------------------------------------------------------------------------------------------//
string S;
cin>>S;
if(S=="Apple")
{
cout<<"Gravity"<<endl;
}
else
{
cout<<"Space"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: n=input()
if n=='Apple':print('Gravity')
else:print('Space'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. You need to print the squares of all numbers from 1 to N in different lines.The only input line contains an integer N.
Constraints:
1 <= N <= 1000Print N lines where the ith line (1-based indexing) contains an integer i<sup>2</sup>.Sample Input 1:
4
Output:
1
4
9
16
Explanation:
1*1 = 1
2*2 = 4
3*3 = 9
4*4 = 16
Sample Input 2:
2
Output:
1
4
Explanation:
1*1 = 1
2*2 = 4, I have written this Solution Code: n=int(input())
for i in range(1,n+1):
print(i**2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. You need to print the squares of all numbers from 1 to N in different lines.The only input line contains an integer N.
Constraints:
1 <= N <= 1000Print N lines where the ith line (1-based indexing) contains an integer i<sup>2</sup>.Sample Input 1:
4
Output:
1
4
9
16
Explanation:
1*1 = 1
2*2 = 4
3*3 = 9
4*4 = 16
Sample Input 2:
2
Output:
1
4
Explanation:
1*1 = 1
2*2 = 4, I have written this Solution Code: import java.io.*;
import java.util.Scanner;
class Main {
public static void main (String[] args) {
int n;
Scanner s = new Scanner(System.in);
n = s.nextInt();
for(int i=1;i<=n;i++){
System.out.println(i*i);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 β€ A, B β€ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
String s[]=bu.readLine().split(" ");
int a=Integer.parseInt(s[0]),b=Integer.parseInt(s[1]);
int ans=2;
if(a==b) ans=0;
else if(a%b==0 || b%a==0 || a+1==b || b+1==a) ans=1;
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 β€ A, B β€ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: l=list(map(int, input().split()))
A=l[0]
B=l[1]
if A==B:
print(0)
elif A%B==0 or B%A==0 or abs(A-B)==1:
print(1)
else:
print(2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 β€ A, B β€ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a == b) cout << 0;
else if (abs(a - b) == 1) cout << 1;
else if (a % b == 0 || b % a == 0) cout << 1;
else cout << 2;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: static void pattern(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j + " ");
}
System.out.println();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: function pattern(n) {
// write code herenum
for(let i = 1;i<=n;i++){
let str = ''
for(let k = 1; k <= i;k++){
if(k === 1) {
str += `${k}`
}else{
str += ` ${k}`
}
}
console.log(str)
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: def patternPrinting(n):
for i in range(1,n+1):
for j in range (1,i+1):
print(j,end=' ')
print()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(Β°c) = (T(Β°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(Β°c) = (T(Β°f) - 32)*5/9
T(Β°c) = (77-32)*5/9
T(Β°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){
n-=32;
n/=9;
n*=5;
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(Β°c) = (T(Β°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(Β°c) = (T(Β°f) - 32)*5/9
T(Β°c) = (77-32)*5/9
T(Β°c) =25, I have written this Solution Code: Fahrenheit= int(input())
Celsius = int(((Fahrenheit-32)*5)/9 )
print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(Β°c) = (T(Β°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(Β°c) = (T(Β°f) - 32)*5/9
T(Β°c) = (77-32)*5/9
T(Β°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit)
{
int celsius = ((farhrenheit-32)*5)/9;
System.out.println(celsius);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: def getMissingNo(arr, n):
total = (n+1)*(n)//2
sum_of_A = sum(arr)
return total - sum_of_A
N = int(input())
arr = list(map(int,input().split()))
one = getMissingNo(arr,N)
print(one), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n-1];
for(int i=0;i<n-1;i++){
a[i]=sc.nextInt();
}
boolean present = false;
for(int i=1;i<=n;i++){
present=false;
for(int j=0;j<n-1;j++){
if(a[j]==i){present=true;}
}
if(present==false){
System.out.print(i);
return;
}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++){
cin>>a[i];
}
sort(a,a+n-1);
for(int i=1;i<n;i++){
if(i!=a[i-1]){cout<<i<<endl;return 0;}
}
cout<<n;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code:
import java.io.*;
import java.util.*;
class Main {
public static boolean isArrangementPossible(long arr[],int n,long sum){
if(n==1){
if(arr[0]==sum)
return true;
else
return false;
}
return(isArrangementPossible(arr,n-1,sum-arr[n-1]) || isArrangementPossible(arr,n-1,sum+arr[n-1]));
}
public static void main (String[] args) throws IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String str1[]=br.readLine().trim().split(" ");
int n=Integer.parseInt(str1[0]);
long sum=Long.parseLong(str1[1]);
String str[]=br.readLine().trim().split(" ");
long arr[]=new long[n];
for(int i=0;i<n;i++){
arr[i]=Long.parseLong(str[i]);
}
if(isArrangementPossible(arr,n,sum)){
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: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code: def checkIfGivenTargetIsPossible(nums,currSum,i,targetSum):
if i == len(nums):
if currSum == targetSum:
return 1
return 0
if(checkIfGivenTargetIsPossible(nums,currSum + nums[i],i+1,targetSum)):
return 1
return checkIfGivenTargetIsPossible(nums,currSum - nums[i], i+1,targetSum)
n,k = map(int,input().split())
nums = list(map(int,input().split()))
if(checkIfGivenTargetIsPossible(nums,0,0,k)):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code: #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define int long long
int k;
using namespace std;
int solve(int n, int a[], int i, int curr ){
if(i==n){
if(curr==k){return 1;}
return 0;
}
if(solve(n,a,i+1,curr+a[i])==1){return 1;}
return solve(n,a,i+1,curr-a[i]);
}
signed main() {
int n;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
if(solve(n,a,1,a[0])){
cout<<"YES";}
else{
cout<<"NO";}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Being told that an unsorted array contains (n - 1) of n consecutive numbers (where the bounds are defined), find the missing number in O(n) time.
The bounds tell that all the numbers between the lower bound and the upper bound are present in the array except one number which is missing. You have to find that missing number.The function takes three arguments , the first argument is the array of integers, the second argument is the upper bound and the third argument is the lower bound.
All the numbers between the lower and the upper bounds are present in the array (inclusive of both upper and lower bound) except one number which is missing.
Input is provided in the form of an array which would have 3 elements. The first element is the array of integers, the second element is the upper bound and the third element is the lower bound. All three elements are used internally to call the function.
Example: [[1, 4, 3] ,4, 1]
Here, [1,4,3] is the array of integers
4 is the upper bound
1 is the lower boundThe function should print the missing number in the console.const input = [[1, 4, 3] ,4, 1];
const arr = input[0];
const upper_bound = input[1];
const lower_bound = input[2];
findMissingNumber(arr, upper_bound, lower_bound); //prints 2
// Explanation: From numbers 1 to 4, only 2 is missing from the array, I have written this Solution Code:
function findMissingNumber(arrayOfIntegers, upperBound, lowerBound) {
// Iterate through array to find the sum of the numbers
let sumOfIntegers = 0;
for (let i = 0; i < arrayOfIntegers.length; i++) {
sumOfIntegers += arrayOfIntegers[i];
}
// Find theoretical sum of the consecutive numbers using a variation of Gauss Sum.
// Formula: [(N * (N + 1)) / 2] - [(M * (M - 1)) / 2];
// N is the upper bound and M is the lower bound
upperLimitSum = (upperBound * (upperBound + 1)) / 2;
lowerLimitSum = (lowerBound * (lowerBound - 1)) / 2;
theoreticalSum = upperLimitSum - lowerLimitSum;
console.log(theoreticalSum - sumOfIntegers);
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <i> Why Geometry?? ? </i>
You are given 4*N+1 distinct points on the cartesian plane. Out of these points, 4*N points represent the end points of N rectangles (<b>with axis parallel to co-ordinate axis</b>), while one point does not belong to any of the rectangles. Report the coordinates of the point that does not belong to any of the N rectangles.The first line of the input contains an integer N.
The next 4*N+1 lines contain two integers X and Y, the coordinates of the given points.
Constraints
1 <= N <= 100000
0 <= X, Y <= 1000000
The given points always represent N rectangles and an extra pointOutput space separated X and Y coordinates of the extra point.Samle Input
1
1 3
1 1
3 1
1 4
3 3
Sample Output
1 4
Explanation: (1, 1), (1, 3), (3, 1), and (3, 3) represent the end of a rectangle, while (1, 4) is the extra point., I have written this Solution Code: n=int(input())
x,y=0,0
for i in range(4*n+1):
a1,b1=map(int,input().split())
x=x^a1
y=y^b1
print(x,y), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <i> Why Geometry?? ? </i>
You are given 4*N+1 distinct points on the cartesian plane. Out of these points, 4*N points represent the end points of N rectangles (<b>with axis parallel to co-ordinate axis</b>), while one point does not belong to any of the rectangles. Report the coordinates of the point that does not belong to any of the N rectangles.The first line of the input contains an integer N.
The next 4*N+1 lines contain two integers X and Y, the coordinates of the given points.
Constraints
1 <= N <= 100000
0 <= X, Y <= 1000000
The given points always represent N rectangles and an extra pointOutput space separated X and Y coordinates of the extra point.Samle Input
1
1 3
1 1
3 1
1 4
3 3
Sample Output
1 4
Explanation: (1, 1), (1, 3), (3, 1), and (3, 3) represent the end of a rectangle, while (1, 4) is the extra point., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
n = n*4+1;
int x = 0;
int y = 0;
For(i, 0, n){
int a, b; cin>>a>>b;
x^=a;
y^=b;
}
cout<<x<<" "<<y<<"\n";
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <i> Why Geometry?? ? </i>
You are given 4*N+1 distinct points on the cartesian plane. Out of these points, 4*N points represent the end points of N rectangles (<b>with axis parallel to co-ordinate axis</b>), while one point does not belong to any of the rectangles. Report the coordinates of the point that does not belong to any of the N rectangles.The first line of the input contains an integer N.
The next 4*N+1 lines contain two integers X and Y, the coordinates of the given points.
Constraints
1 <= N <= 100000
0 <= X, Y <= 1000000
The given points always represent N rectangles and an extra pointOutput space separated X and Y coordinates of the extra point.Samle Input
1
1 3
1 1
3 1
1 4
3 3
Sample Output
1 4
Explanation: (1, 1), (1, 3), (3, 1), and (3, 3) represent the end of a rectangle, while (1, 4) is the extra point., I have written this Solution Code: import java.io.*;
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static long mod = 1000000007 ;
public static double epsilon=0.00000000008854;
public static InputReader sc = new InputReader(System.in);
public static PrintWriter pw = new PrintWriter(System.out);
public static long pow(long x,long y,long mod){
long ans=1;
x%=mod;
while(y>0){
if((y&1)==1){
ans=(ans*x)%mod;
}
y=y>>1;
x=(x*x)%mod;
}
return ans;
}
public static void main(String[] args) throws Exception {
int n=sc.nextInt();
n=4*n+1;
int x=0,y=0;
for(int i=0;i<n;i++){
int a=sc.nextInt();
x^=a;
int b=sc.nextInt();
y^=b;
}
pw.println(x+" "+y);
pw.flush();
pw.close();
}
public static Comparator<Integer[]> MOquery(int block){
return
new Comparator<Integer[]>(){
@Override
public int compare(Integer a[],Integer b[]){
int a1=a[0]/block;
int b1=b[0]/block;
if(a1==b1){
if((a1&1)==1)
return a[1].compareTo(b[1]);
else{
return b[1].compareTo(a[1]);
}
}
return a1-b1;
}
};
}
public static Comparator<Long[]> column(int i){
return
new Comparator<Long[]>() {
@Override
public int compare(Long[] o1, Long[] o2) {
return o1[i].compareTo(o2[i]);
}
};
}
public static Comparator<Integer[]> column(){
return
new Comparator<Integer[]>() {
@Override
public int compare(Integer[] o1, Integer[] o2) {
long a1=o1[0];
long a2=o2[1];
long b1=o2[0];
long b2=o1[1];
int ans=0;
if(a1*a2>b1*b2){
ans=1;
}
else ans=-1;
return ans;
}
};
}
public static Comparator<Integer[]> col(int i){
return
new Comparator<Integer[]>() {
@Override
public int compare(Integer[] o1, Integer[] o2) {
if(o1[i]-o2[i]!=0)
return o1[i].compareTo(o2[i]);
return o1[i+1].compareTo(o2[i+1]);
}
};
}
public static Comparator<Integer> des(){
return
new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o2.compareTo(o1);
}
};
}
public static String reverseString(String s){
StringBuilder input1 = new StringBuilder();
input1.append(s);
input1 = input1.reverse();
return input1.toString();
}
public static int[] scanArray(int n){
int a[]=new int [n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
return a;
}
public static long[] scanLongArray(int n){
long a[]=new long [n];
for(int i=0;i<n;i++)
a[i]=sc.nextLong();
return a;
}
public static String [] scanStrings(int n){
String a[]=new String [n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
return a;
}
public static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int snext() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public String readString() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main (String[] args)throws IOException {
Reader sc = new Reader();
int N = sc.nextInt();
int[] arr = new int[N];
for(int i=0;i<N;i++){
arr[i] = sc.nextInt();
}
int max=0;
if(arr[0]<arr[N-1])
System.out.print(N-1);
else{
for(int i=0;i<N-1;i++){
int j = N-1;
while(j>i){
if(arr[i]<arr[j]){
if(max<j-i){
max = j-i;
} break;
}
j--;
}
if(i==j)
break;
if(j==N-1)
break;
}
if(max==0)
System.out.print("-1");
else
System.out.print(max);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
/* For a given array arr[],
returns the maximum j β i such that
arr[j] > arr[i] */
int maxIndexDiff(int arr[], int n)
{
int maxDiff;
int i, j;
int *LMin = new int[(sizeof(int) * n)];
int *RMax = new int[(sizeof(int) * n)];
/* Construct LMin[] such that
LMin[i] stores the minimum value
from (arr[0], arr[1], ... arr[i]) */
LMin[0] = arr[0];
for (i = 1; i < n; ++i)
LMin[i] = min(arr[i], LMin[i - 1]);
/* Construct RMax[] such that
RMax[j] stores the maximum value from
(arr[j], arr[j+1], ..arr[n-1]) */
RMax[n - 1] = arr[n - 1];
for (j = n - 2; j >= 0; --j)
RMax[j] = max(arr[j], RMax[j + 1]);
/* Traverse both arrays from left to right
to find optimum j - i. This process is similar to
merge() of MergeSort */
i = 0, j = 0, maxDiff = -1;
while (j < n && i < n)
{
if (LMin[i] < RMax[j])
{
maxDiff = max(maxDiff, j - i);
j = j + 1;
}
else
i = i + 1;
}
return maxDiff;
}
// Driver Code
signed main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int maxDiff = maxIndexDiff(a, n);
cout << maxDiff;
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 integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
rightMax = [0] * n
rightMax[n - 1] = arr[n - 1]
for i in range(n - 2, -1, -1):
rightMax[i] = max(rightMax[i + 1], arr[i])
maxDist = -2**31
i = 0
j = 0
while (i < n and j < n):
if (rightMax[j] >= arr[i]):
maxDist = max(maxDist, j - i)
j += 1
else:
i += 1
if maxDist==0:
maxDist=-1
print(maxDist), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code: function numberOfDays(n)
{
let ans;
switch(n)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
ans = Number(31);
break;
case 2:
ans = Number(28);
break;
default:
ans = Number(30);
break;
}
return ans;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code:
static void numberofdays(int M){
if(M==4 || M ==6 || M==9 || M==11){System.out.print(30);}
else if(M==2){System.out.print(28);}
else{
System.out.print(31);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the function <code>callThisFnBack</code>
Such that it takes a number as the first argument and a function (callback function) as the second argument. You have to pass the first argument of the function <code>callThisFnBack</code> to the callback function and execute the callback function inside the <code>callThisFnBack</code> and return its result.The function will take two arguments, one which is a number and the second which will be a function.Returns the result of the second argument which is the callback function when its argument is the first argument of the function <code>callThisFnBack</code>.const result = callThisFnBack(5, (num)=>{
return num+6
})
console.log(result) // prints 11 because 5+6
const newFn = (number) => {
return number - 5
}
const newResult = callThisFnBack(5,newFn)
console.log(newResult) // prints 0 because 5-5=0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int ans = 0;
char operate = sc.next().charAt(0);
switch(operate){
case '+':
ans = num + num;
break;
case '-' :
ans = num - num;
break;
case '*':
ans = num * num;
break;
case '/':
ans = num / num;
break;
}
System.out.print(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the function <code>callThisFnBack</code>
Such that it takes a number as the first argument and a function (callback function) as the second argument. You have to pass the first argument of the function <code>callThisFnBack</code> to the callback function and execute the callback function inside the <code>callThisFnBack</code> and return its result.The function will take two arguments, one which is a number and the second which will be a function.Returns the result of the second argument which is the callback function when its argument is the first argument of the function <code>callThisFnBack</code>.const result = callThisFnBack(5, (num)=>{
return num+6
})
console.log(result) // prints 11 because 5+6
const newFn = (number) => {
return number - 5
}
const newResult = callThisFnBack(5,newFn)
console.log(newResult) // prints 0 because 5-5=0, I have written this Solution Code: function callThisFnBack(number, fn) {
return fn(number)
// return the output using return keyword
// do not console.log it
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A pair is called lucky if its sum is even and positive. Given three numbers find if there exists a lucky pair or not.The only line contains three integers a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub>
<b>Constraints:</b>
-10<sup>9</sup> <= a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub> <= 10<sup>9</sup>Print "YES" without quotes if there exists a lucky pair otherwise print "NO" without quotes.Sample Input 1:
23 32 12
Sample Output 1:
YES
Sample Input 2:
1 -1 2
Sample Output 2:
NO, I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("popcnt")
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define fr first
#define sc second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout);
#define out(x) cout << ((x) ? "Yes\n" : "No\n")
#define sz(x) x.size()
typedef long long ll;
typedef long long unsigned int llu;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
void solve(){
vector<ll>a(3);
for(ll i = 0;i<3;i++)cin >> a[i];
for(ll i = 0;i<3;i++){
for(ll j = i+1;j<3;j++){
if((a[i]+a[j])>0 && (a[i]+a[j])%2 == 0){
cout << "YES\n";
return;
}
}
}
cout << "NO\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// cout.tie(NULL);
#ifdef LOCALFLAG
freopen("Input.txt", "r", stdin);
freopen("Output2.txt", "w", stdout);
#endif
ll t = 1;
//cin >> t;
while(t--){
solve();
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: It's Solo's 1st birthday and everyone is gifting her chocolates. There are N guests invited, and the i<sup>th</sup> guest gives Solo C<sub>i</sub> chocolates.
Find the total number of chocolates that Solo receives.The first line of the input contains an integer N, the number of guests.
The second line of the input contains N integers C<sub>1</sub>, C<sub>2</sub>, ....C<sub>N</sub>
Constraints
1 <= N <= 100
1 <= C<sub>i</sub> <= 100Output a single integer, the total number of chocolates that Solo receives.Sample Input
5
1 2 4 3 2
Sample Output
12
Explanation: Solo receives a total of 1+2+4+3+2 = 12 chocolates.
Sample Input
1
2
Sample Output
2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
int ans = 0;
For(i, 0, n){
int a; cin>>a;
ans += a;
}
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: It's Solo's 1st birthday and everyone is gifting her chocolates. There are N guests invited, and the i<sup>th</sup> guest gives Solo C<sub>i</sub> chocolates.
Find the total number of chocolates that Solo receives.The first line of the input contains an integer N, the number of guests.
The second line of the input contains N integers C<sub>1</sub>, C<sub>2</sub>, ....C<sub>N</sub>
Constraints
1 <= N <= 100
1 <= C<sub>i</sub> <= 100Output a single integer, the total number of chocolates that Solo receives.Sample Input
5
1 2 4 3 2
Sample Output
12
Explanation: Solo receives a total of 1+2+4+3+2 = 12 chocolates.
Sample Input
1
2
Sample Output
2, I have written this Solution Code: n = int(input())
chocolates = list(map(int, input().strip().split(" ")))
count = 0
for val in chocolates:
count += val
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: It's Solo's 1st birthday and everyone is gifting her chocolates. There are N guests invited, and the i<sup>th</sup> guest gives Solo C<sub>i</sub> chocolates.
Find the total number of chocolates that Solo receives.The first line of the input contains an integer N, the number of guests.
The second line of the input contains N integers C<sub>1</sub>, C<sub>2</sub>, ....C<sub>N</sub>
Constraints
1 <= N <= 100
1 <= C<sub>i</sub> <= 100Output a single integer, the total number of chocolates that Solo receives.Sample Input
5
1 2 4 3 2
Sample Output
12
Explanation: Solo receives a total of 1+2+4+3+2 = 12 chocolates.
Sample Input
1
2
Sample Output
2, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int A[] = new int[n];
for(int i=0;i<n;i++){
A[i]=sc.nextInt();
}
int Total=0;
for(int i=0;i<n;i++){
Total+=A[i];
}
System.out.print(Total);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character β*β draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, 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 M=sc.nextInt();
int N=sc.nextInt();
for(int col=0;col<N;col++){
System.out.print("*");
}
System.out.println();
for(int row=0;row<M-2;row++){
System.out.print("*");
for(int col=0;col<N-2;col++){
System.out.print(" ");
}
System.out.print("*");
System.out.println();
}
for(int col=0;col<N;col++){
System.out.print("*");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character β*β draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, I have written this Solution Code: li = list(map(int,input().strip().split()))
m=li[0]
n=li[1]
for i in range(0,n):
if i==n-1:
print("*",end="\n")
else:
print("*",end="")
for i in range(1,m-1):
print("*",end="")
for j in range(0,n-2):
print(" ",end="")
print("*",end="\n")
for i in range(0,n):
print("*",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character β*β draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int m,n;
cin>>m>>n;
for(int i=0;i<n;i++){
cout<<'*';
}
cout<<endl;
m-=2;
while(m--){
cout<<'*';
for(int i=0;i<n-2;i++){
cout<<' ';
}
cout<<'*'<<endl;
}
for(int i=0;i<n;i++){
cout<<'*';
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args){
FastReader read = new FastReader();
int a = read.nextInt();
int b = read.nextInt();
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(){
InputStreamReader inr = new InputStreamReader(System.in);
br = new BufferedReader(inr);
}
String next(){
while(st==null || !st.hasMoreElements())
try{
st = new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
long nextLong(){
return Long.parseLong(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split())
print(a+b)
print(a-b)
print(a*b)
print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: function PokemonMaster(a,b) {
// write code here
// do no console.log the answer
// return the output using return keyword
const ans = (a - b >= 0) ? 1 : 0
return ans
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: def PokemonMaster(A,B):
if(A>=B):
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: int PokemonMaster(int A, int B){
if(A>=B){return 1;}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: int PokemonMaster(int A, int B){
if(A>=B){return 1;}
return 0;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: static int PokemonMaster(int A, int B){
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 a number String S, Your task is to find the sum of the 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>Sum()</b> that takes the String S as a parameter.
Constraints:-
1 <= |S| <= 1000
Note:- String will contain only numbers from 0-9.Return the sum of the string.Sample Input:-
123
Sample Output:-
6
Sample Input:-
123456789
Sample Output:-
45, I have written this Solution Code: a=input()
b=0
for i in a:
b=b+int(i)
print(b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number String S, Your task is to find the sum of the 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>Sum()</b> that takes the String S as a parameter.
Constraints:-
1 <= |S| <= 1000
Note:- String will contain only numbers from 0-9.Return the sum of the string.Sample Input:-
123
Sample Output:-
6
Sample Input:-
123456789
Sample Output:-
45, 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);
String s = sc.next();
System.out.print(StringLength(s));
}
static int StringLength(String S){
int n = S.length();
int sum=0;
for(int i=0;i<n;i++){
sum+=(int)S.charAt(i)-(int)'0';
}
return sum;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number String S, Your task is to find the sum of the 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>Sum()</b> that takes the String S as a parameter.
Constraints:-
1 <= |S| <= 1000
Note:- String will contain only numbers from 0-9.Return the sum of the string.Sample Input:-
123
Sample Output:-
6
Sample Input:-
123456789
Sample Output:-
45, I have written this Solution Code: // str is input string
function Sum(str) {
// write code here
// do not console.log
// return the sum
return str.split('').map(Number).reduce((a,b)=>a+b,0)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: def compound_interest(principle, rate, time):
Amount = principle * (pow((1 + rate / 100), time))
CI = Amount - principle
print( '%.2f'%CI)
principle,rate,time=map(int, input().split())
compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: function calculateCI(P, R, T)
{
let interest = P * (Math.pow(1.0 + R/100.0, T) - 1);
return interest.toFixed(2);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int p,r,t;
cin>>p>>r>>t;
double rate= (float)r/100;
double amt = (float)p*(pow(1+rate,t));
cout << fixed << setprecision(2) << (amt - p);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s= br.readLine().split(" ");
double[] darr = new double[s.length];
for(int i=0;i<s.length;i++){
darr[i] = Double.parseDouble(s[i]);
}
double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0];
System.out.printf("%.2f",ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: static void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
System.out.print(x+4*j+" ");
}
System.out.println();
x+=6;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: def Pattern(N):
x=0
for i in range (0,N):
for j in range (0,N):
print(x+4*j,end=' ')
print()
x = x+6
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An N x N board contains only 0s and 1s. In each move, you can swap any 2 rows with each other, or any 2 columns with each other.
What is the minimum number of moves to transform the board into a "chessboard" - a board where no 0s and no 1s are 4-directionally adjacent? If the task is impossible, return -1.The input line contains T, denoting the number of test cases. Each test case contains two lines. First-line contains N, size of the matrix. Second-line contains N*N elements of binary matrix.
<b>Constraints:</b>
1 <= T <= 100
2 <= N <= 50
0 <= mat[i][j] <= 1For each testcase you need to print the minimum number of swaps required.Input:
2
4
0 1 1 0
0 1 1 0
1 0 0 1
1 0 0 1
3
0 1 0
1 0 1
1 1 0
Output:
2
-1
Explanation:
One potential sequence of moves is shown below, from left to right:
0110 1010 1010
0110 --> 1010 --> 0101
1001 0101 1010
1001 0101 0101
The first move swaps the first and second columns.
The second move swaps the second and third row., 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 K = Integer.parseInt(str[1]);
//`int D = Integer.parseInt(str[1]);
int arr[][] = new int[N][N];
for(int i = 0; i < N; i++)
{
str = read.readLine().trim().split(" ");
for(int j = 0; j < N; j++)
arr[i][j] = Integer.parseInt(str[j]);
}
//int res[] = moveZeroes(arr);
//print(res);
System.out.println(movesToChessboard(arr));
}
}
static void print(int list[])
{
for(int i = 0; i < list.length; i++)
System.out.print(list[i] + " ");
}
public static int movesToChessboard(int[][] board) {
if (board == null || board.length == 0 || board[0].length == 0) {
return -1;
}
int N = board.length;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if ((board[0][0] ^ board[i][0] ^ board[0][j] ^ board[i][j]) == 1) {
return -1;
}
}
}
int rowSum = 0;
int colSum = 0;
int rowSwap = 0;
int colSwap = 0;
for (int i = 0; i < N; ++i) {
rowSum += board[0][i];
colSum += board[i][0];
if (board[i][0] == i % 2) {
++rowSwap;
}
if (board[0][i] == i % 2) {
++colSwap;
}
}
if (N / 2 > rowSum || N / 2 > (N - rowSum) ||
N / 2 > colSum || N / 2 > (N - colSum)) {
return -1;
}
if (N % 2 == 0) {
rowSwap = Math.min(rowSwap, N - rowSwap);
colSwap = Math.min(colSwap, N - colSwap);
} else {
if (colSwap % 2 == 1) {
colSwap = N - colSwap;
}
if (rowSwap % 2 == 1) {
rowSwap = N - rowSwap;
}
}
return (rowSwap + colSwap) / 2;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] β {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: t=int(input())
while t!=0:
m,n=input().split()
m,n=int(m),int(n)
for i in range(m):
arr=input().strip()
if '1' in arr:
arr='1 '*n
else:
arr='0 '*n
print(arr)
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] β {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
int a[N][N];
// Driver code
int main()
{
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
bool b[n];
for(int i=0;i<n;i++){
b[i]=false;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
if(a[i][j]==1){
b[i]=true;
}
}
}
for(int i=0;i<n;i++){
if(b[i]){
for(int j=0;j<m;j++){
cout<<1<<" ";
}}
else{
for(int j=0;j<m;j++){
cout<<0<<" ";
}
}
cout<<endl;
}
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] β {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws Exception{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(isr);
int t = Integer.parseInt(bf.readLine());
while (t-- > 0){
String inputs[] = bf.readLine().split(" ");
int m = Integer.parseInt(inputs[0]);
int n = Integer.parseInt(inputs[1]);
String[] matrix = new String[m];
for(int i=0; i<m; i++){
matrix[i] = bf.readLine();
}
StringBuffer ones = new StringBuffer("");
StringBuffer zeros = new StringBuffer("");
for(int i=0; i<n; i++){
ones.append("1 ");
zeros.append("0 ");
}
for(int i=0; i<m; i++){
if(matrix[i].contains("1")){
System.out.println(ones);
}else{
System.out.println(zeros);
}
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.