Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import math
n = int(input())
n=n+1
if n<3:
print(0)
else:
primes=[1]*(n//2)
for i in range(3,int(math.sqrt(n))+1,2):
if primes[i//2]:primes[i*i//2::i]=[0]*((n-i*i-1)//(2*i)+1)
print(sum(primes)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<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 integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: def Pattern(N):
print('*')
for i in range (0,N-2):
print('*',end='')
for j in range (0,i+1):
print('^',end='')
print('*')
for i in range (0,N+1):
print('*',end='')
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<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 integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: void Pattern(int N){
cout<<'*'<<endl;
for(int i=0;i<N-2;i++){
cout<<'*';
for(int j=0;j<=i;j++){
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 an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<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 integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: static void Pattern(int N){
System.out.println('*');
for(int i=0;i<N-2;i++){
System.out.print('*');
for(int j=0;j<=i;j++){
System.out.print('^');
}System.out.println('*');
}
for(int i=0;i<=N;i++){
System.out.print('*');
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<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 integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: void Pattern(int N){
printf("*\n");
for(int i=0;i<N-2;i++){
printf("*");
for(int j=0;j<=i;j++){
printf("^");}printf("*\n");
}
for(int i=0;i<=N;i++){
printf("*");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: #include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define ma 10000001
bool a[ma];
int main()
{
int n;
cin>>n;
for(int i=0;i<=n;i++){
a[i]=false;
}
for(int i=2;i<=n;i++){
if(a[i]==false){
for(int j=i+i;j<=n;j+=i){
a[j]=true;
}
}
}
int cnt=0;
for(int i=2;i<=n;i++){
if(a[i]==false){cnt++;}
}
cout<<cnt;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args)
throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long n = Integer.parseInt(br.readLine());
long i=2,j,count,noOfPrime=0;
if(n<=1)
System.out.println("0");
else{
while(i<=n)
{
count=0;
for(j=2; j<=Math.sqrt(i); j++)
{
if( i%j == 0 ){
count++;
break;
}
}
if(count==0){
noOfPrime++;
}
i++;
}
System.out.println(noOfPrime);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: function numberOfPrimes(N)
{
let arr = new Array(N+1);
for(let i = 0; i <= N; i++)
arr[i] = 0;
for(let i=2; i<= N/2; i++)
{
if(arr[i] === -1)
{
continue;
}
let p = i;
for(let j=2; p*j<= N; j++)
{
arr[p*j] = -1;
}
}
//console.log(arr);
let count = 0;
for(let i=2; i<= N; i++)
{
if(arr[i] === 0)
{
count++;
}
}
//console.log(arr);
return count;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import math
n = int(input())
n=n+1
if n<3:
print(0)
else:
primes=[1]*(n//2)
for i in range(3,int(math.sqrt(n))+1,2):
if primes[i//2]:primes[i*i//2::i]=[0]*((n-i*i-1)//(2*i)+1)
print(sum(primes)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list consisting of <b>L</b> nodes and given a number <b>N</b>. The task is to find the Nth node from the end of the linked list.First line of input contains number of testcase T. For each testcase, first line of input contains number of nodes in the linked list L and the number N. Next line contains N nodes of linked list.
<b>User Task:</b>
The task is to complete the function <b>getNthFromLast()</b> which takes two arguments: reference to head and N and you need to return Nth from end.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= L <= 10^3
For each testcase, output the data of node which is at Nth distance from end.Input:
2
9 2
1 2 3 4 5 6 7 8 9
4 5
10 5 100 5
Output:
8
-1
Explanation:
Testcase 1: In the first example, there are 9 nodes in linked list and we need to find 2nd node from end. 2nd node from end os 8.
Testcase 2: In the second example, there are 4 nodes in linked list and we need to find 5th from end. Since 'n' is more than number of nodes in linked list, output is -1., I have written this Solution Code: static int getNthFromLast(Node head, int n)
{
int len = 0;
Node temp = head;
while(temp != null) // Traverse temp throught the linked list and find the length
{
temp = temp.next;
len++;
}
if(len < n)
return -1;
//System.out.println(count);
//int r = count - n;
temp = head;
for(int i=1; i<len-n+1; i++) // Traverse the node till the position from begining: length - n +1.
temp = temp.next;
return temp.data;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size n, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int m = 100001;
int main(){
int n,k;
cin>>n>>k;
long long a[n],sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]<0){
a[i]=-a[i];
}
}
sort(a,a+n);
for(int i=0;i<k;i++){
sum+=a[n-i-1]*a[n-i-1];
}
cout<<sum;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size n, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
String[] NK = br.readLine().split(" ");
String[] inputs = br.readLine().split(" ");
int N = Integer.parseInt(NK[0]);
int K = Integer.parseInt(NK[1]);
long[] arr = new long[N];
long answer = 0;
for(int i = 0; i < N; i++){
arr[i] = Math.abs(Long.parseLong(inputs[i]));
}
quicksort(arr, 0, N-1);
for(int i = (N-K); i < N;i++){
answer += (arr[i]*arr[i]);
}
System.out.println(answer);
}
static void quicksort(long[] arr, int start, int end){
if(start < end){
int pivot = partition(arr, start, end);
quicksort(arr, start, pivot-1);
quicksort(arr, pivot+1, end);
}
}
static int partition(long[] arr, int start, int end){
long pivot = arr[end];
int i = start - 1;
for(int j = start; j < end; j++){
if(arr[j] < pivot){
i++;
swap(arr, i, j);
}
}
swap(arr, i+1, end);
return (i+1);
}
static void swap(long[] arr, int i, int j){
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size n, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: x,y = map(int,input().split())
arr = list(map(int,input().split()))
s=0
for i in range(x):
if arr[i]<0:
arr[i]=abs(arr[i])
arr=sorted(arr,reverse=True)
for i in range(0,y):
s = s+arr[i]*arr[i]
print(s)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a doubly linked list consisting of N nodes and two integers <b>P</b> and <b>K</b>. Your task is to add an element K at the Pth position from the start of the linked list<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>insertnew()</b>. The description of parameters are mentioned below:
<b>head</b>: head node of the double linked list
<b>K</b>: the element which you have to insert
<b>P</b>: the position at which you have insert
Constraints:
1 <= P <=N <= 1000
1 <=K, Node.data<= 1000
In the sample Input N, P and K are in the order as mentioned below:
<b>N P K</b>Return the head of the modified linked list.Sample Input:-
5 3 2
1 3 2 4 5
Sample Output:-
1 3 2 2 4 5, I have written this Solution Code: public static Node insertnew(Node head, int k,int pos) {
int cnt=1;
if(pos==1){Node temp=new Node(k);
temp.next=head;
head.prev=temp;
return temp;}
Node temp=head;
while(cnt!=pos-1){
temp=temp.next;
cnt++;
}
Node x= new Node(k);
x.next=temp.next;
temp.next.prev=x;
temp.next=x;
x.prev=temp;
return head;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a weighted undirected graph.Task is to find the shortest path from source vertex (vertex number 1) to all other vertices from 2 to n.Given 2 integers N and M. N represents the number of vertices in the graph. M represents the number of edges between any 2 vertices.
Then M lines follow, each line has 2 space separated integers a, b where a and b represents an edge from vertex a to vertex b and the weight of that edge = (a+b)%1000.
Constraints
1<=N<=100000
1<=M<=1000000Print the shortest distances from the source vertex (vertex number 1) to all other vertices from 2 to n in separate line. Print "-1" in case the vertex can't be reached form the source vertex.Sample Input
4 5
1 2
1 4
4 2
4 3
2 3
Sample Output
3
8
5
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String args[] ) throws Exception {
int n,m;
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
String line = br.readLine();
StringTokenizer st = new StringTokenizer(line);
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
ArrayList<ArrayList<int[]>> graph = new ArrayList<>(n+1);
for ( int i= 0; i <= n; i++){
graph.add( new ArrayList<int[]>());
}
for ( int i = 0; i < m; i++){
int u,v,w;
line = br.readLine();
if ( line == null)
continue;
st = new StringTokenizer(line);
u = Integer.parseInt( st.nextToken());
v = Integer.parseInt( st.nextToken());
w=(u+v)%1000;
graph.get(u).add( new int[]{v,w});
graph.get(v).add( new int[]{u,w});
}
long[] dist = Dijkstra(graph,1);
for( int i = 2; i <= n ; i++){
if(dist[i]==9223372036854775807L){
System.out.println("-1");
}
else
System.out.println(dist[i]);
}
}
private static long[] Dijkstra( ArrayList<ArrayList<int[]>> graph, int source){
int n = graph.size();
long[] dist = new long[n];
boolean[] visited = new boolean[n];
Arrays.fill(dist,Long.MAX_VALUE);
PriorityQueue<long[]> queue = new PriorityQueue<>( (long[] i1,long[] i2)->{
if( i1[1] < i2[1])
return -1;
return 1;
});
queue.add(new long[]{source,0});
while ( !queue.isEmpty()){
long[] cn = queue.remove();
if( visited[(int)cn[0]] ){
continue;
}
visited[(int)cn[0]] = true;
dist[(int)cn[0]] = cn[1];
for( int[] neighbour : graph.get((int)cn[0])){
if ( !visited[neighbour[0]] ){
long newdistance = cn[1] + neighbour[1];
if ( newdistance < dist[neighbour[0]]){
dist[neighbour[0]] = newdistance;
queue.add( new long[]{neighbour[0],newdistance});
}
}
}
}
return dist;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a weighted undirected graph.Task is to find the shortest path from source vertex (vertex number 1) to all other vertices from 2 to n.Given 2 integers N and M. N represents the number of vertices in the graph. M represents the number of edges between any 2 vertices.
Then M lines follow, each line has 2 space separated integers a, b where a and b represents an edge from vertex a to vertex b and the weight of that edge = (a+b)%1000.
Constraints
1<=N<=100000
1<=M<=1000000Print the shortest distances from the source vertex (vertex number 1) to all other vertices from 2 to n in separate line. Print "-1" in case the vertex can't be reached form the source vertex.Sample Input
4 5
1 2
1 4
4 2
4 3
2 3
Sample Output
3
8
5
, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
vector<int> NEB[sz],wt[sz];
int dist[sz];
int vis[sz];
signed main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++)
{
int a,b;
cin>>a>>b;
int c=(a+b)%1000;
NEB[a].pu(b);
NEB[b].pu(a);
wt[a].pu(c);
wt[b].pu(c);
}
for(int i=1;i<=n;i++)
{
dist[i]=1000000000;
}
multiset<pii> ss;
ss.insert(mp(0,1));
dist[1]=0;
while(ss.size()>0)
{
pii xx=*ss.begin();
int a=xx.se;
ss.erase(ss.begin());
if(vis[a]==1) continue;
vis[a]=1;
int ww=dist[a];
for(int i=0;i<NEB[a].size();i++)
{
int x=NEB[a][i];
int y=wt[a][i];
if(dist[x]>dist[a]+y)
{
dist[x]=dist[a]+y;
ss.insert(mp(dist[x],x));
}
}
}
for(int i=2;i<=n;i++)
{ if(dist[i]>=1000000000) cout<<-1<<"\n";
else cout<<dist[i]<<"\n";
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tom has a water bottle with the shape of a rectangular prism whose base is a square of side a cm and whose height is b cm. (The thickness of the bottle can be ignored)
We will pour x cubic cm of water into the bottle, and gradually tilt the bottle around one of the sides of the base. When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.Their is only one line of input which contain three integers a, b and x.
Constraints:-
1 ≤ a ≤ 100
1 ≤ b ≤ 100
1 ≤ x ≤ (a^2)*bPrint the maximum angle in which we can tilt the bottle without spilling any water, in degrees. Print 10 digits after decimal.Sample Input:
2 2 4
Sample Output
45.0000000000
Sample Input
12 21 10
Sample Output
89.7834636934, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader scan=new BufferedReader(new InputStreamReader(System.in));
String s[]=scan.readLine().split(" ");
int width=Integer.parseInt(s[0]);
int height=Integer.parseInt(s[1]);
int givenVolume=Integer.parseInt(s[2]);
double heightOfGivenVolume=(givenVolume)/(double)(width*width);
double angleInDegree=0.0;
if(heightOfGivenVolume==height)
{
angleInDegree=90.0;
}
else if(heightOfGivenVolume<=(height/2))
{
double tanTheta=(2.0*width*heightOfGivenVolume)/(double)(height*height);
double angleInRadian=Math.atan(tanTheta);
angleInDegree=90.0-Math.toDegrees(angleInRadian);
}
else
{
double tanTheta=width/(2.0*(height-heightOfGivenVolume));
double angleInRadian=Math.atan(tanTheta);
angleInDegree=90.0-Math.toDegrees(angleInRadian);
}
System.out.printf("%.10f",angleInDegree);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tom has a water bottle with the shape of a rectangular prism whose base is a square of side a cm and whose height is b cm. (The thickness of the bottle can be ignored)
We will pour x cubic cm of water into the bottle, and gradually tilt the bottle around one of the sides of the base. When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.Their is only one line of input which contain three integers a, b and x.
Constraints:-
1 ≤ a ≤ 100
1 ≤ b ≤ 100
1 ≤ x ≤ (a^2)*bPrint the maximum angle in which we can tilt the bottle without spilling any water, in degrees. Print 10 digits after decimal.Sample Input:
2 2 4
Sample Output
45.0000000000
Sample Input
12 21 10
Sample Output
89.7834636934, I have written this Solution Code: #include <bits/stdc++.h>
// #define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
double a,b,x;
cin>>a>>b>>x;
double ans;
double pi = 2*acos(0.0);
if(x<(a*a*b)/2 )
{
double p= (a*b*b)/(2*x);
ans = atan(p);
ans= (ans*180)/pi;
}
else
{
double p = (2*((a*a*b) - x))/(a*a*a);
ans = atan(p);
ans= (ans*180)/pi;
}
cout <<std::fixed;
cout<<setprecision(10)<<ans;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stock’s price for all n days.
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day(including), for which the price of the stock on the current day is less than or equal to its price on the given day.
For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}.
Explanation to the given example:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6.The first line of each test case is N, N is the size of the array. The second line of each test case contains N input A[i].
1 ≤ N ≤ 100000
1 ≤ A[i] ≤ 100000For each test case, print the span values for all days.Input
7
100 80 60 70 60 75 85
Output
1 1 1 2 1 4 6
Input
6
10 4 5 90 120 80
Output
1 1 2 4 5 1
Explanation:
Test case 1:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int size = Integer.parseInt(br.readLine());
String st = br.readLine();
String[] stArr = st.trim().split(" ");
int[] arr = new int[size];
for(int i=0; i<size; i++){
arr[i] = Integer.parseInt(stArr[i]);
}
Stack<Integer> stack = new Stack<>();
StringBuilder sb=new StringBuilder("");
for(int i=0; i<size; i++){
int count = 0;
if(stack.isEmpty()){
stack.push(i);
sb.append("1 ");
} else if(arr[stack.peek()] > arr[i]){
stack.push(i);
sb.append("1 ");
} else{
while(!stack.isEmpty() && arr[stack.peek()] <= arr[i]){
stack.pop();
}
if(stack.isEmpty()){
count = i+1;
} else{
count = i - stack.peek();
}
sb.append(count+" ");
stack.push(i);
}
}
System.out.print(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stock’s price for all n days.
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day(including), for which the price of the stock on the current day is less than or equal to its price on the given day.
For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}.
Explanation to the given example:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6.The first line of each test case is N, N is the size of the array. The second line of each test case contains N input A[i].
1 ≤ N ≤ 100000
1 ≤ A[i] ≤ 100000For each test case, print the span values for all days.Input
7
100 80 60 70 60 75 85
Output
1 1 1 2 1 4 6
Input
6
10 4 5 90 120 80
Output
1 1 2 4 5 1
Explanation:
Test case 1:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6., I have written this Solution Code: n = int(input())
lst = list(map(int, input().strip().split()))
S = [0]*n
st = []
st.append(0)
for i in range(n):
while( len(st) > 0 and lst[st[-1]] <= lst[i]):
st.pop()
S[i] = i + 1 if len(st) <= 0 else (i - st[-1])
st.append(i)
for i in range(0, n):
print (S[i], end =" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stock’s price for all n days.
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day(including), for which the price of the stock on the current day is less than or equal to its price on the given day.
For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}.
Explanation to the given example:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6.The first line of each test case is N, N is the size of the array. The second line of each test case contains N input A[i].
1 ≤ N ≤ 100000
1 ≤ A[i] ≤ 100000For each test case, print the span values for all days.Input
7
100 80 60 70 60 75 85
Output
1 1 1 2 1 4 6
Input
6
10 4 5 90 120 80
Output
1 1 2 4 5 1
Explanation:
Test case 1:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int n; cin >> n;
stack<int> s;
a[0] = inf;
s.push(0);
for(int i = 1; i <= n; i++){
cin >> a[i];
while(!s.empty() && a[s.top()] <= a[i])
s.pop();
cout << i - s.top() << " ";
s.push(i);
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: a, b = list(map(int, input().split(" ")))
print(str(a <= 10 and b >= 10).lower(), end=' ')
print(str(a % 2 == 0 or b % 2 == 0).lower(), end=' ')
print(str(not a == b).lower()), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Main {
static boolean Logical_AND(int a, int b){
if(a<=10 && b>=10){
return true;}
return false;}
static boolean Logical_OR(int a, int b){
if(a%2==0 || b%2==0){
return true;}
return false;}
static boolean Logical_NOT(int a, int b){
if(a!=b){
return true;}
return false;}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
System.out.print(Logical_AND(a, b)+" ");
System.out.print(Logical_OR(a,b)+" ");
System.out.print(Logical_NOT(a,b)+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton wants to take revenge from two apples fallen on his head. So, he applies force F<sub>1</sub> on first apple (mass M<sub>1</sub>) resulting in acceleration of A<sub>1</sub> and F<sub>2</sub> on second apple (mass M<sub>2</sub>) resulting in acceleration of A<sub>2</sub>. Given M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>. Calculate total force applied by him on two apples.
<b>Note:</b> F = M*A is the equation of relation between force, mass and acceleration.First line contains four integers M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>.
1 <= M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub> <= 100Output total force applied by Newton.INPUT:
1 2 3 4
OUTPUT:
14
Explanation:
Total force is equal to 1*2 + 3*4 = 14., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int m1,a1,m2,a2;
cin >> m1 >> a1 >> m2 >> a2;
cout << (m1*a1)+(m2*a2) << endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement the function <code>round</code>, which should take a number which can be a float(decimal)
and return its result as an integer rounded of (Use JS In built functions)Function will take a float as input (can be negative or positive)Function will return a rounded off numberconsole. log(round(1.112)) // prints 1
console. log(round(1.9)) // prints 2
console. log(round(-0.66)) // prints -1, I have written this Solution Code: function round(num){
// write code here
// return the output , do not use console.log here
return Math.round(num)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement the function <code>round</code>, which should take a number which can be a float(decimal)
and return its result as an integer rounded of (Use JS In built functions)Function will take a float as input (can be negative or positive)Function will return a rounded off numberconsole. log(round(1.112)) // prints 1
console. log(round(1.9)) // prints 2
console. log(round(-0.66)) // prints -1, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.math.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
double n=sc.nextDouble();
System.out.println(Math.round(n));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: #include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define ma 10000001
bool a[ma];
int main()
{
int n;
cin>>n;
for(int i=0;i<=n;i++){
a[i]=false;
}
for(int i=2;i<=n;i++){
if(a[i]==false){
for(int j=i+i;j<=n;j+=i){
a[j]=true;
}
}
}
int cnt=0;
for(int i=2;i<=n;i++){
if(a[i]==false){cnt++;}
}
cout<<cnt;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args)
throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long n = Integer.parseInt(br.readLine());
long i=2,j,count,noOfPrime=0;
if(n<=1)
System.out.println("0");
else{
while(i<=n)
{
count=0;
for(j=2; j<=Math.sqrt(i); j++)
{
if( i%j == 0 ){
count++;
break;
}
}
if(count==0){
noOfPrime++;
}
i++;
}
System.out.println(noOfPrime);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: function numberOfPrimes(N)
{
let arr = new Array(N+1);
for(let i = 0; i <= N; i++)
arr[i] = 0;
for(let i=2; i<= N/2; i++)
{
if(arr[i] === -1)
{
continue;
}
let p = i;
for(let j=2; p*j<= N; j++)
{
arr[p*j] = -1;
}
}
//console.log(arr);
let count = 0;
for(let i=2; i<= N; i++)
{
if(arr[i] === 0)
{
count++;
}
}
//console.log(arr);
return count;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import math
n = int(input())
n=n+1
if n<3:
print(0)
else:
primes=[1]*(n//2)
for i in range(3,int(math.sqrt(n))+1,2):
if primes[i//2]:primes[i*i//2::i]=[0]*((n-i*i-1)//(2*i)+1)
print(sum(primes)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The product sum of two equal length arrays num1 and num2 is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0- indexed).
For example, if num1 = [1, 2, 3, 4] and num2 = [5, 2, 3, 1], the product sum would be 1*5 + 2*2 + 3*3 + 4*1 = 22.
Given two arrays num1 and num2 of length n, return the minimum product sum if you are allowed to rearrange the order of the elements in num1.The first line of the input contains the n (size of the array)
The Second line of the input contains the array num1.
Next line of the input contains the array num2.
<b>Constraints</b>
1 <= n <= 1e5
1 <= num1[i], num2[i] <= 100Print the minimum product sum.Sample Input 1:
4
5 3 4 2
4 2 2 5
Sample Output 1:
40
Explanation :
We can rearrange num1 to become [3, 5, 4, 2]. The product sum of [3, 5, 4, 2] and [4, 2, 2, 5] is 3*4 + 5*2 + 4*2 + 2*5 = 40., 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));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int[] num1 = new int[n];
int[] num2 = new int[n];
int i, ans=0;
st = new StringTokenizer(br.readLine());
for(i=0;i<n;i++)
num1[i] = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
for(i=0;i<n;i++)
num2[i] = Integer.parseInt(st.nextToken());
Arrays.sort(num1);
Arrays.sort(num2);
for(i=0;i<n;i++)
ans+= num1[i]*num2[n-i-1];
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The product sum of two equal length arrays num1 and num2 is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0- indexed).
For example, if num1 = [1, 2, 3, 4] and num2 = [5, 2, 3, 1], the product sum would be 1*5 + 2*2 + 3*3 + 4*1 = 22.
Given two arrays num1 and num2 of length n, return the minimum product sum if you are allowed to rearrange the order of the elements in num1.The first line of the input contains the n (size of the array)
The Second line of the input contains the array num1.
Next line of the input contains the array num2.
<b>Constraints</b>
1 <= n <= 1e5
1 <= num1[i], num2[i] <= 100Print the minimum product sum.Sample Input 1:
4
5 3 4 2
4 2 2 5
Sample Output 1:
40
Explanation :
We can rearrange num1 to become [3, 5, 4, 2]. The product sum of [3, 5, 4, 2] and [4, 2, 2, 5] is 3*4 + 5*2 + 4*2 + 2*5 = 40., I have written this Solution Code: n = int(input())
num1 = [int(x) for x in input().split()]
num2 = [int(x) for x in input().split()]
num1.sort()
num2.sort()
res = 0
for i in range(n):
res += num1[i] * num2[n-i-1]
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The product sum of two equal length arrays num1 and num2 is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0- indexed).
For example, if num1 = [1, 2, 3, 4] and num2 = [5, 2, 3, 1], the product sum would be 1*5 + 2*2 + 3*3 + 4*1 = 22.
Given two arrays num1 and num2 of length n, return the minimum product sum if you are allowed to rearrange the order of the elements in num1.The first line of the input contains the n (size of the array)
The Second line of the input contains the array num1.
Next line of the input contains the array num2.
<b>Constraints</b>
1 <= n <= 1e5
1 <= num1[i], num2[i] <= 100Print the minimum product sum.Sample Input 1:
4
5 3 4 2
4 2 2 5
Sample Output 1:
40
Explanation :
We can rearrange num1 to become [3, 5, 4, 2]. The product sum of [3, 5, 4, 2] and [4, 2, 2, 5] is 3*4 + 5*2 + 4*2 + 2*5 = 40., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int32_t main() {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
debug(a);
debug(b);
sort(a.begin(), a.end());
// sort(b.begin(), b.end(), greater<int>());
priority_queue<int, vector<int>> pq;
for (int i = 0; i < n; i++) {
pq.push(b[i]);
}
int sum = 0;
int i = 0;
while (pq.size() > 0) {
int x = pq.top();
sum += a[i] * x;
i += 1;
pq.pop();
}
cout << sum << "\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a non-negative Integer x, check if this number is constant, constant number is a number whose digits are all same.The first line contains 1 integer x.
<b>Constraints</b>
0 ≤ x ≤ 10<sup>5</sup>Print true if the number is constant, otherwise, false.Sample Input 1 :
20
Sample Output 1 :
false
Sample Input 2 :
2222
Sample Output 2 :
true, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
assert n>=0&&n<=100000 : "Input Not Valid";
int curr=n%10;
boolean ans=true;
while(n>0){
int c=n%10;
n/=10;
if(c!=curr){
ans=false;
break;
}
curr = c;
}
System.out.print(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a class and some inputs for the corresponding variables of the class, your task is to create an object of the given class by the name <b>Car1</b> and assign the given input to its variables.The input will contain 3 lines:-
First- line contains a string which is the Name of the Car
Second- line contains an integer which is the Model of the Car
The last line of input contains an integer which is the Engine of the Car.You don't need to print anything printing will be done by the driver code itself, you just have to create an object of the class Car by the name Car1 and assign the variables given in the input.Sample Input:-
Ferrari
143
123
Sample Output:-
Ferrari
143
123, I have written this Solution Code: Car1 carObj = new Car1();
carObj.carName = carName;
carObj.modelNum = modelNum;
carObj.engineNum = engineNum;, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a class and some inputs for the corresponding variables of the class, your task is to create an object of the given class by the name <b>Car1</b> and assign the given input to its variables.The input will contain 3 lines:-
First- line contains a string which is the Name of the Car
Second- line contains an integer which is the Model of the Car
The last line of input contains an integer which is the Engine of the Car.You don't need to print anything printing will be done by the driver code itself, you just have to create an object of the class Car by the name Car1 and assign the variables given in the input.Sample Input:-
Ferrari
143
123
Sample Output:-
Ferrari
143
123, I have written this Solution Code:
Car1 = Car();
Car1.Name = input()
Car1.Engine = int(input())
Car1.Model = int(input()), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: def inv(a,b,m):
res = 1
while(b):
if b&1:
res = (res*a)%m
a = (a*a)%m
b >>= 1
return res
n,x = map(int,input().split())
a = list(map(int,input().split()))
m = 1000000007
for i in a:
x = (x*inv(i,m-2,m))%m
print(x), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
int power_mod(int a,int b,int mod){
int ans = 1;
while(b){
if(b&1)
ans = (ans*a)%mod;
b = b/2;
a = (a*a)%mod;
}
return ans;
}
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int x;
cin>>x;
int mo=1000000007;
int mu=1;
for(int i=0;i<n;++i){
int d;
cin>>d;
mu=(mu*d)%mo;
}
cout<<(x*power_mod(mu,mo-2,mo))%mo;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: import java.io.*;import java.util.*;import java.math.*;
public class Main
{
long mod=1000000007l;int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;
long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;StringBuilder sb;
public void tq()throws Exception
{
st=new StringTokenizer(br.readLine());
int tq=1;
o:
while(tq-->0)
{
int n=i();
long k=l();
long ar[]=arl(n);
long v=1l;
for(long x:ar)v=(v*x)%mod;
v=(k*(mul(v,mod-2,mod)))%mod;
pl(v);
}
}
public static void main(String[] a)throws Exception{new Main().tq();}
int[] so(int ar[]){Integer r[]=new Integer[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
long[] so(long ar[]){Long r[]=new Long[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
char[] so(char ar[])
{Character r[]=new Character[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
void s(String s){sb.append(s);}void s(int s){sb.append(s);}void s(long s){sb.append(s);}
void s(char s){sb.append(s);}void s(double s){sb.append(s);}
void ss(){sb.append(' ');}void sl(String s){sb.append(s);sb.append("\n");}
void sl(int s){sb.append(s);sb.append("\n");}
void sl(long s){sb.append(s);sb.append("\n");}void sl(char s){sb.append(s);sb.append("\n");}
void sl(double s){sb.append(s);sb.append("\n");}void sl(){sb.append("\n");}
int min(int a,int b){return a<b?a:b;}
int min(int a,int b,int c){return a<b?a<c?a:c:b<c?b:c;}
int max(int a,int b){return a>b?a:b;}
int max(int a,int b,int c){return a>b?a>c?a:c:b>c?b:c;}
long min(long a,long b){return a<b?a:b;}
long min(long a,long b,long c){return a<b?a<c?a:c:b<c?b:c;}
long max(long a,long b){return a>b?a:b;}
long max(long a,long b,long c){return a>b?a>c?a:c:b>c?b:c;}
int abs(int a){return Math.abs(a);}
long abs(long a){return Math.abs(a);}
int sq(int a){return (int)Math.sqrt(a);}long sq(long a){return (long)Math.sqrt(a);}
long gcd(long a,long b){return b==0l?a:gcd(b,a%b);}
boolean pa(String s,int i,int j){while(i<j)if(s.charAt(i++)!=s.charAt(j--))return false;return true;}
boolean[] si(int n)
{boolean bo[]=new boolean[n+1];bo[0]=true;bo[1]=true;for(int x=4;x<=n;x+=2)bo[x]=true;
for(int x=3;x*x<=n;x+=2){if(!bo[x]){int vv=(x<<1);for(int y=x*x;y<=n;y+=vv)bo[y]=true;}}
return bo;}long mul(long a,long b,long m)
{long r=1l;a%=m;while(b>0){if((b&1)==1)r=(r*a)%m;b>>=1;a=(a*a)%m;}return r;}
int i()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Integer.parseInt(st.nextToken());}
long l()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Long.parseLong(st.nextToken());}String s()throws IOException
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());return st.nextToken();}
double d()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Double.parseDouble(st.nextToken());}void p(Object p){System.out.print(p);}
void p(String p){System.out.print(p);}void p(int p){System.out.print(p);}
void p(double p){System.out.print(p);}void p(long p){System.out.print(p);}
void p(char p){System.out.print(p);}void p(boolean p){System.out.print(p);}
void pl(Object p){System.out.println(p);}void pl(String p){System.out.println(p);}
void pl(int p){System.out.println(p);}void pl(char p){System.out.println(p);}
void pl(double p){System.out.println(p);}void pl(long p){System.out.println(p);}
void pl(boolean p){System.out.println(p);}void pl(){System.out.println();}
void s(int a[]){for(int e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(long a[]){for(long e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(int ar[][]){for(int a[]:ar){for(int e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}
void s(char a[]){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(char ar[][]){for(char a[]:ar){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}
int[] ari(int n)throws IOException
{int ar[]=new int[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=Integer.parseInt(st.nextToken());return ar;}
int[][] ari(int n,int m)throws IOException
{int ar[][]=new int[n][m];for(int x=0;x<n;x++){if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());}return ar;}
long[] arl(int n)throws IOException
{long ar[]=new long[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++) ar[x]=Long.parseLong(st.nextToken());return ar;}
long[][] arl(int n,int m)throws IOException
{long ar[][]=new long[n][m];for(int x=0;x<n;x++)
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());}return ar;}
String[] ars(int n)throws IOException
{String ar[]=new String[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++) ar[x]=st.nextToken();return ar;}
double[] ard(int n)throws IOException
{double ar[]=new double[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());return ar;}
double[][] ard(int n,int m)throws IOException
{double ar[][]=new double[n][m];for(int x=0;x<n;x++)
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Double.parseDouble(st.nextToken());}return ar;}
char[] arc(int n)throws IOException{char ar[]=new char[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);return ar;}
char[][] arc(int n,int m)throws IOException{char ar[][]=new char[n][m];
for(int x=0;x<n;x++){String s=br.readLine();for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);}return ar;}
void p(int ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(int a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(int ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(int a[]:ar){for(int aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(long ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(long a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(long ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(long a[]:ar){for(long aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(String ar[]){int c=0;for(String s:ar)c+=s.length()+1;StringBuilder sb=new StringBuilder(c);
for(String a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(double ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(double a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(double ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(double a[]:ar){for(double aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(char ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(char aa:ar){sb.append(aa);sb.append(' ');}System.out.println(sb);}
void p(char ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(char a[]:ar){for(char aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: for i in range(int(input())):
n, x = map(int, input().split())
if x >= 10:
print(0)
else:
print((10-x)*(n-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n, x;
cin >> n >> x;
if(x >= 10)
cout << 0 << endl;
else
cout << (10-x)*(n-1) << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
while (T -->0){
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int p = Integer.parseInt(s[1]);
if (p<10)
System.out.println(Math.abs(n-1)*(10-p));
else System.out.println(0);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to find the count of repeated elements. Print the repeated elements in ascending order along with their frequency.
Have a look at the example for more understanding.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000For each duplicate element in sorted order in a new line, First, print the duplicate element and then print its number of occurence space- separated.
Note:- It is guaranteed that at least one duplicate element will exist in the given array.Sample Input:-
5
3 2 1 1 2
Sample Output:-
1 2
2 2
Sample Input:-
5
1 1 1 1 5
Sample Output:-
1 4
Explaination:
test 1: Only 1 and 2 are repeated. Both are repeated twice. So, we print:
1 -> frequency of 1
2 -> frequency of 2
1 is printed before 2 as it is smaller than 2, I have written this Solution Code: import numpy as np
from collections import defaultdict
n=int(input())
a=np.array([input().strip().split()],int).flatten()
d=defaultdict(int)
for i in a:
d[i]+=1
d=sorted(d.items())
for i in d:
if(i[1]>1):
print(i[0],end=" ")
print(i[1])
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to find the count of repeated elements. Print the repeated elements in ascending order along with their frequency.
Have a look at the example for more understanding.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000For each duplicate element in sorted order in a new line, First, print the duplicate element and then print its number of occurence space- separated.
Note:- It is guaranteed that at least one duplicate element will exist in the given array.Sample Input:-
5
3 2 1 1 2
Sample Output:-
1 2
2 2
Sample Input:-
5
1 1 1 1 5
Sample Output:-
1 4
Explaination:
test 1: Only 1 and 2 are repeated. Both are repeated twice. So, we print:
1 -> frequency of 1
2 -> frequency of 2
1 is printed before 2 as it is smaller than 2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int noOfElements = Integer.parseInt(in.readLine());
String [] elem = in.readLine().trim().split(" ");
int [] elements = new int [noOfElements];
for(int i=0 ; i< noOfElements; i++){
elements[i] = Integer.parseInt(elem[i]);
}
Arrays.sort(elements);
int count =0;
for(int i = 0 ; i < noOfElements-1 ; i++){
if(elements[i] == elements[i+1]){
count ++;
}
else if(count != 0){
System.out.print(elements[i]+" "+(count+1));
count =0;
System.out.println();
}
}
if(count != 0)
System.out.print(elements[noOfElements-1]+" "+(count+1));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to find the count of repeated elements. Print the repeated elements in ascending order along with their frequency.
Have a look at the example for more understanding.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000For each duplicate element in sorted order in a new line, First, print the duplicate element and then print its number of occurence space- separated.
Note:- It is guaranteed that at least one duplicate element will exist in the given array.Sample Input:-
5
3 2 1 1 2
Sample Output:-
1 2
2 2
Sample Input:-
5
1 1 1 1 5
Sample Output:-
1 4
Explaination:
test 1: Only 1 and 2 are repeated. Both are repeated twice. So, we print:
1 -> frequency of 1
2 -> frequency of 2
1 is printed before 2 as it is smaller than 2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin>>n;
int a[n];
map<int,int> m;
for(int i=0;i<n;i++){
cin>>a[i];
m[a[i]]++;
}
for(auto it = m.begin();it!=m.end();it++){
if(it->second>1){
cout<<it->first<<" "<<it->second<<'\n';
}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. The task is to print all permutations of the characters in the given string.The only line of input contains a string S with all distinct uppercase letters of the English alphabet.
Constraints:-
1<=|S|<=8Print all permutations of a given string S with single space and all permutations should be in lexicographically increasing order.Sample Input:
ABC
Sample Output:
ABC ACB BAC BCA CAB CBA, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static ArrayList<String> solution = new ArrayList<String>();
public static char[] swap(char[] charArray, int i, int j){
char temp;
temp = charArray[i];
charArray[i] = charArray[j];
charArray[j] = temp;
return charArray;
}
public static void permute(char[] charArray, int left, int right){
if(left == right){
String str = new String(charArray);
solution.add(str);
}
else{
for(int i=left; i<=right; i++)
{
charArray = swap(charArray, left, i);
permute(charArray, left+1, right);
charArray = swap(charArray, left, i);
}
}
}
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
String str = s.nextLine();
int n = str.length();
char[] charArray = str.toCharArray();
permute(charArray, 0, n-1);
Collections.sort(solution);
for(int i = 0; i < solution.size(); i++){
System.out.print(solution.get(i)+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. The task is to print all permutations of the characters in the given string.The only line of input contains a string S with all distinct uppercase letters of the English alphabet.
Constraints:-
1<=|S|<=8Print all permutations of a given string S with single space and all permutations should be in lexicographically increasing order.Sample Input:
ABC
Sample Output:
ABC ACB BAC BCA CAB CBA, 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;
vector<string> v;
void permute(string a, int l, int r)
{
// Base case
if (l == r)
v.push_back(a);
else
{
// Permutations made
for (int i = l; i <= r; i++)
{
// Swapping done
swap(a[l], a[i]);
// Recursion called
permute(a, l+1, r);
//backtrack
swap(a[l], a[i]);
}
}
}
signed main() {
IOS;
string s;
cin >> s;
sort(s.begin(), s.end());
permute(s, 0, s.length()-1);
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
cout<<v[i]<<" ";
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. The task is to print all permutations of the characters in the given string.The only line of input contains a string S with all distinct uppercase letters of the English alphabet.
Constraints:-
1<=|S|<=8Print all permutations of a given string S with single space and all permutations should be in lexicographically increasing order.Sample Input:
ABC
Sample Output:
ABC ACB BAC BCA CAB CBA, I have written this Solution Code: from itertools import permutations
s = input()
l1 = list(s)
s1 = "".join(sorted(l1))
l = permutations(s1,len(s1))
for i in l:
print("".join(i),end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Linear probing is a collision handling technique in hashing. Linear probing says that whenever a collision occurs, search for the immediate next position.
In this question, we'll learn how to fill up the hash table using linear probing technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr of size n. You need to fill up the hash table using linear probing and print the resultant hash table.
Note: All the positions that are unoccupied are denoted by -1 in the hash table.
If there is no more space to insert, then just drop that element.The first line of input contains T denoting the number of test cases. T-test cases follow. Each test case contains 2 lines of input. The first line contains the size of the hashtable and the size of the array. The third line contains elements of the array.
<b>Constraints:-</b>
1 ≤ T ≤ 100
1 ≤ hashSize ≤ 10<sup>3</sup>
1 ≤ sizeOfArray ≤ 10<sup>3</sup>
0 ≤ Array[] ≤ 10<sup>5</sup>
For each testcase, in a new line, print the hash table as shown in example.Input:
2
10 4
4 14 24 44
10 4
9 99 999 9999
Output:
-1 -1 -1 -1 4 14 24 44 -1 -1
99 999 9999 -1 -1 -1 -1 -1 -1 9
Explanation:
Testcase1: 4%10=4. So put 4 in hashtable[4]. Now, 14%10=4, but hashtable[4] is already filled so put 14 in the next slot and so on.
Testcase2: 9%10=9. So put 9 in hashtable[9]. Now, 99%10=9, but hashtable[9] is already filled so put 99 in the (99+1)%10 =0 slot so 99 goes into hashtable[0] and so on., I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define max1 1000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
bool isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
return power(n, p-2, p);
}
// Returns nCr % p using Fermat's little
// theorem.
int main(){
int t;
cin>>t;
while(t--){
int n,p;
cin>>p>>n;
int a[n];
li sum;
ll cur=0;
int b[p];
FOR(i,p){
b[i]=-1;}
unordered_map<ll,int> m;
ll cnt=0;
FOR(i,n){cin>>a[i];}
for(int i=0;i<min(n,p);i++){
cur=a[i]%p;
int j=0;
while(b[(cur+j)%p]!=-1){
j++;
}
b[(cur+j)%p]=a[i];
}
FOR(i,p){
out1(b[i]);
}
END;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Linear probing is a collision handling technique in hashing. Linear probing says that whenever a collision occurs, search for the immediate next position.
In this question, we'll learn how to fill up the hash table using linear probing technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr of size n. You need to fill up the hash table using linear probing and print the resultant hash table.
Note: All the positions that are unoccupied are denoted by -1 in the hash table.
If there is no more space to insert, then just drop that element.The first line of input contains T denoting the number of test cases. T-test cases follow. Each test case contains 2 lines of input. The first line contains the size of the hashtable and the size of the array. The third line contains elements of the array.
<b>Constraints:-</b>
1 ≤ T ≤ 100
1 ≤ hashSize ≤ 10<sup>3</sup>
1 ≤ sizeOfArray ≤ 10<sup>3</sup>
0 ≤ Array[] ≤ 10<sup>5</sup>
For each testcase, in a new line, print the hash table as shown in example.Input:
2
10 4
4 14 24 44
10 4
9 99 999 9999
Output:
-1 -1 -1 -1 4 14 24 44 -1 -1
99 999 9999 -1 -1 -1 -1 -1 -1 9
Explanation:
Testcase1: 4%10=4. So put 4 in hashtable[4]. Now, 14%10=4, but hashtable[4] is already filled so put 14 in the next slot and so on.
Testcase2: 9%10=9. So put 9 in hashtable[9]. Now, 99%10=9, but hashtable[9] is already filled so put 99 in the (99+1)%10 =0 slot so 99 goes into hashtable[0] and so on., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0){
String str[] = read.readLine().trim().split("\\s+");
int hashSize = Integer.parseInt(str[0]);
int N = Integer.parseInt(str[1]);
int arr[] = new int[N];
str = read.readLine().trim().split("\\s+");
for(int i = 0; i < N; i++){
arr[i] = Integer.parseInt(str[i]);
}
int hashTable[] = new int[hashSize];
for(int i=0; i<hashSize; i++){
hashTable[i] = -1;
}
for(int i = 0; i< Math.min(N, hashSize); i++){
int idx = arr[i] % hashSize;
int j = 0;
while(hashTable[(idx + j) % hashSize] != -1){
j++;
}
hashTable[(idx + j) % hashSize] = arr[i];
}
for(int i=0; i<hashSize; i++){
System.out.print(hashTable[i] +" ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Linear probing is a collision handling technique in hashing. Linear probing says that whenever a collision occurs, search for the immediate next position.
In this question, we'll learn how to fill up the hash table using linear probing technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr of size n. You need to fill up the hash table using linear probing and print the resultant hash table.
Note: All the positions that are unoccupied are denoted by -1 in the hash table.
If there is no more space to insert, then just drop that element.The first line of input contains T denoting the number of test cases. T-test cases follow. Each test case contains 2 lines of input. The first line contains the size of the hashtable and the size of the array. The third line contains elements of the array.
<b>Constraints:-</b>
1 ≤ T ≤ 100
1 ≤ hashSize ≤ 10<sup>3</sup>
1 ≤ sizeOfArray ≤ 10<sup>3</sup>
0 ≤ Array[] ≤ 10<sup>5</sup>
For each testcase, in a new line, print the hash table as shown in example.Input:
2
10 4
4 14 24 44
10 4
9 99 999 9999
Output:
-1 -1 -1 -1 4 14 24 44 -1 -1
99 999 9999 -1 -1 -1 -1 -1 -1 9
Explanation:
Testcase1: 4%10=4. So put 4 in hashtable[4]. Now, 14%10=4, but hashtable[4] is already filled so put 14 in the next slot and so on.
Testcase2: 9%10=9. So put 9 in hashtable[9]. Now, 99%10=9, but hashtable[9] is already filled so put 99 in the (99+1)%10 =0 slot so 99 goes into hashtable[0] and so on., I have written this Solution Code: t = int(input())
for _ in range(t):
n,arrSize = map(int,input().split())
nums = list(map(int,input().split()))
hashSet = [-1]*n
for i in nums:
if hashSet[i%n] == -1:
hashSet[i%n] = i
else:
j = i%n + 1
while j!=i%n:
if hashSet[j%n] == -1:
hashSet[j%n] = i
break
j += 1
if hashSet.count(-1) == 0:
break
print(*hashSet), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
int[] arr=new int[5];
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
String[] s=rd.readLine().split(" ");
int sum=0;
for(int i=0;i<5;i++){
arr[i]=Integer.parseInt(s[i]);
sum+=arr[i];
}
int i=0,j=arr.length-1;
boolean isEmergency=false;
while(i<=j)
{
int temp=arr[i];
sum-=arr[i];
if(arr[i]>= sum)
{
isEmergency=true;
break;
}
sum+=temp;
i++;
}
if(isEmergency==false)
{
System.out.println("Stable");
}
else
{
System.out.println("SPD Emergency");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: arr = list(map(int,input().split()))
m = sum(arr)
f=[]
for i in range(len(arr)):
s = sum(arr[:i]+arr[i+1:])
if(arr[i]<s):
f.append(1)
else:
f.append(0)
if(all(f)):
print("Stable")
else:
print("SPD Emergency"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
vector<int> vect(5);
int tot = 0;
for(int i=0; i<5; i++){
cin>>vect[i];
tot += vect[i];
}
sort(all(vect));
tot -= vect[4];
if(vect[4] >= tot){
cout<<"SPD Emergency";
}
else{
cout<<"Stable";
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given a positive integer K and your task is to print the number of elements in array a[] that are smaller than or equal to K.<b>In case of Java only</b>
<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>smallerElements()</b> that takes the array a[], integer N and integer k as arguments.
<b>Custom Input</b>
The first line of input contains a single integer N.
The second line of input contains N space- separated integers depicting the values of the array.
The third line of input contains a single integer Q, the number of queries.
Each of the next Q lines of input contain a single integer, the value of K.
<b>Constraints:-</b>
1 <= N <= 10<sup>5</sup>
1 <= K, Arr[i] <= 10<sup>12</sup>
1 <= Q <= 10<sup>4</sup>Return the count of elements smaller than or equal to K.Sample Input:-
5
2 5 6 11 15
5
2
4
8
1
16
Sample Output:-
1
1
3
0
5, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int n;
cin>>n;
vector<int> v(n);
FOR(i,n){
cin>>v[i];}
int q;
cin>>q;
int x;
while(q--){
cin>>x;
auto it = upper_bound(v.begin(),v.end(),x);
out(it-v.begin());
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given a positive integer K and your task is to print the number of elements in array a[] that are smaller than or equal to K.<b>In case of Java only</b>
<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>smallerElements()</b> that takes the array a[], integer N and integer k as arguments.
<b>Custom Input</b>
The first line of input contains a single integer N.
The second line of input contains N space- separated integers depicting the values of the array.
The third line of input contains a single integer Q, the number of queries.
Each of the next Q lines of input contain a single integer, the value of K.
<b>Constraints:-</b>
1 <= N <= 10<sup>5</sup>
1 <= K, Arr[i] <= 10<sup>12</sup>
1 <= Q <= 10<sup>4</sup>Return the count of elements smaller than or equal to K.Sample Input:-
5
2 5 6 11 15
5
2
4
8
1
16
Sample Output:-
1
1
3
0
5, I have written this Solution Code: static int smallerElements(int a[], int n, int k){
int l=0;
int h=n-1;
int m;
int ans=n;
while(l<=h){
m=l+h;
m/=2;
if(a[m]<=k){
l=m+1;
}
else{
h=m-1;
ans=m;
}
}
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T — the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, — the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=0;i<T;i++)
{
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
if(a>b && a>c)
{
System.out.println("Alice");
}
else if(b>a && b>c)
{
System.out.println("Bob");
}
else if(c>a && c>b)
{
System.out.println("Charlie");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T — the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, — the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: #include <bits/stdc++.h>
int main() {
int T = 0;
std::cin >> T;
while (T--) {
int A = 0, B = 0, C = 0;
std::cin >> A >> B >> C;
assert(A != B && B != C && C != A);
if (A > B && A > C) {
std::cout << "Alice" << '\n';
} else if (B > A && B > C) {
std::cout << "Bob" << '\n';
} else {
std::cout << "Charlie" << '\n';
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice, Bob and Charlie are bidding for an artifact at an auction. Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct). According to the rules of the auction, the person who bids the highest amount will win the auction. Determine who will win the auction.The first line contains a single integer T — the number of test cases. Then the test cases follow.
The first and only line of each test case contains three integers A, B, and C, — the amount bid by Alice, Bob, and Charlie respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, B, C ≤ 1000
A, B, and C are distinct.For each test case, output who (out of Alice, Bob, and Charlie) will win the auction.Sample Input :
4
200 100 400
155 1000 566
736 234 470
124 67 2
Sample Output :
Charlie
Bob
Alice
Alice
Explanation :
<ul>
<li>Charlie wins the auction since he bid the highest amount. </li>
<li>Bob wins the auction since he bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
<li>Alice wins the auction since she bid the highest amount. </li>
</ul>, I have written this Solution Code: T = int(input())
for i in range(T):
A,B,C = list(map(int,input().split()))
if A>B and A>C:
print("Alice")
elif B>A and B>C:
print("Bob")
else:
print("Charlie"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, I have written this Solution Code: import math
n=int(input())
count=0
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
if (n / i == i) :
count=count+1
else:
count=count+2
i = i + 1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
int ans = 0;
for(int i=1; i*i<n; i++){
if(n%i == 0){
ans += 2;
}
}
int nn = sqrt(n);
if(nn*nn == n) {
ans++;
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Saloni has recently distributed N chocolates to some kids. She does not remember the number of kids she distributed the chocolates to. But she knows for sure that she did not break any chocolate while distributing. Can you tell her the number of possible values for the number of children?The first and the only line of input contains an integer N.
Constraints
1 <= N <= 10<sup>12</sup>Output a single integer, the number of possible values for the number of children.Sample Input
6
Sample Output
4
Explanation: The possible values for the number of children are 1, 2, 3, and 6.
Sample Input
10
Sample Output
4, I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
long num = sc.nextLong();
System.out.println(possibleValues(num));
}
static int possibleValues(long num)
{
int ans = 0;
for(int i = 1; (long)i*i < num; i++)
{
if(num%i == 0)
ans += 2;
}
int nn = (int)Math.sqrt(num);
if((long)(nn*nn) == num)
ans++;
return ans;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){cout<<"FizzBuzz"<<" ";}
else if(i%5==0){cout<<"Buzz ";}
else if(i%3==0){cout<<"Fizz ";}
else{cout<<i<<" ";}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, 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 x= sc.nextInt();
fizzbuzz(x);
}
static void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");}
else if(i%5==0){System.out.print("Buzz ");}
else if(i%3==0){System.out.print("Fizz ");}
else{System.out.print(i+" ");}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: def fizzbuzz(n):
for i in range (1,n+1):
if (i%3==0 and i%5==0):
print("FizzBuzz",end=' ')
elif i%3==0:
print("Fizz",end=' ')
elif i%5==0:
print("Buzz",end=' ')
else:
print(i,end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){printf("FizzBuzz ");}
else if(i%5==0){printf("Buzz ");}
else if(i%3==0){printf("Fizz ");}
else{printf("%d ",i);}
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a binary tree rooted at 1. You have to find the mirror image of any node qi about node 1. If it doesn't exist then print -1. Consider the mirror to be a vertical plane at node 1.
Node 1 is considered to be a mirror image of itself.First line contains the integer N and Q, denoting the number of nodes in the binary tree and the number of queries respectively.
Next N lines contains two integers denoting the left and right child of the i-th node respectively.
If the node doesn't have a left or right child, it is denoted by '-1'
Next Q lines contains a single integer q[i]
Constraints:
1 <= N <= 10^3
1<= Q <= 10^3For each query print in a separate line the mirror image of the node if it exists, otherwise print -1.Sample Input 1:
7 4
2 4
5 3
-1 -1
-1 7
6 -1
-1 -1
-1 -1
2
5
3
1
Sample output 1:
4
7
-1
1
Explanation: Given binary tree
1
/ \
2 4
/ \ \
5 3 7
/
6
Query 1: mirror image of node 2 is node 4
Query 2: mirror image of node 5 is node 7
Query 3: mirror image of node 3 is the left child of node 4, but since there is no left child, print -1
Query 4: mentioned in statement, I have written this Solution Code: import java.io.*;
import java.util.*;
class Node {
Node leftChild;
Node rightChild;
int data;
Node() {
}
Node(int data) {
this.data = data;
this.leftChild = null;
this.rightChild = null;
}
}
class Main {
public static int cal(int number, Node leftPointer, Node rightPointer) {
if(leftPointer == null || rightPointer == null) {
return -1;
}
if(number == leftPointer.data) {
return rightPointer.data;
}
if(number == rightPointer.data) {
return leftPointer.data;
}
int foundFlag = cal(number, leftPointer.leftChild, rightPointer.rightChild);
if(foundFlag != -1) {
return foundFlag;
}
return cal(number, leftPointer.rightChild, rightPointer.leftChild);
}
public static int mirror(int number, Node root) {
if((root.leftChild == null && root.rightChild == null) || root.data == number) {
return 1;
}
return cal(number, root.leftChild, root.rightChild);
}
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str1[] = br.readLine().split(" ");
int nodes = Integer.parseInt(str1[0]);
int queries = Integer.parseInt(str1[1]);
Map<Integer, Node> map = new HashMap();
Node root = new Node(1);
root.leftChild = null;
root.rightChild = null;
map.put(1, root);
for(int j = 1; j <= nodes; j++){
String str[] = br.readLine().split(" ");
int leftChild = Integer.parseInt(str[0]);
int rightChild = Integer.parseInt(str[1]);
Node leftNode = new Node(leftChild);
Node rightNode = new Node(rightChild);
Node parent = map.get(j);
parent.leftChild = leftChild == -1 ? null : leftNode;
parent.rightChild = rightChild == -1 ? null : rightNode;
if(leftChild != -1) {
map.put(leftChild, leftNode);
}
if(rightChild != -1) {
map.put(rightChild, rightNode);
}
}
for(int i = 0; i < queries; i++) {
int number = Integer.parseInt(br.readLine());
System.out.println(mirror(number, root));
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a binary tree rooted at 1. You have to find the mirror image of any node qi about node 1. If it doesn't exist then print -1. Consider the mirror to be a vertical plane at node 1.
Node 1 is considered to be a mirror image of itself.First line contains the integer N and Q, denoting the number of nodes in the binary tree and the number of queries respectively.
Next N lines contains two integers denoting the left and right child of the i-th node respectively.
If the node doesn't have a left or right child, it is denoted by '-1'
Next Q lines contains a single integer q[i]
Constraints:
1 <= N <= 10^3
1<= Q <= 10^3For each query print in a separate line the mirror image of the node if it exists, otherwise print -1.Sample Input 1:
7 4
2 4
5 3
-1 -1
-1 7
6 -1
-1 -1
-1 -1
2
5
3
1
Sample output 1:
4
7
-1
1
Explanation: Given binary tree
1
/ \
2 4
/ \ \
5 3 7
/
6
Query 1: mirror image of node 2 is node 4
Query 2: mirror image of node 5 is node 7
Query 3: mirror image of node 3 is the left child of node 4, but since there is no left child, print -1
Query 4: mentioned in statement, I have written this Solution Code: n,q=map(int,(input().split()))
l=[-1]*(n+1)
r=[-1]*(n+1)
l[0]=1
r[0]=1
for i in range(1,n+1):
a,b=map(int,input().split())
l[i]=a
r[i]=b
def find(target,left,right):
if left==-1 and right==-1:
return False
if left==target:
print(right)
return True
if right==target:
print(left)
return True
if left!=-1 and right!=-1:
return find(target,l[left],r[right]) or find(target,r[left],l[right])
return False
for i in range(q):
temp=int(input())
if temp==1:
print(1)
elif not find(temp,l[1],r[1]):
print(-1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a binary tree rooted at 1. You have to find the mirror image of any node qi about node 1. If it doesn't exist then print -1. Consider the mirror to be a vertical plane at node 1.
Node 1 is considered to be a mirror image of itself.First line contains the integer N and Q, denoting the number of nodes in the binary tree and the number of queries respectively.
Next N lines contains two integers denoting the left and right child of the i-th node respectively.
If the node doesn't have a left or right child, it is denoted by '-1'
Next Q lines contains a single integer q[i]
Constraints:
1 <= N <= 10^3
1<= Q <= 10^3For each query print in a separate line the mirror image of the node if it exists, otherwise print -1.Sample Input 1:
7 4
2 4
5 3
-1 -1
-1 7
6 -1
-1 -1
-1 -1
2
5
3
1
Sample output 1:
4
7
-1
1
Explanation: Given binary tree
1
/ \
2 4
/ \ \
5 3 7
/
6
Query 1: mirror image of node 2 is node 4
Query 2: mirror image of node 5 is node 7
Query 3: mirror image of node 3 is the left child of node 4, but since there is no left child, print -1
Query 4: mentioned in statement, I have written this Solution Code: #include "bits/stdc++.h"
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 = 1e3 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int l[N], r[N], p[N];
void solve(){
int n, q;
cin >> n >> q;
for(int i = 1; i <= n; i++){
cin >> l[i] >> r[i];
if(l[i] != -1) p[l[i]] = i;
if(r[i] != -1) p[r[i]] = i;
}
while(q--){
vector<int> v;
int x; cin >> x;
while(x != 1){
if(l[p[x]] == x)
v.push_back(1);
else
v.push_back(0);
x = p[x];
}
reverse(v.begin(), v.end());
for(auto i: v){
if(x == -1) break;
if(i == 0){
if(l[x] == -1){
x = l[x];
break;
}
x = l[x];
}
else{
if(r[x] == -1){
x = r[x];
break;
}
x = r[x];
}
}
cout << x << endl;;
}
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
} , In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
int n;
while(t>0) {
n = Integer.parseInt(br.readLine());
int a[] = new int[n];
String s = br.readLine();
String arr[] = s.split(" ");
for(int i=0;i<n;i++) {
a[i] = Integer.parseInt(arr[i]);
}
int b[] = sort(a);
for(int i=0;i<n;i++) {
System.out.print(b[i] + " ");
}
System.out.println();
t--;
}
}
static int[] sort(int[] a) {
int temp, index;
for(int i=0;i<a.length-1;i++) {
index = i;
for(int j=i+1;j<a.length;j++) {
if(a[j]<a[index]) {
index = j;
}
}
temp = a[i];
a[i] = a[index];
a[index] = temp;
}
return a;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: for _ in range(int(input())):
n = input()
res = map(str, sorted(list( map(int,input().split()))))
print(' '.join(res)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You went to shopping. You bought an item worth N rupees. What is the minimum change that you can get from the shopkeeper if you possess only 200 and 500 rupees notes.
Eg: If N = 678, the minimum change you can receive is 22, if you pay the shopkeeper a 500 and a 200 rupee note. You can show that no other combination can lead to a change lesser than this like (200, 200, 200, 200) or (500, 500).
Note: You have infinite number of 200 and 500 rupees notes. Enjoy, XD.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000000000Output a single integer, the minimum amount of change that you will receive.Sample Input
678
Sample Output
22
Sample Input
900
Sample Output
0, I have written this Solution Code: def sample(n):
if n<200:
print(200-n)
elif n<400:
print(400-n)
elif n<500:
print(500-n)
else:
div=n//100
if div*100==n:
print(0)
else:
print((div+1)*100-n)
n=int(input())
sample(n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You went to shopping. You bought an item worth N rupees. What is the minimum change that you can get from the shopkeeper if you possess only 200 and 500 rupees notes.
Eg: If N = 678, the minimum change you can receive is 22, if you pay the shopkeeper a 500 and a 200 rupee note. You can show that no other combination can lead to a change lesser than this like (200, 200, 200, 200) or (500, 500).
Note: You have infinite number of 200 and 500 rupees notes. Enjoy, XD.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000000000Output a single integer, the minimum amount of change that you will receive.Sample Input
678
Sample Output
22
Sample Input
900
Sample Output
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define 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;
if(n <= 200){
cout<<200-n;
return;
}
if(n <= 400){
cout<<400-n;
return;
}
int ans = (100-n%100)%100;
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: You went to shopping. You bought an item worth N rupees. What is the minimum change that you can get from the shopkeeper if you possess only 200 and 500 rupees notes.
Eg: If N = 678, the minimum change you can receive is 22, if you pay the shopkeeper a 500 and a 200 rupee note. You can show that no other combination can lead to a change lesser than this like (200, 200, 200, 200) or (500, 500).
Note: You have infinite number of 200 and 500 rupees notes. Enjoy, XD.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000000000Output a single integer, the minimum amount of change that you will receive.Sample Input
678
Sample Output
22
Sample Input
900
Sample Output
0, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int ans=0;
if(n <= 200){
ans = 200-n;
}
else if(n <= 400){
ans=400-n;
}
else{
ans = (100-n%100)%100;
}
System.out.print(ans);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[ ] of size N containing positive integers, find maximum and minimum elements from the array.The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows. The first line of each testcase contains a single integer N denoting the size of array. The second line contains N space-separated integers denoting the elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^7For each testcase you need to print the maximum and minimum element found separated by space.Sample Input:
2
5
7 3 4 5 6
4
1 2 3 4
Sample Output:
7 3
4 1
, I have written this Solution Code: def solve(a):
maxi = 0
mini = 1e7+1
for i in a:
if(i < mini):
mini = i
if(i > maxi):
maxi = i
return mini,maxi, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[ ] of size N containing positive integers, find maximum and minimum elements from the array.The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows. The first line of each testcase contains a single integer N denoting the size of array. The second line contains N space-separated integers denoting the elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^7For each testcase you need to print the maximum and minimum element found separated by space.Sample Input:
2
5
7 3 4 5 6
4
1 2 3 4
Sample Output:
7 3
4 1
, I have written this Solution Code:
import java.io.*;
import java.util.*;
class Main
{
public static void main(String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while (t-- > 0) {
int n = Integer.parseInt(read.readLine());
int[] arr = new int[n];
String str[] = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
findMinMax(arr, n);
System.out.println();
}
}
public static void findMinMax(int arr[], int n)
{
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for(int i = 0; i < n; i++)
{
min = Math.min(arr[i], min);
max = Math.max(arr[i], max);
}
System.out.print(max + " " + min);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b>
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>9</sup>Print the integer N.Sample Input:-
3
Sample Output:
3
Sample Input:
56
Sample Output:
56, I have written this Solution Code: static void printInteger(int N){
System.out.println(N);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b>
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>9</sup>Print the integer N.Sample Input:-
3
Sample Output:
3
Sample Input:
56
Sample Output:
56, I have written this Solution Code: void printInteger(int x){
printf("%d", x);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b>
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>9</sup>Print the integer N.Sample Input:-
3
Sample Output:
3
Sample Input:
56
Sample Output:
56, I have written this Solution Code: void printIntger(int n)
{
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b>
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>9</sup>Print the integer N.Sample Input:-
3
Sample Output:
3
Sample Input:
56
Sample Output:
56, I have written this Solution Code: n=int(input())
print (n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Take an integer as input and print it.The first line contains integer as input.
<b>Constraints</b>
1 <= N <= 10Print the input integer in a single lineSample Input:-
2
Sample Output:-
2
Sample Input:-
4
Sample Output:-
4, I have written this Solution Code: /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void printVariable(int variable){
System.out.println(variable);
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
printVariable(num);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John is confused about the number of ways to propose to Olivia. So, he asked for your help. Now, you need to determine the number of ways for John to propose to Olivia.
For that, You are given an integer N and you need to count the number of pairs (x<sub>1</sub>, x<sub>2</sub>) such that x<sub>1</sub><sup>2</sup> + x<sub>2</sub><sup>2</sup> = N and x<sub>1</sub>, x<sub>2</sub> both are positive integer.The first line contains a single integer T, the number of test cases.
T lines follow. Each line describes a single test case and contains a single integer N.
<b>Constraints:</b>
1 <= T <= 100
2 <= N <= 10<sup>5</sup>For each test case, print a single integer count of such pairs.Sample Input 1:
2
13
4
Sample Output 2:
2
0, 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>;
using cd = complex<double>;
const double PI = acos(-1);
// 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;
// DEBUG FUNCTIONS
#ifndef ONLINE_JUDGE
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
void solve(){
ll n; cin >> n;
ll ans = 0;
for(ll i = 1;i*i<n;i++){
ll x = sqrt(n - i*i);
if(x*x + i*i == n){
ans++;
}
}
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// cout.tie(NULL);
#ifdef LOCALFLAG
freopen("input.txt", "r", stdin);
freopen("output.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: Given a linked list consisting of <b>L</b> nodes and given a number <b>N</b>. The task is to find the Nth node from the end of the linked list.First line of input contains number of testcase T. For each testcase, first line of input contains number of nodes in the linked list L and the number N. Next line contains N nodes of linked list.
<b>User Task:</b>
The task is to complete the function <b>getNthFromLast()</b> which takes two arguments: reference to head and N and you need to return Nth from end.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= L <= 10^3
For each testcase, output the data of node which is at Nth distance from end.Input:
2
9 2
1 2 3 4 5 6 7 8 9
4 5
10 5 100 5
Output:
8
-1
Explanation:
Testcase 1: In the first example, there are 9 nodes in linked list and we need to find 2nd node from end. 2nd node from end os 8.
Testcase 2: In the second example, there are 4 nodes in linked list and we need to find 5th from end. Since 'n' is more than number of nodes in linked list, output is -1., I have written this Solution Code: static int getNthFromLast(Node head, int n)
{
int len = 0;
Node temp = head;
while(temp != null) // Traverse temp throught the linked list and find the length
{
temp = temp.next;
len++;
}
if(len < n)
return -1;
//System.out.println(count);
//int r = count - n;
temp = head;
for(int i=1; i<len-n+1; i++) // Traverse the node till the position from begining: length - n +1.
temp = temp.next;
return temp.data;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: static void simpleSum(int a, int b, int c){
System.out.println(a+b+c);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: void simpleSum(int a, int b, int c){
cout<<a+b+c;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: x = input()
a, b, c = x.split()
a = int(a)
b = int(b)
c = int(c)
print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: static int MagicKnight(int N, int T){
while(T-->0){
N/=2;
N+=2;
if(N==3 || N==4){return N;}
}
return N;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: long MagicKnight(long N, long T){
while(T--){
N/=2;
N+=2;
if(N==3 || N==4){return N;}
}
return N;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: def MagicKnight(N,T):
while T > 0:
N = N//2
N = N+2
if N == 3 or N ==4:
return N
T = T - 1
return N
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: long MagicKnight(long N, long T){
while(T--){
N/=2;
N+=2;
if(N==3 || N==4){return N;}
}
return N;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: def DivisorProblem(N):
ans=0
while N>1:
cnt=2
while N%cnt!=0:
cnt=cnt+1
N = N//cnt
ans=ans+1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: static int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Your task is to implement a stack using a linked list and perform given queries
Note:-if stack is already empty than pop operation will do nothing and 0 will be printed as a top element of stack if it is empty.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 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>You don't need to print anything else other than in top function in which you require to print the top most element of your stack in a new line, if the stack is empty you just need to print 0.Input:
7
push 1
push 2
top
pop
top
pop
top
Output:
2
1
0
, I have written this Solution Code:
Node top = null;
public void push(int x)
{
Node temp = new Node(x);
temp.next = top;
top = temp;
}
public void pop()
{
if (top == null) {
}
else {
top = (top).next;}
}
public void top()
{
// check for stack underflow
if (top == null) {
System.out.println("0");
}
else {
Node temp = top;
System.out.println(temp.val);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, 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 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().split(" ");
int N = Integer.parseInt(s[0]);
int M = Integer.parseInt(s[1]);
s = br.readLine().split(" ");
int[] prefix = new int[N];
int preSum = 0;
for(int i=0; i<N; i++){
int curr = Integer.parseInt(s[i]);
preSum += curr;
prefix[i] = preSum;
}
if(M>=prefix[N-1]){
System.out.println(prefix[N-1]);
return;
}
int maxSum = 0;
for(int i=0; i<N; i++){
for(int j=0; j<i; j++){
int curr = prefix[i]%M;
maxSum = Math.max(maxSum, curr);
curr = (prefix[i]-prefix[j])%M;
maxSum = Math.max(maxSum, curr);
if(maxSum==M-1){
break;
}
}
}
System.out.println(maxSum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, 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 an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc =new Scanner(System.in);
int T= sc.nextInt();
for(int i=0;i<T;i++){
int arrsize=sc.nextInt();
int max=0,secmax=0,thirdmax=0,j;
for(int k=0;k<arrsize;k++){
j=sc.nextInt();
if(j>max){
thirdmax=secmax;
secmax=max;
max=j;
}
else if(j>secmax){
thirdmax=secmax;
secmax=j;
}
else if(j>thirdmax){
thirdmax=j;
}
if(k%10000==0){
System.gc();
}
}
System.out.println(max+" "+secmax+" "+thirdmax+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.