Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code: def OccurenceOfX(N,X):
cnt=0
for i in range(1, N+1):
if(X%i==0 and X/i<=N):
cnt=cnt+1
return cnt, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code:
int OccurenceOfX(int N,long X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code:
int OccurenceOfX(int N,long X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}
int main()
{
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code: public static int OccurenceOfX(int N,int X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For an integer N, your task is to calculate sum of first N natural numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to worry about input. You just have to complete the function <b>sum()</b> which takes the integer N as a parameter.
Constraints:
1 <= N < = 100000000Print the sum of first N natural numbers.Sample Input:-
5
Sample Output:-
15
Sample Input:-
3
Sample Output:-
6, I have written this Solution Code:
static void sum(int N){
long x=N;
x=x*(x+1);
x=x/2;
System.out.print(x);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list consisting of N nodes, your task is to delete every kth Node from the circular linked list until only one node is left. Also, print the intermediate lists
<b>Note:
Sample Input and Output just show how a linked list will look depending on the questions. Do not copy-paste as it is in custom input</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>deleteK()</b> that takes head node of circular linked list and the integer K as parameter.
Constraints:
1 <= K <= N <= 500
1 <= Node. data<= 1000Print the intermediate nodes until one node is left as shown in example.Sample Input:-
4 2
1 2 3 4
Sample Output:-
1->2->3->4->1
1->2->4->1
2->4->2
2->2
Sample Input:-
9 4
1 2 3 4 5 6 7 8 9
Sample Output:-
1->2->3->4->5->6->7->8->9->1
1->2->3->4->6->7->8->9->1
1->2->3->4->6->7->8->1
1->2->3->6->7->8->1
2->3->6->7->8->2
2->3->6->8->2
2->3->8->2
2->3->2
2->2, I have written this Solution Code: static void printList(Node head)
{
if (head == null)
return;
Node temp = head;
do
{
System.out.print( temp.data + "->");
temp = temp.next;
}
while (temp != head);
System.out.println(head.data );
}
/*Function to delete every kth Node*/
static Node deleteK(Node head_ref, int k)
{
Node head = head_ref;
// If list is empty, simply return.
if (head == null)
return null;
// take two pointers - current and previous
Node curr = head, prev=null;
while (true)
{
// Check if Node is the only Node\
// If yes, we reached the goal, therefore
// return.
if (curr.next == head && curr == head)
break;
// Print intermediate list.
printList(head);
// If more than one Node present in the list,
// Make previous pointer point to current
// Iterate current pointer k times,
// i.e. current Node is to be deleted.
for (int i = 0; i < k; i++)
{
prev = curr;
curr = curr.next;
}
// If Node to be deleted is head
if (curr == head)
{
prev = head;
while (prev.next != head)
prev = prev.next;
head = curr.next;
prev.next = head;
head_ref = head;
}
// If Node to be deleted is last Node.
else if (curr.next == head)
{
prev.next = head;
}
else
{
prev.next = curr.next;
}
}
return head;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer <b>N</b> and <b>Q</b> queries. For every query, you will be given <b>start</b> and <b>end</b> point and a positive integer <b>K</b> which is going to be added to the numbers in the range(from start to end) as per query. Once you are done with all the queries, you need to print the maximum number obtained after updation.
Note:-Initially the array is-<b> 1,2,3,....N </b>First line of input contains number of testcases T. For each testcase, first line contains N and Q( number of queries). Q lines after this will contain three integers each line has start, end and K, where start is the starting index of the range, end is the ending index of the range and K is the value to add with the elements in the range.
<b>Note:</b> Array is 1-based index
<b>Constraints:</b>
1 <= T <= 100
1 <= N, K <= 10^5
1 <= Q <= 10^5
1 <= start <= end <= N
Sum of N, Q for every test case is less than or equal to 10^5For each testcase, you need to print the maximum.Input:
1
5 3
1 2 5
2 5 10
3 4 5
Output:
19
Explanation:
Testcase 1: After the queries, we have elements added in the given ranges, so updated numbers from 1 to 5 will be as 6, 17, 18, 19, 15. Thus maximum after updation comes as19., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void abc(int[] a,int s,int e,int k)
{
for(int i=s;i<e;i++)
a[i]+=k;
}
public static void main (String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
for(int z=0;z<t;z++)
{
String[] s=br.readLine().split(" ");
int n=Integer.parseInt(s[0]);
int q=Integer.parseInt(s[1]);
int[] arr=new int[n];
for(int i=0;i<n;i++)
arr[i]=i+1;
for(int i=0;i<q;i++)
{
String[] ss=br.readLine().split(" ");
int st=Integer.parseInt(ss[0]);
int en=Integer.parseInt(ss[1]);
int k=Integer.parseInt(ss[2]);
abc(arr,st-1,en,k);
}
int max=-9999999;
for(int i=0;i<n;i++)
{
if(arr[i]>max)
max=arr[i];
}
System.out.println(max);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer <b>N</b> and <b>Q</b> queries. For every query, you will be given <b>start</b> and <b>end</b> point and a positive integer <b>K</b> which is going to be added to the numbers in the range(from start to end) as per query. Once you are done with all the queries, you need to print the maximum number obtained after updation.
Note:-Initially the array is-<b> 1,2,3,....N </b>First line of input contains number of testcases T. For each testcase, first line contains N and Q( number of queries). Q lines after this will contain three integers each line has start, end and K, where start is the starting index of the range, end is the ending index of the range and K is the value to add with the elements in the range.
<b>Note:</b> Array is 1-based index
<b>Constraints:</b>
1 <= T <= 100
1 <= N, K <= 10^5
1 <= Q <= 10^5
1 <= start <= end <= N
Sum of N, Q for every test case is less than or equal to 10^5For each testcase, you need to print the maximum.Input:
1
5 3
1 2 5
2 5 10
3 4 5
Output:
19
Explanation:
Testcase 1: After the queries, we have elements added in the given ranges, so updated numbers from 1 to 5 will be as 6, 17, 18, 19, 15. Thus maximum after updation comes as19., I have written this Solution Code: tc=int(input())
while(tc>0):
n,q=[int(i) for i in input().split()]
li=[0]*(n+1);
while(q>0):
a,b,k=[int(i) for i in input().split()]
li[a-1]+=k
li[b]-=k
q-=1
m=0
for i in range(1,n):
li[i]+=li[i-1]
for i in range(0,n):
if(li[i]+i+1>m):
m=li[i]+i+1
print(m)
tc-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer <b>N</b> and <b>Q</b> queries. For every query, you will be given <b>start</b> and <b>end</b> point and a positive integer <b>K</b> which is going to be added to the numbers in the range(from start to end) as per query. Once you are done with all the queries, you need to print the maximum number obtained after updation.
Note:-Initially the array is-<b> 1,2,3,....N </b>First line of input contains number of testcases T. For each testcase, first line contains N and Q( number of queries). Q lines after this will contain three integers each line has start, end and K, where start is the starting index of the range, end is the ending index of the range and K is the value to add with the elements in the range.
<b>Note:</b> Array is 1-based index
<b>Constraints:</b>
1 <= T <= 100
1 <= N, K <= 10^5
1 <= Q <= 10^5
1 <= start <= end <= N
Sum of N, Q for every test case is less than or equal to 10^5For each testcase, you need to print the maximum.Input:
1
5 3
1 2 5
2 5 10
3 4 5
Output:
19
Explanation:
Testcase 1: After the queries, we have elements added in the given ranges, so updated numbers from 1 to 5 will be as 6, 17, 18, 19, 15. Thus maximum after updation comes as19., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
int a[n+1];
for(int i=0;i<=n;i++){
a[i]=0;
}
int x,y,p;
while(k--){
cin>>x>>y>>p;
x--;
a[x]+=p;
a[y]-=p;
}
long long sum=0,ans=0;
for(int i=0;i<n;i++){
sum+=a[i];
ans=max(sum+i+1,ans);
}
cout<<ans<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The question is super small and super simple.
You are given an integer n. Initially you have an empty string. You need to construct the string of length n with the following rules:
1. Insert the first character in the beginning of string, the second in the end, the third in the beginning, fourth in the end, and so on.
2. The first character should be 'a', followed by 'b', 'c', and so on. 'z' will be followed by 'a'.The first and the only line of input contains a single number n.
Constraints
1 <= n <= 500000Output the generated string.Sample Input
4
Sample Output
cabd
Sample Input
30
Sample Output
caywusqomkigecabdfhjlnprtvxzbd
Explanation
In the first case the string transforms as follows: "" -> "a" -> "ab" -> "cab" -> "cabd", I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader scan=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(scan.readLine());
char ch='a';
boolean isFirst = true;
StringBuilder sb = new StringBuilder();
for(int i=0;i<n;i++)
{
if(isFirst) {
sb.insert(0, (char)(ch + i%26));
} else {
sb.append((char) (ch + i%26));
}
isFirst = !isFirst;
}
System.out.print(sb.toString());
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The question is super small and super simple.
You are given an integer n. Initially you have an empty string. You need to construct the string of length n with the following rules:
1. Insert the first character in the beginning of string, the second in the end, the third in the beginning, fourth in the end, and so on.
2. The first character should be 'a', followed by 'b', 'c', and so on. 'z' will be followed by 'a'.The first and the only line of input contains a single number n.
Constraints
1 <= n <= 500000Output the generated string.Sample Input
4
Sample Output
cabd
Sample Input
30
Sample Output
caywusqomkigecabdfhjlnprtvxzbd
Explanation
In the first case the string transforms as follows: "" -> "a" -> "ab" -> "cab" -> "cabd", I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 100005;
// it's swapnil07 ;)
#ifdef SWAPNIL07
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define end_routine()
#endif
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int n; cin>>n;
deque<char> vect;
int cur = 0;
bool fl = false;
for(int i=0; i<n; i++){
if(!fl)
vect.push_front('a'+cur);
else
vect.push_back('a'+cur);
cur = (cur+1)%26;
fl = !fl;
}
while(!vect.empty()){
char c = vect.front();
vect.pop_front();
cout<<c;
}
// end_routine();
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Olivia likes triangles. Hence, John decided to give her three integers and ask whether a triangle with edge length as given three integers is possible.
Help Olivia in answering it.The input consists of a single line containing three space-separated integers A, B, and C.
<b>Constraints </b>
1 <= A, B, C <= 100Output "Yes" if the triangle is possible otherwise, "No" (without quotes).Sample Input 1:
5 3 4
Sample Output 1:
Yes
Sample Explanation 1:
The possible triangle is a right-angled triangle with a hypotenuse of 5., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int a, b, c;
cin >> a >> b >> c;
if(a<(b+c) && b<(c+a) && c<(a+b)){
cout << "Yes\n";
}else{
cout << "No\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice has Q queries for you. If you can solve all her queries, she will invite you to participate in a fireworks display with her.
In each query, she gives you a positive integer N, and you have to find the number of positive integers M such that M × d(M) = N.
Here, d(M) refers to the sum of all digits of M. For example, d(1023) = 6.The first line consists of a single integer Q – the number of queries.
Then Q lines follow, each line containing a single integer N denoting a query.
<b> Constraints: </b>
1 ≤ Q ≤ 1000
1 ≤ N ≤ 10<sup>18</sup>Print Q lines, the i<sup>th</sup> line containing the answer to the i<sup>th</sup> query.Sample Input 1:
3
1
6
36
Sample Output 1:
1
0
2
Sample Explanation 1:
For the first query, the only possibility is 1.
For the third query, the only possibilities are 6 and 12., I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
private static final int START_TEST_CASE = 1;
public static void solveCase(FastIO io, int testCase) {
final long N = io.nextLong();
int count = 0;
for (int i = 1; i <= 200; ++i) {
if (N % i == 0) {
long j = N / i;
if (digitSum(j) == i) {
++count;
}
}
}
io.println(count);
}
private static long digitSum(long x) {
long s = 0;
while (x > 0) {
s += x % 10;
x /= 10;
}
return s;
}
public static void solve(FastIO io) {
final int T = io.nextInt();
for (int t = 0; t < T; ++t) {
solveCase(io, START_TEST_CASE + t);
}
}
public static class FastIO {
private InputStream reader;
private PrintWriter writer;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastIO(InputStream r, OutputStream w) {
reader = r;
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = reader.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
return Double.parseDouble(nextString());
}
public int[] nextIntArray(int n) {
return nextIntArray(n, 0);
}
public int[] nextIntArray(int n, int off) {
int[] arr = new int[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
return nextLongArray(n, 0);
}
public long[] nextLongArray(int n, int off) {
long[] arr = new long[n + off];
for (int i = 0; i < n; i++) {
arr[i + off] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printArray(long[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(arr[i]);
}
}
public void printlnArray(int[] arr) {
printArray(arr);
writer.println();
}
public void printlnArray(long[] arr) {
printArray(arr);
writer.println();
}
public void printf(String format, Object... args) {
print(String.format(format, args));
}
public void flush() {
writer.flush();
}
}
private static class Solution implements Runnable {
@Override
public void run() {
FastIO io = new FastIO(System.in, System.out);
solve(io);
io.flush();
}
}
public static void main(String[] args) throws InterruptedException {
Thread t = new Thread(null, new Solution(), "Solution", 1 << 30);
t.start();
t.join();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice has Q queries for you. If you can solve all her queries, she will invite you to participate in a fireworks display with her.
In each query, she gives you a positive integer N, and you have to find the number of positive integers M such that M × d(M) = N.
Here, d(M) refers to the sum of all digits of M. For example, d(1023) = 6.The first line consists of a single integer Q – the number of queries.
Then Q lines follow, each line containing a single integer N denoting a query.
<b> Constraints: </b>
1 ≤ Q ≤ 1000
1 ≤ N ≤ 10<sup>18</sup>Print Q lines, the i<sup>th</sup> line containing the answer to the i<sup>th</sup> query.Sample Input 1:
3
1
6
36
Sample Output 1:
1
0
2
Sample Explanation 1:
For the first query, the only possibility is 1.
For the third query, the only possibilities are 6 and 12., I have written this Solution Code:
q = int(input())
for _ in range(q):
n = int(input())
count = 0
for i in range(1,9*len(str(n))):
if not n % i:
dig = n//i
if sum(map(int,str(dig))) == i:
count += 1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice has Q queries for you. If you can solve all her queries, she will invite you to participate in a fireworks display with her.
In each query, she gives you a positive integer N, and you have to find the number of positive integers M such that M × d(M) = N.
Here, d(M) refers to the sum of all digits of M. For example, d(1023) = 6.The first line consists of a single integer Q – the number of queries.
Then Q lines follow, each line containing a single integer N denoting a query.
<b> Constraints: </b>
1 ≤ Q ≤ 1000
1 ≤ N ≤ 10<sup>18</sup>Print Q lines, the i<sup>th</sup> line containing the answer to the i<sup>th</sup> query.Sample Input 1:
3
1
6
36
Sample Output 1:
1
0
2
Sample Explanation 1:
For the first query, the only possibility is 1.
For the third query, the only possibilities are 6 and 12., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
// #pragma gcc optimize("ofast")
// #pragma gcc target("avx,avx2,fma")
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
#define fi first
#define se second
// const int mod = 1e9 + 7;
const int mod=998'244'353;
const long long INF = 2e18 + 10;
// const int INF=4e9+10;
#define readv(x, n) \
vector<int> x(n); \
for (auto &i : x) \
cin >> i;
template <typename t>
using v = vector<t>;
template <typename t>
using vv = vector<vector<t>>;
template <typename t>
using vvv = vector<vector<vector<t>>>;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<vector<int>>>> vvvvi;
typedef vector<vector<double>> vvd;
typedef pair<int, int> pii;
int multiply(int a, int b, int in_mod) { return (int)(1ll * a * b % in_mod); }
int mult_identity(int a) { return 1; }
const double pi = acosl(-1);
vector<vector<int> > multiply(vector<vector<int>> a, vector<vector<int>> b, int in_mod)
{
int n = a.size();
int l = b.size();
int m = b[0].size();
vector<vector<int> > result(n,vector<int>(n));
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
for(int k=0;k<l;k++)
{
result[i][j] = (result[i][j] + a[i][k]*b[k][j])%in_mod;
}
}
}
return result;
}
vector<vector<int>> operator%(vector<vector<int>> a, int in_mod)
{
for(auto &i:a)
for(auto &j:i)
j%=in_mod;
return a;
}
vector<vector<int>> mult_identity(vector<vector<int>> a)
{
int n=a.size();
vector<vector<int>> output(n, vector<int> (n));
for(int i=0;i<n;i++)
output[i][i]=1;
return output;
}
vector<int> mat_vector_product(vector<vector<int>> a, vector<int> b, int in_mod)
{
int n =a.size();
vector<int> output(n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
output[i]+=a[i][j]*b[j];
output[i]%=in_mod;
}
}
return output;
}
auto power(auto a, auto b, const int in_mod)
{
auto prod = mult_identity(a);
auto mult = a % in_mod;
while (b != 0)
{
if (b % 2)
{
prod = multiply(prod, mult, in_mod);
}
if(b/2)
mult = multiply(mult, mult, in_mod);
b /= 2;
}
return prod;
}
auto mod_inv(auto q, const int in_mod)
{
return power(q, in_mod - 2, in_mod);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define stp cout << fixed << setprecision(20);
int digit_sum(int x){
int sm = 0;
while(x){
sm += x%10;
x/= 10;
}
return sm;
}
void solv(){
int n;
cin>>n;
int cnt = 0;
for(int sm = 1;sm<= 200;sm++){
if(n %sm == 0){
if( digit_sum(n/sm) == sm){
cnt++;
}
}
}
cout<<cnt<<endl;
}
void solve()
{
int t = 1;
cin>>t;
for(int T=1;T<=t;T++)
{
// cout<<"Case #"<<T<<": ";
solv();
}
}
signed main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
auto clk = clock();
// -------------------------------------Code starts here---------------------------------------------------------------------
signed t = 1;
// cin >> t;
for (signed test = 1; test <= t; test++)
{
// cout<<"Case #"<<test<<": ";
solve();
}
// -------------------------------------Code ends here------------------------------------------------------------------
clk = clock() - clk;
#ifndef ONLINE_JUDGE
cerr << fixed << setprecision(6) << "\nTime: " << ((float)clk) / CLOCKS_PER_SEC << "\n";
#endif
return 0;
}
/*
000100
1000100
1 0 -1 -2 -1 -2 -3
*/
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: They say friendship is greater than love. Why not play the famous game "FLAMES".
The rules are super simple. Given two strings (all lowercase), remove all the letters that are common to both the strings from both the strings. You cannot erase a character in first string whichever corresponding same character in other string not exist.
For example, in the case
String 1: saumya
String 2: ansh
You can remove only 1 'a' and 1 's' from both the strings.
Remaining strings are:
String 1: umya
String 2: nh
Now all you need to do is find the sum of the remaining strings length % 6.
Output:
If obtained value is 1, output "Friends"
If obtained value is 2, output "Love"
If obtained value is 3, output "Affection"
If obtained value is 4, output "Marriage"
If obtained value is 5, output "Enemy"
If obtained value is 0, output "Siblings"You will be given two strings on different lines.
Constraints
1 <= Length of both the strings <= 100000Output a single string, the result of FLAMES test.Sample Input:-
saumya
ansh
Sample Output:-
Siblings
Explanation:-
after deleting characters :-
str1 = umya
str2 = nh
sum = 4+2
sum%6=0
, 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 str1 = br.readLine();
String str2 = br.readLine();
countCommonCharacters(str1, str2);
}
static void countCommonCharacters(String s1, String s2) {
int[] arr1 = new int[26];
int[] arr2 = new int[26];
for (int i = 0; i < s1.length(); i++)
arr1[s1.codePointAt(i) - 97]++;
for (int i = 0; i < s2.length(); i++)
arr2[s2.codePointAt(i) - 97]++;
int lenToCut = 0;
for (int i = 0; i < 26; i++) {
int leastOccurrence = Math.min(arr1[i], arr2[i]);
lenToCut += (2 * leastOccurrence);
}
System.out.println(findRelation((s1.length() + s2.length() - lenToCut) % 6));
}
static String findRelation(int value) {
switch (value) {
case 1:
return "Friends";
case 2:
return "Love";
case 3:
return "Affection";
case 4:
return "Marriage";
case 5:
return "Enemy";
default:
return "Siblings";
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: They say friendship is greater than love. Why not play the famous game "FLAMES".
The rules are super simple. Given two strings (all lowercase), remove all the letters that are common to both the strings from both the strings. You cannot erase a character in first string whichever corresponding same character in other string not exist.
For example, in the case
String 1: saumya
String 2: ansh
You can remove only 1 'a' and 1 's' from both the strings.
Remaining strings are:
String 1: umya
String 2: nh
Now all you need to do is find the sum of the remaining strings length % 6.
Output:
If obtained value is 1, output "Friends"
If obtained value is 2, output "Love"
If obtained value is 3, output "Affection"
If obtained value is 4, output "Marriage"
If obtained value is 5, output "Enemy"
If obtained value is 0, output "Siblings"You will be given two strings on different lines.
Constraints
1 <= Length of both the strings <= 100000Output a single string, the result of FLAMES test.Sample Input:-
saumya
ansh
Sample Output:-
Siblings
Explanation:-
after deleting characters :-
str1 = umya
str2 = nh
sum = 4+2
sum%6=0
, I have written this Solution Code: name1 = input().strip().lower()
name2 = input().strip().lower()
listA = [0]*26
listB = [0]*26
for i in name1:
listA[ord(i)-ord('a')] = listA[ord(i)-ord('a')] + 1
for i in name2:
listB[ord(i)-ord('a')] = listB[ord(i)-ord('a')] + 1
count = 0
for i in range(0,26):
count = count+abs(listA[i]-listB[i])
res = ["Siblings","Friends","Love","Affection", "Marriage", "Enemy"]
print(res[count%6]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: They say friendship is greater than love. Why not play the famous game "FLAMES".
The rules are super simple. Given two strings (all lowercase), remove all the letters that are common to both the strings from both the strings. You cannot erase a character in first string whichever corresponding same character in other string not exist.
For example, in the case
String 1: saumya
String 2: ansh
You can remove only 1 'a' and 1 's' from both the strings.
Remaining strings are:
String 1: umya
String 2: nh
Now all you need to do is find the sum of the remaining strings length % 6.
Output:
If obtained value is 1, output "Friends"
If obtained value is 2, output "Love"
If obtained value is 3, output "Affection"
If obtained value is 4, output "Marriage"
If obtained value is 5, output "Enemy"
If obtained value is 0, output "Siblings"You will be given two strings on different lines.
Constraints
1 <= Length of both the strings <= 100000Output a single string, the result of FLAMES test.Sample Input:-
saumya
ansh
Sample Output:-
Siblings
Explanation:-
after deleting characters :-
str1 = umya
str2 = nh
sum = 4+2
sum%6=0
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define max1 10000001
int main(){
string s1,s2;
cin>>s1>>s2;
string a[6];
a[1]= "Friends";
a[2]= "Love";
a[3]="Affection";
a[4]= "Marriage";
a[5]= "Enemy";
a[0]= "Siblings";
int b[26],c[26];
for(int i=0;i<26;i++){b[i]=0;c[i]=0;}
for(int i=0;i<s1.length();i++){
b[s1[i]-'a']++;
}
for(int i=0;i<s2.length();i++){
c[s2[i]-'a']++;
}
int sum=0;
for(int i=0;i<26;i++){
sum+=abs(b[i]-c[i]);
}
cout<<a[sum%6];
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find the hour with the highest gasoline cost. Assume there's only one hour with the most increased cost of gas.
Display hour with highest gasoline cost.DataFrame/SQL Table with the following schema -
<schema>[{'name': 'lyft_rides', 'columns': [{'name': 'index', 'type': 'int64'}, {'name': 'weather', 'type': 'object'}, {'name': 'hour', 'type': 'int64'}, {'name': 'travel_distance', 'type': 'float64'}, {'name': 'gasoline_cost', 'type': 'float64'}]}]</schema>Each row in a new line and each value of a row separated by a |, i.e.,
0|1|2
1|2|3
2|3|4-, I have written this Solution Code: df = lyft_rides.sort_values(by = ['gasoline_cost'],ascending= False)
df = df.head(1)
for i, r in df.iterrows():
print(f"{r['hour']}"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find the hour with the highest gasoline cost. Assume there's only one hour with the most increased cost of gas.
Display hour with highest gasoline cost.DataFrame/SQL Table with the following schema -
<schema>[{'name': 'lyft_rides', 'columns': [{'name': 'index', 'type': 'int64'}, {'name': 'weather', 'type': 'object'}, {'name': 'hour', 'type': 'int64'}, {'name': 'travel_distance', 'type': 'float64'}, {'name': 'gasoline_cost', 'type': 'float64'}]}]</schema>Each row in a new line and each value of a row separated by a |, i.e.,
0|1|2
1|2|3
2|3|4-, I have written this Solution Code: SELECT
hour
FROM
lyft_rides
ORDER BY
gasoline_cost DESC
LIMIT 1, In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement the function <code>sumMaxMin</code>, which should take 5 numbers as input arguments.
The function should return the sum of max and min elements of those 5 numbers (Use JS In built functions)Function will take 5 arguments which will be numbers.Function will return a number which is the sum of min and max element of those 5 arguments.console. log(sumMaxMin(100, 100, -200, 300, 0)) // prints 100 because 300+(-200) = 300-200
console. log(sumMaxMin(1, 3, 2, 4, 5)) // prints 6 because 1+5
console. log(sumMaxMin(-1000, -2000, -10, -120, -60)) // prints -2010 because -2000 min and -10 max sums to -2010, 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[] arr1=new int[5];
for(int i=0;i< arr1.length;i++)
arr1[i]=sc.nextInt();
Main m=new Main();
System.out.println(m.sumMaxMin(arr1));
}
public static int sumMaxMin(int []array){
int max =array[0];
int min=array[0];
int sum1=0;
for (int i = 0; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
if (array[i] < min) {
min = array[i];
}
}
sum1= max +(min);
return sum1;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement the function <code>sumMaxMin</code>, which should take 5 numbers as input arguments.
The function should return the sum of max and min elements of those 5 numbers (Use JS In built functions)Function will take 5 arguments which will be numbers.Function will return a number which is the sum of min and max element of those 5 arguments.console. log(sumMaxMin(100, 100, -200, 300, 0)) // prints 100 because 300+(-200) = 300-200
console. log(sumMaxMin(1, 3, 2, 4, 5)) // prints 6 because 1+5
console. log(sumMaxMin(-1000, -2000, -10, -120, -60)) // prints -2010 because -2000 min and -10 max sums to -2010, I have written this Solution Code:
function sumMaxMin(a,b,c,d,e){
// write code here
// return the output , do not use console.log here
return Math.max(a,b,c,d,e) + Math.min(a,b,c,d,e)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers N and M, your task is to print the number of primes present between N and M (both included).
<b>Note</b>:- You have already provided a function that will check if the given number is prime or not. To use the given function you need to call <b>check_prime(x)</b> where x is the number you want to check. If the given number is prime the function will return 1 else it returns 0.
<b>Note</b>:- Do not close your main class.The input contains two space- separated integers depicting the values of N and M.
Constraints:-
1 <= N <= M <= 10000Print the count of prime numbers in the given range.Sample Input:-
1 10
Sample Output:-
4
Sample Input:-
8 10
Sample Output:-
0, I have written this Solution Code: from math import sqrt
def isPrime(n):
if (n <= 1):
return False
for i in range(2, int(sqrt(n))+1):
if (n % i == 0):
return False
return True
x=input().split()
n=int(x[0])
m=int(x[1])
count = 0
for i in range(n,m):
if isPrime(i):
count = count +1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers N and M, your task is to print the number of primes present between N and M (both included).
<b>Note</b>:- You have already provided a function that will check if the given number is prime or not. To use the given function you need to call <b>check_prime(x)</b> where x is the number you want to check. If the given number is prime the function will return 1 else it returns 0.
<b>Note</b>:- Do not close your main class.The input contains two space- separated integers depicting the values of N and M.
Constraints:-
1 <= N <= M <= 10000Print the count of prime numbers in the given range.Sample Input:-
1 10
Sample Output:-
4
Sample Input:-
8 10
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 m = sc.nextInt();
int cnt=0;
for(int i=n;i<=m;i++){
if(check_prime(i)==1){cnt++;}
}
System.out.println(cnt);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an integer N of at least 100. Print the last two digits of N. Strictly speaking, print the tens and one's digits of N in this order.The input consists of an integer.
N
<b>Constraints</b>
100≤N≤999
N is an integer.Print the answer.<b>Sample Input 1</b>
254
<b>Sample Output 1</b>
54
<b>Sample Input 2</b>
101
<b>Sample Output 2</b>
01, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
cout<<(n%100)/10<<n%10<<endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three numbers tell whether they form a pythagorus triplet or not.
Given A , B and C.
Three integers form pythagorus triplet if sum of square of two is equal to square of third.The first line of the input contains three space separated integers A, B and C.
Constraints
1 <= A,B,C <= 100The output should contain "YES" if they form a triplet else you should print "NO" without quotes.Sample Input
4 3 5
Sample Output
YES
Sample Input
4 6 5
Sample Output
NO, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner in =new Scanner(System.in);
int A = in.nextInt();
int B = in.nextInt();
int C = in.nextInt();
System.out.println(isPythagorasTriplet(A,B,C));
}
static String isPythagorasTriplet(int A, int B, int C){
if(A>B && A>C){
if(A==Math.sqrt(B*B+C*C)){
return "YES";
}
return "NO";
}else if(B>C){
if(B==Math.sqrt(A*A+C*C)){
return "YES";
}
return "NO";
}else{
if(C==Math.sqrt(A*A+B*B)){
return "YES";
}
return "NO";
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three numbers tell whether they form a pythagorus triplet or not.
Given A , B and C.
Three integers form pythagorus triplet if sum of square of two is equal to square of third.The first line of the input contains three space separated integers A, B and C.
Constraints
1 <= A,B,C <= 100The output should contain "YES" if they form a triplet else you should print "NO" without quotes.Sample Input
4 3 5
Sample Output
YES
Sample Input
4 6 5
Sample Output
NO, I have written this Solution Code: nums=list(map(int,input().rstrip().split()))
nums.sort()
if((nums[0]**2)+(nums[1]**2)==(nums[2]**2)):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three numbers tell whether they form a pythagorus triplet or not.
Given A , B and C.
Three integers form pythagorus triplet if sum of square of two is equal to square of third.The first line of the input contains three space separated integers A, B and C.
Constraints
1 <= A,B,C <= 100The output should contain "YES" if they form a triplet else you should print "NO" without quotes.Sample Input
4 3 5
Sample Output
YES
Sample Input
4 6 5
Sample Output
NO, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main()
{
int a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
if((a[0]*a[0]+a[1]*a[1])==a[2]*a[2]){cout<<"YES";}
else{cout<<"NO";}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Insertion is a basic but frequently used operation. Arrays in most languages cannnot be dynamically shrinked or expanded. Here, we will work with such arrays and try to insert an element at the end of array.
You are given an array arr. The size of the array is N. You need to insert an element at its end and print this newly modified array.The first line of input contains T denoting the number of testcases.
T testcases follow. Each testcase contains two lines of input.
The first line contains size of the array denoted by N and element to be inserted.
The third line contains N elements separated by spaces.
Constraints:
1 <= T <= 20
2 <= N <= 10000
0 <= element, arri <= 10^6For each testcase, in a new line, print the modified array.Input:
2
5 90
1 2 3 4 5
3 50
1 2 3
Output:
1 2 3 4 5 90
1 2 3 50
Explanation:
Testcase 1: After inserting 90 at end, we have array elements as 1 2 3 4 5 90.
Testcase 2: After inserting 50 at end, we have array elements as 1 2 3 50., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--) {
long int n, el;
cin>>n>>el;
long int arr[n+1];
for(long int i=0; i<n; i++) {
cin>>arr[i];
}
arr[n] = el;
for(long int i=0; i<=n; i++) {
cout<<arr[i];
if (i != n) {
cout<<" ";
}
else if(t != 0) {
cout<<endl;
}
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Insertion is a basic but frequently used operation. Arrays in most languages cannnot be dynamically shrinked or expanded. Here, we will work with such arrays and try to insert an element at the end of array.
You are given an array arr. The size of the array is N. You need to insert an element at its end and print this newly modified array.The first line of input contains T denoting the number of testcases.
T testcases follow. Each testcase contains two lines of input.
The first line contains size of the array denoted by N and element to be inserted.
The third line contains N elements separated by spaces.
Constraints:
1 <= T <= 20
2 <= N <= 10000
0 <= element, arri <= 10^6For each testcase, in a new line, print the modified array.Input:
2
5 90
1 2 3 4 5
3 50
1 2 3
Output:
1 2 3 4 5 90
1 2 3 50
Explanation:
Testcase 1: After inserting 90 at end, we have array elements as 1 2 3 4 5 90.
Testcase 2: After inserting 50 at end, we have array elements as 1 2 3 50., I have written this Solution Code: t=int(input())
while t>0:
t-=1
li = list(map(int,input().strip().split()))
n=li[0]
num=li[1]
a= list(map(int,input().strip().split()))
a.insert(len(a),num)
for i in a:
print(i,end=" ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Insertion is a basic but frequently used operation. Arrays in most languages cannnot be dynamically shrinked or expanded. Here, we will work with such arrays and try to insert an element at the end of array.
You are given an array arr. The size of the array is N. You need to insert an element at its end and print this newly modified array.The first line of input contains T denoting the number of testcases.
T testcases follow. Each testcase contains two lines of input.
The first line contains size of the array denoted by N and element to be inserted.
The third line contains N elements separated by spaces.
Constraints:
1 <= T <= 20
2 <= N <= 10000
0 <= element, arri <= 10^6For each testcase, in a new line, print the modified array.Input:
2
5 90
1 2 3 4 5
3 50
1 2 3
Output:
1 2 3 4 5 90
1 2 3 50
Explanation:
Testcase 1: After inserting 90 at end, we have array elements as 1 2 3 4 5 90.
Testcase 2: After inserting 50 at end, we have array elements as 1 2 3 50., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n =Integer.parseInt(br.readLine().trim());
while(n-->0){
String str[]=br.readLine().trim().split(" ");
String newel =br.readLine().trim()+" "+str[1];
System.out.println(newel);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter.
Constraints:
1 <= T <= 100
1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input:
3
3
5
6
Sample Output:
0
5
9
Explanation:
For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code: static int numberOfDiagonal(int N){
if(N<=3){return 0;}
return (N*(N-3))/2;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter.
Constraints:
1 <= T <= 100
1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input:
3
3
5
6
Sample Output:
0
5
9
Explanation:
For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code:
int numberOfDiagonals(int n){
if(n<=3){return 0;}
return (n*(n-3))/2;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter.
Constraints:
1 <= T <= 100
1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input:
3
3
5
6
Sample Output:
0
5
9
Explanation:
For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code: def numberOfDiagonals(n):
if n <=3:
return 0
return (n*(n-3))//2
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter.
Constraints:
1 <= T <= 100
1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input:
3
3
5
6
Sample Output:
0
5
9
Explanation:
For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code:
int numberOfDiagonals(int n){
if(n<=3){return 0;}
return (n*(n-3))/2;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two arrays and an integer x. Calculate the minimum absolute difference between sum of pair of elements (one from each array) and the integer x.First line of input contains the length of the array N
Second line contains first array elements
Third line contains second array elements
Last line contains the value of x
Constraints:-
1<=N<=10000
1<=elements<=100000
1<=x<=100000Output a single line containing the minimum differenceSample Input:-
4
1 4 5 7
10 20 30 40
32
Sample Output:-
1
Explanation:
Required pair is 30,1., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(in.readLine());
int[] a=new int[n];
int[] b=new int[n];
String s[]=in.readLine().split(" ");
for(int i=0;i<n;i++){
a[i]=Integer.parseInt(s[i]);
}
s=in.readLine().split(" ");
for(int i=0;i<n;i++){
b[i]=Integer.parseInt(s[i]);
}
int x=Integer.parseInt(in.readLine());
Arrays.sort(a);
Arrays.sort(b);
int i=0,j=n-1;
int min=Integer.MAX_VALUE;
while(i<n&&j>=0){
int sum=a[i]+b[j];
if(sum==x){
min=0;
break;
}else if(sum>x){
min=Math.min(sum-x,min);
j--;
}else{
min=Math.min(x-sum,min);
i++;
}
}
System.out.print(min);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two arrays and an integer x. Calculate the minimum absolute difference between sum of pair of elements (one from each array) and the integer x.First line of input contains the length of the array N
Second line contains first array elements
Third line contains second array elements
Last line contains the value of x
Constraints:-
1<=N<=10000
1<=elements<=100000
1<=x<=100000Output a single line containing the minimum differenceSample Input:-
4
1 4 5 7
10 20 30 40
32
Sample Output:-
1
Explanation:
Required pair is 30,1., I have written this Solution Code: n=int(input())
array1=list(map(int,input().split()))
array2=list(map(int,input().split()))
array1=sorted(array1)
array2=sorted(array2)
value=int(input())
i=0
n=len(array1)
j=len(array2)-1
closest=None
while(i<n and j>=0):
v=array1[i]+array2[j]
if closest==None:
closest=v
elif abs(v-value)<abs(closest-value):
closest=v
if v>value:
j-=1
else:
i+=1
print(abs(closest-value)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two arrays and an integer x. Calculate the minimum absolute difference between sum of pair of elements (one from each array) and the integer x.First line of input contains the length of the array N
Second line contains first array elements
Third line contains second array elements
Last line contains the value of x
Constraints:-
1<=N<=10000
1<=elements<=100000
1<=x<=100000Output a single line containing the minimum differenceSample Input:-
4
1 4 5 7
10 20 30 40
32
Sample Output:-
1
Explanation:
Required pair is 30,1., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define max1 10000001
int main(){
int n,q;
cin>>n;
int a[n];
int b[n];
long sum=LONG_MAX;
unordered_map<int,int> a1,a2;
for(int i=0;i<n;i++){
cin>>a[i];a1[a[i]]++;
}
for(int i=0;i<n;i++){
cin>>b[i];
a2[b[i]]++;
}
int x;
cin>>x;
sort(a,a+n);
sort(b,b+n);
int c[2*n];
int i=0,j=0,k=0;
while(i!=n && j!=n){
if(a[i]<b[j]){c[k]=a[i];k++;i++;}
else{c[k]=b[j];j++;k++;}
}
while(i!=n){
c[k]=a[i];
k++;i++;
}
while(j!=n){
c[k]=b[j];
k++;j++;
}
i=0,j=2*n-1;
while(i<j){
if((c[i]+c[j])>x){if(a1.find(c[i])==a1.end() && a1.find(c[j])==a1.end()){j--;continue;}
else if(a2.find(c[i])==a2.end() && a2.find(c[j])==a2.end()){j--;continue;}
sum=min(sum,(long)abs(x-(c[i]+c[j])));
j--;}
else{
if(a1.find(c[i])==a1.end() && a1.find(c[j])==a1.end()){i++;continue;}
else if(a2.find(c[i])==a2.end() && a2.find(c[j])==a2.end()){i++;continue;}
sum=min(sum,(long)abs(x-(c[i]+c[j])));
i++;
}
}
cout<<sum<<endl;
}
, 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 return the sum of all of its divisors.<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>SumOfDivisors()</b> that takes the integer N as parameter.
Constraints:-
1<=N<=10^9Return the sum of all of the divisors.Sample Input:-
4
Sample Output:-
7
Sample Input:-
13
Sample Output:-
14, I have written this Solution Code: public static long SumOfDivisors(long N){
long sum=0;
long c=(long)Math.sqrt(N);
for(long i=1;i<=c;i++){
if(N%i==0){
sum+=i;
if(i*i!=N){sum+=N/i;}
}
}
return sum;
}
, 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 return the sum of all of its divisors.<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>SumOfDivisors()</b> that takes the integer N as parameter.
Constraints:-
1<=N<=10^9Return the sum of all of the divisors.Sample Input:-
4
Sample Output:-
7
Sample Input:-
13
Sample Output:-
14, I have written this Solution Code:
long long SumOfDivisors(long long N){
long long sum=0;
long sq=sqrt(N);
for(long i=1;i<=sq;i++){
if(N%i==0){
sum+=i;
if(i*i!=N){
sum+=N/i;
}
}
}
return sum;
}, 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 return the sum of all of its divisors.<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>SumOfDivisors()</b> that takes the integer N as parameter.
Constraints:-
1<=N<=10^9Return the sum of all of the divisors.Sample Input:-
4
Sample Output:-
7
Sample Input:-
13
Sample Output:-
14, I have written this Solution Code:
long long SumOfDivisors(long long N){
long long sum=0;
long sq=sqrt(N);
for(long i=1;i<=sq;i++){
if(N%i==0){
sum+=i;
if(i*i!=N){
sum+=N/i;
}
}
}
return sum;
}, 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 return the sum of all of its divisors.<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>SumOfDivisors()</b> that takes the integer N as parameter.
Constraints:-
1<=N<=10^9Return the sum of all of the divisors.Sample Input:-
4
Sample Output:-
7
Sample Input:-
13
Sample Output:-
14, I have written this Solution Code:
def SumOfDivisors(num) :
# Final result of summation of divisors
result = 0
# find all divisors which divides 'num'
i = 1
while i<= (math.sqrt(num)) :
# if 'i' is divisor of 'num'
if (num % i == 0) :
# if both divisors are same then
# add it only once else add both
if (i == (num / i)) :
result = result + i;
else :
result = result + (i + num/i);
i = i + 1
# Add 1 to the result as 1 is also
# a divisor
return (result); , In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int i=str.length()-1;
if(i==0){
int number=Integer.parseInt(str);
System.out.println(number);
}else{
while(str.charAt(i)=='0'){
i--;
}
for(int j=i;j>=0;j--){
System.out.print(str.charAt(j));
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: n=int(input())
def reverse(n):
return int(str(n)[::-1])
print(reverse(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
reverse(s.begin(),s.end());
int I;
for( I=0;I<s.length();I++){
if(s[I]!='0'){break;}
}
if(I==s.length()){cout<<0;return 0;}
for(int j=I;j<s.length();j++){
cout<<s[j];}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two sorted arrays A and B of size N and M respectively.
You have to find the value V, which is the summation of (A[j] - A[i]) for all pairs of i and j such that (j - i) is present in array B.The first line contains two space separated integers N and M – size of arrays A and B respectively.
The second line contains N integers A<sub>1</sub>, A<sub>2</sub>, ... A<sub>N</sub>.
The third line contains M integers B<sub>1</sub>, B<sub>2</sub>, ... B<sub>M</sub>.
<b> Constraints: </b>
1 ≤ N ≤ 2×10<sup>5</sup>
1 ≤ M < N
1 ≤ A<sub>1</sub> ≤ A<sub>2</sub> ≤ ... ≤ A<sub>N</sub> ≤ 10<sup>8</sup>.
1 ≤ B<sub>1</sub> < B<sub>2</sub> < ... < B<sub>M</sub> < N.Print a single integer, the value of V.Sample Input 1:
4 2
1 2 3 4
1 3
Sample Output 1:
6
Sample Explanation 1:
Valid pairs of (i, j) are (1, 2), (2, 3), (3, 4), (1, 4)., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define epsi (double)(0.00000000001)
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<pii>
#define vvi vector<vi>
//#define max(a,b) ((a>b)?a:b)
//#define min(a,b) ((a>b)?b:a)
#define min3(a,b,c) min(min(a,b),c)
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max3(a,b,c) max(max(a,b),c)
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define ff(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define REP(a,b,c) for(int a=b; a<c; a++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define ld long double
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define setbits(x) __builtin_popcountll(x)
#define trav(a,x) for(auto &a:x)
#define make_unique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rev(arr) reverse(all(arr))
#define gcd(a,b) __gcd(a,b);
#define ub upper_bound // '>'
#define lb lower_bound // '>='
#define qi queue<ll>
#define fsh cout.flush()
#define si stack<ll>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define fill(a,b) memset(a, b, sizeof(a))
template<typename T,typename E>bool chmin(T& s,const E& t){bool res=s>t;s=min<T>(s,t);return res;}
const ll INF=1LL<<60;
void solve(){
ll n,m;
cin >> n >> m;
vi v1(n),v2(m);
for(auto &i:v1){
cin >> i;
}
for(auto &i:v2){
cin >> i;
}
ll ans=0;
for(int i=1 ; i<=n ; i++){
auto it=lower_bound(all(v2),i);
ll x=it-v2.begin();
ans+=(x*v1[i-1]);
it=lower_bound(all(v2),n-i+1);
x=it-v2.begin();
ans-=(x*v1[i-1]);
}
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int 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: Modify the <code>takeMultipleNumbersAndAdd </code> such that it can take any number of arguments
and return its sum.
This is JS only question.Function should be able to take any number of argsSum of the numberstakeMultipleNumbersAndAdd(1, 2, 2) should return 5 because 1 + 2 + 2
takeMultipleNumbersAndAdd(-1, 2, -1, 5) should return 5, I have written this Solution Code:
function takeMultipleNumbersAndAdd (...nums){
// write your code here
return nums.reduce((prev,cur)=>prev+cur,0)
// return the output using return keyword
// do not console.log it
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono and Solo are one of the best programmers on the planet. Solo knows how to solve the problem on maximum subarray sum using the Kadane algorithm (don't you?). Now, Tono gives Solo a trickier problem to solve. In this problem, Solo can choose any non- empty subarray, the value of the subarray will be the <b>(sum of all the elements of the subarray - largest element of the subarray)</b>. Can you find the maximum value of any subarray?The first line of the input contains a single integer N, the size of the array.
The second line of the input contains N elements A[1], A[2],. , A[N].
Constraints
1 <= N <= 100000
-30 <= A[i] <= 30Output a single integer, the value of the subarray having maximum value.Sample Input
7
5 2 5 3 -30 -30 6
Sample Output
10
Explanation: Solo chooses the subarray [5, 2, 5, 3]. The value of the subarray is 10.
Sample Input
3
-10 6 -15
Sample Output
0, 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 line[] = br.readLine().split(" ");
long a[] = new long[size + 1];
for(int i = 1 ; i <= size; i++)
a[i] = Long.parseLong(line[i - 1]);
long value1 = maxofsubarray(a,size);
long value2 = maxofsubarrayBreakingatNegativeVal(a, size);
System.out.print(Math.max(value1, value2));
}
static long maxofsubarray(long[] a , int size)
{
long currsum = 0 , maxsum = 0, maxEl = 0;
for(int i = 1 ; i <= size ; i++)
{
currsum += a[i];
if(currsum < 0) currsum =0;
if(currsum > maxsum)
{
maxsum = currsum; maxEl = Math.max(maxEl, a[i]);
}
} return (maxsum - maxEl);
}
static long maxofsubarrayBreakingatNegativeVal(long[] a , int size)
{
long currsum = 0 , maxsum = 0, maxEl = 0, maxofall = 0;
for(int i = 1 ; i <= size ; i++)
{
maxEl = Math.max(maxEl, a[i]);
currsum += a[i];
if(currsum - maxEl < 0)
{
currsum =0; maxEl = 0;
}
if(currsum - maxEl > maxsum)
{
maxofall = currsum - maxEl; maxsum = maxofall;
}
}
return (maxofall);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono and Solo are one of the best programmers on the planet. Solo knows how to solve the problem on maximum subarray sum using the Kadane algorithm (don't you?). Now, Tono gives Solo a trickier problem to solve. In this problem, Solo can choose any non- empty subarray, the value of the subarray will be the <b>(sum of all the elements of the subarray - largest element of the subarray)</b>. Can you find the maximum value of any subarray?The first line of the input contains a single integer N, the size of the array.
The second line of the input contains N elements A[1], A[2],. , A[N].
Constraints
1 <= N <= 100000
-30 <= A[i] <= 30Output a single integer, the value of the subarray having maximum value.Sample Input
7
5 2 5 3 -30 -30 6
Sample Output
10
Explanation: Solo chooses the subarray [5, 2, 5, 3]. The value of the subarray is 10.
Sample Input
3
-10 6 -15
Sample Output
0, I have written this Solution Code: def maxSumTill(arr,n):
currSum = 0
maxSum = 0
maxEle = 0
maxi = 0
for i in range(1,n+1):
maxEle = max(maxEle,arr[i])
currSum += arr[i]
if currSum-maxEle < 0:
currSum = 0
maxEle =0
if currSum-maxEle > maxSum:
maxi = currSum - maxEle
maxSum = maxi
return maxi
def maxOfSum(arr,n):
currSum = 0
maxSum = 0
maxEle = 0
for i in range(1,n+1):
currSum += arr[i]
if currSum < 0:
currSum = 0
if currSum > maxSum:
maxSum = currSum
maxEle = max(maxEle, arr[i])
return maxSum - maxEle
n = int(input())
arr = list(map(int,input().split()))
arr = [0]+arr
val1 = maxSumTill(arr,n)
val2 = maxOfSum(arr,n)
print(max(val1,val2))
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono and Solo are one of the best programmers on the planet. Solo knows how to solve the problem on maximum subarray sum using the Kadane algorithm (don't you?). Now, Tono gives Solo a trickier problem to solve. In this problem, Solo can choose any non- empty subarray, the value of the subarray will be the <b>(sum of all the elements of the subarray - largest element of the subarray)</b>. Can you find the maximum value of any subarray?The first line of the input contains a single integer N, the size of the array.
The second line of the input contains N elements A[1], A[2],. , A[N].
Constraints
1 <= N <= 100000
-30 <= A[i] <= 30Output a single integer, the value of the subarray having maximum value.Sample Input
7
5 2 5 3 -30 -30 6
Sample Output
10
Explanation: Solo chooses the subarray [5, 2, 5, 3]. The value of the subarray is 10.
Sample Input
3
-10 6 -15
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(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 = 1e5+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
int arr[N];
int n;
int kadane(){
int mx = 0;
int cur = 0;
For(i, 0, n){
cur += arr[i];
mx = max(mx, cur);
if(cur < 0)
cur = 0;
}
return mx;
}
void play(int x){
For(i, 0, n){
if(arr[i]==x){
arr[i]=-1000000000;
}
}
}
void solve(){
cin>>n;
For(i, 0, n){
cin>>arr[i];
assert(arr[i]>=-30 && arr[i]<=30);
}
int ans = 0;
for(int i=30; i>=1; i--){
ans = max(ans, kadane()-i);
play(i);
}
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: There are n people in a circle, numbered from 1 to n, each of whom always tells the truth or always lies.
Each person i makes a claim of the form: “the number of truth-tellers in this circle is between a<sub>i</sub> and b<sub>i</sub>, inclusive.”
Compute the maximum number of people who could be telling the truth.The first line contains a single integer n (1 ≤ n ≤ 10^3).
Each of the next n lines contains two space-separated integers a<sub>i</sub> and b<sub>i</sub>
(0 ≤ a<sub>i</sub> ≤ b<sub>i</sub> ≤ n).Print, on a single line, the maximum number of people who could be telling the truth. If the given
set of statements are inconsistent, print -1 instead.Sample input
3
1 1
2 3
2 2
Sample output
2
Sample input
8
0 1
1 7
4 8
3 7
1 2
4 5
3 7
1 8
Sample output
-1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(read.readLine());
int count=0;
int cnt[]=new int[n+2];
for(int i=0;i<n;i++){
StringTokenizer st=new StringTokenizer(read.readLine()," ");
int ai=Integer.parseInt(st.nextToken());
int bi=Integer.parseInt(st.nextToken());
for(int j=ai;j<=bi;j++)
{
cnt[j]++;
}
}
int ans=-1;
for(int i=0;i<=n;i++){
if(cnt[i]==i)
{
ans=i;
}
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n people in a circle, numbered from 1 to n, each of whom always tells the truth or always lies.
Each person i makes a claim of the form: “the number of truth-tellers in this circle is between a<sub>i</sub> and b<sub>i</sub>, inclusive.”
Compute the maximum number of people who could be telling the truth.The first line contains a single integer n (1 ≤ n ≤ 10^3).
Each of the next n lines contains two space-separated integers a<sub>i</sub> and b<sub>i</sub>
(0 ≤ a<sub>i</sub> ≤ b<sub>i</sub> ≤ n).Print, on a single line, the maximum number of people who could be telling the truth. If the given
set of statements are inconsistent, print -1 instead.Sample input
3
1 1
2 3
2 2
Sample output
2
Sample input
8
0 1
1 7
4 8
3 7
1 2
4 5
3 7
1 8
Sample output
-1, I have written this Solution Code: n=int(input())
a=[0]*(n+1)
m=0
for i in range(n):
b=[int(k) for k in input().split()]
for j in range(b[0],b[1]+1):
a[j]+=1;
for i in range(n,0,-1):
if a[i]==i:
print(i)
exit()
print(-1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n people in a circle, numbered from 1 to n, each of whom always tells the truth or always lies.
Each person i makes a claim of the form: “the number of truth-tellers in this circle is between a<sub>i</sub> and b<sub>i</sub>, inclusive.”
Compute the maximum number of people who could be telling the truth.The first line contains a single integer n (1 ≤ n ≤ 10^3).
Each of the next n lines contains two space-separated integers a<sub>i</sub> and b<sub>i</sub>
(0 ≤ a<sub>i</sub> ≤ b<sub>i</sub> ≤ n).Print, on a single line, the maximum number of people who could be telling the truth. If the given
set of statements are inconsistent, print -1 instead.Sample input
3
1 1
2 3
2 2
Sample output
2
Sample input
8
0 1
1 7
4 8
3 7
1 2
4 5
3 7
1 8
Sample output
-1, I have written this Solution Code: #include<stdio.h>
#define maxn 1100
struct node{
int l,r;
}a[maxn];
int main(){
int n,i,cnt,j,ans=-1;
scanf("%d",&n);
for (i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r);
for (i=n;i>=0;i--) {
cnt=0;
for (j=1;j<=n;j++) if(a[j].l<=i&&i<=a[j].r) cnt++;
if (cnt==i) {ans=i;break;}
}
printf("%d\n",ans);
return 0;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of numbers. Use appropriate array methods to find all numbers that are greater than 5. Complete the function <code>getNumbersGreaterThan5</code> that accepts an array of integers <code>nums</code> and returns an array of numbers that are greater than 5.An array <code>nums</code> of numbersAn array of the numbers greater than 5 that are present in <code>nums</code>const inputArr = [1,2,3,9,10,7,5,4,3]
const ans = getNumbersGreaterThan5(inputArr)
console.log(ans) // prints [9, 10, 7], I have written this Solution Code: function getNumbersGreaterThan5(nums) {
return nums.filter((num) => num > 5);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Andrew loves to solve problems related to prime numbers. One of Andrew's friend has asked him to solve below problem for him.
Given two positive integers <b>N</b> and <b>M</b>, the task is to check that N is the Mth power of a <b>prime number</b> or not.First line of input contains testcases <b>T</b>. For each testcase, there will be two positive integers N and M.
Constraints :
1 <= T <= 100
2 <= N <= 10^6
1 <= M <= 10For each testcase you need to print "<b>Yes</b>" if N is the Mth power of a prime number otherrwise "<b>No</b>". Input :
2
16 4
16 3
Output:
Yes
No
Explanation :
16 is m-th (4th) power of 2, where 2 is prime., I have written this Solution Code: import math
def mroot(n,m):
check = round(n**(1/m))
# print(check)
if check**m == n:
return check
else:
return -1
def prime(n,m):
check = mroot(n,m)
if check == -1:
return "No"
if check == 2:
return "Yes"
for i in range(2, int(math.sqrt(check))+1):
if n%i == 0:
return "No"
return "Yes"
T = int(input())
for _ in range(T):
n,m = list(map(int, input().split()))
print(prime(n,m)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Andrew loves to solve problems related to prime numbers. One of Andrew's friend has asked him to solve below problem for him.
Given two positive integers <b>N</b> and <b>M</b>, the task is to check that N is the Mth power of a <b>prime number</b> or not.First line of input contains testcases <b>T</b>. For each testcase, there will be two positive integers N and M.
Constraints :
1 <= T <= 100
2 <= N <= 10^6
1 <= M <= 10For each testcase you need to print "<b>Yes</b>" if N is the Mth power of a prime number otherrwise "<b>No</b>". Input :
2
16 4
16 3
Output:
Yes
No
Explanation :
16 is m-th (4th) power of 2, where 2 is prime., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(rd.readLine());
while(t-->0){
String b[]=rd.readLine().split(" ");
int n=Integer.parseInt(b[0]);
int m=Integer.parseInt(b[1]);
if(m==1){
int a=(int)Math.sqrt(n);
int p=1;
for(int k=2;k<=a;k++){
if(n%k==0){
p=0;
break;
}
}
if(p==1)
System.out.println("Yes");
else
System.out.println("No");
}
else{
for(int i=2;i<=n/2;i++){
boolean p=true;
for(int j=2;j<=(int)Math.sqrt(i);j++){
if(i%j==0){
p=false;
break;}
}
if(p){
if((int)Math.pow(i,m)==n){
System.out.println("Yes");
break;}
else if((int)Math.pow(i,m)>n){
System.out.println("No");
break;
}
}
}
}}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Andrew loves to solve problems related to prime numbers. One of Andrew's friend has asked him to solve below problem for him.
Given two positive integers <b>N</b> and <b>M</b>, the task is to check that N is the Mth power of a <b>prime number</b> or not.First line of input contains testcases <b>T</b>. For each testcase, there will be two positive integers N and M.
Constraints :
1 <= T <= 100
2 <= N <= 10^6
1 <= M <= 10For each testcase you need to print "<b>Yes</b>" if N is the Mth power of a prime number otherrwise "<b>No</b>". Input :
2
16 4
16 3
Output:
Yes
No
Explanation :
16 is m-th (4th) power of 2, where 2 is prime., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
const int n = 1000001;
bool a[n];
int main(){
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 t;
cin>>t;
while(t--){
int x,y;
cin>>x>>y;
if(y>1){
for(int i=2;i<1000;i++){
if(a[i]==false){
int s=1;
for(int j=0;j<y;j++){
s*=i;
}
if(s==x){
cout<<"Yes"<<endl;
goto f;
}
}
}
cout<<"No"<<endl;
f:;
}
else{
if(a[x]==false){cout<<"Yes"<<endl;}
else{cout<<"No"<<endl;}
}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pino is super fond of candies. Today she has A chocolate candies, B orange candies, and C unknown candies. You are also given the happiness she gets after eating a particular candy.
She wants to have exactly X chocolate candies and Y orange candies. She can transform an unknown candy into a candy of any type (chocolate or orange).
Find the maximum happiness she can attain.The first line of input contains 5 integers X, Y, A, B, and C.
The second line contains an A integer corresponding to the happiness of the various chocolate candies.
The third line contains B integers corresponding to the happiness of the various orange candies.
The fourth line contains C integers corresponding to the happiness of the various unknown candies.
<b>Constraints:-</b>
1 <= A, B, C <= 100000
1 <= X <= A
1 <= Y <= B
1 <= happiness of any candy <= 1000000000 (10^9)Output a single integer, the maximum happiness Pino can achieve by eating the candies.Sample Input 1:-
1 2 2 2 1
2 4
5 1
3
Sample Output 1:-
12
Sample Input 2:-
2 2 2 2 2
8 6
9 1
2 1
Sample Output 2:-
25
<b>Explanation:-</b>
Pino eats the 2nd chocolate candy (happiness=4), then eats the 1st orange candy (happiness=4+5=9), then transforms the first unknown candy to orange candy and eats it (happiness=9+3=12), I have written this Solution Code: X, Y, A, B, C = [int(i) for i in input().split()]
t = X + Y
a = sorted([int(i) for i in input().split()])
b = sorted([int(i) for i in input().split()])
c = [int(i) for i in input().split()]
o = []
for i in range(A-1,-1,-1):
if (X) == 0:
break
else:
X -= 1
o.append(a[i])
for i in range(B-1,-1,-1):
if (Y) == 0:
break
else:
Y -= 1
o.append(b[i])
o.extend(c)
s = 0
o.sort()
for i in range(len(o)-1,-1,-1):
if t == 0:
break
else:
t -= 1
s += o[i]
print(s), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pino is super fond of candies. Today she has A chocolate candies, B orange candies, and C unknown candies. You are also given the happiness she gets after eating a particular candy.
She wants to have exactly X chocolate candies and Y orange candies. She can transform an unknown candy into a candy of any type (chocolate or orange).
Find the maximum happiness she can attain.The first line of input contains 5 integers X, Y, A, B, and C.
The second line contains an A integer corresponding to the happiness of the various chocolate candies.
The third line contains B integers corresponding to the happiness of the various orange candies.
The fourth line contains C integers corresponding to the happiness of the various unknown candies.
<b>Constraints:-</b>
1 <= A, B, C <= 100000
1 <= X <= A
1 <= Y <= B
1 <= happiness of any candy <= 1000000000 (10^9)Output a single integer, the maximum happiness Pino can achieve by eating the candies.Sample Input 1:-
1 2 2 2 1
2 4
5 1
3
Sample Output 1:-
12
Sample Input 2:-
2 2 2 2 2
8 6
9 1
2 1
Sample Output 2:-
25
<b>Explanation:-</b>
Pino eats the 2nd chocolate candy (happiness=4), then eats the 1st orange candy (happiness=4+5=9), then transforms the first unknown candy to orange candy and eats it (happiness=9+3=12), I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 100005;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
int red[N], grn[N], col[N];
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int x, y, a, b, c; cin>>x>>y>>a>>b>>c;
For(i, 0, a){
cin>>red[i];
}
For(i, 0, b){
cin>>grn[i];
}
For(i, 0, c){
cin>>col[i];
}
vector<int> vect;
sort(red, red+a); sort(grn, grn+b);
reverse(red, red+a); reverse(grn, grn+b);
For(i, 0, x){
vect.pb(red[i]);
}
For(i, 0, y){
vect.pb(grn[i]);
}
For(i, 0, c){
vect.pb(col[i]);
}
sort(all(vect));
reverse(all(vect));
int ans = 0;
For(i, 0, x+y){
ans+=vect[i];
}
cout<<ans;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Pino is super fond of candies. Today she has A chocolate candies, B orange candies, and C unknown candies. You are also given the happiness she gets after eating a particular candy.
She wants to have exactly X chocolate candies and Y orange candies. She can transform an unknown candy into a candy of any type (chocolate or orange).
Find the maximum happiness she can attain.The first line of input contains 5 integers X, Y, A, B, and C.
The second line contains an A integer corresponding to the happiness of the various chocolate candies.
The third line contains B integers corresponding to the happiness of the various orange candies.
The fourth line contains C integers corresponding to the happiness of the various unknown candies.
<b>Constraints:-</b>
1 <= A, B, C <= 100000
1 <= X <= A
1 <= Y <= B
1 <= happiness of any candy <= 1000000000 (10^9)Output a single integer, the maximum happiness Pino can achieve by eating the candies.Sample Input 1:-
1 2 2 2 1
2 4
5 1
3
Sample Output 1:-
12
Sample Input 2:-
2 2 2 2 2
8 6
9 1
2 1
Sample Output 2:-
25
<b>Explanation:-</b>
Pino eats the 2nd chocolate candy (happiness=4), then eats the 1st orange candy (happiness=4+5=9), then transforms the first unknown candy to orange candy and eats it (happiness=9+3=12), I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String str[] = read.readLine().split(" ");
int X = Integer.parseInt(str[0]);
int Y = Integer.parseInt(str[1]);
int A = Integer.parseInt(str[2]);
int B = Integer.parseInt(str[3]);
int C = Integer.parseInt(str[4]);
int arr[] = new int[X+Y+C];
int arrA[] = new int[A];
int arrB[] = new int[B];
int arrC[] = new int[C];
String strA[] = read.readLine().split(" ");
for(int k = 0; k < A; k++) {
arrA[k] = Integer.parseInt(strA[k]);
}
Arrays.sort(arrA);
String strB[] = read.readLine().split(" ");
for(int p = 0; p < B; p++) {
arrB[p] = Integer.parseInt(strB[p]);
}
Arrays.sort(arrB);
String strC[] = read.readLine().split(" ");
for(int q = 0; q < C; q++) {
arrC[q] = Integer.parseInt(strC[q]);
}
Arrays.sort(arrC);
System.arraycopy(arrA, arrA.length - X, arr, 0, X);
System.arraycopy(arrB, arrB.length - Y, arr, X, Y);
System.arraycopy(arrC, 0, arr, X+Y, C);
Arrays.sort(arr);
long happiness = 0;
int lastIndex = arr.length - 1;
int candies = 0;
for(int z = lastIndex; z >= 0; z--) {
happiness += arr[z];
candies++;
if(candies == X + Y) {
break;
}
}
System.out.print(happiness);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int t; cin >> t;
while(t--){
vector<int> v;
int n, x; cin >> n >> x;
for(int i = 1; i <= n; i++){
int p; cin >> p;
if(p == x)
v.push_back(i-1);
}
if(v.size() == 0)
cout << "Not found\n";
else{
for(auto i: v)
cout << i << " ";
cout << endl;
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, I have written this Solution Code: def position(n,arr,x):
res = []
cnt = 0
for i in arr:
if(i == x):
res.append(cnt)
cnt += 1
return res
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes.
<strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases.
The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes
<strong>Constraints</strong>:
1 <= T <= 100
1 <= N, X <= 10000
1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space.
Assume 0-indexingInput:
2
5 6
2 3 6 5 6
4 3
2 4 6 5
Output:
2 4
Not found, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main (String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t =Integer.parseInt(read.readLine());
while(t-- > 0)
{
String str[] = read.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
int x = Integer.parseInt(str[1]);
int arr[] = new int[n];
str = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
findPositions(arr, n, x);
}
}
static void findPositions(int arr[], int n, int x)
{
boolean flag = false;
StringBuffer sb = new StringBuffer();
for(int i = 0; i < n; i++)
{
if(arr[i] == x)
{
sb.append(i + " ");
flag = true;
}
}
if(flag ==true)
System.out.println(sb.toString());
else System.out.println("Not found");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges.
<b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments.
Constraints:-
1 <= N <= 10000
1 <= A <= N
1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:-
5 3 4
Sample Output:-
2
Sample Input:-
5 5 5
Sample Output:-
5, I have written this Solution Code: static int LikesBoth(int N, int A, int B){
return (A+B-N);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges.
<b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments.
Constraints:-
1 <= N <= 10000
1 <= A <= N
1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:-
5 3 4
Sample Output:-
2
Sample Input:-
5 5 5
Sample Output:-
5, I have written this Solution Code: def LikesBoth(N,A,B):
return (A+B-N)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges.
<b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments.
Constraints:-
1 <= N <= 10000
1 <= A <= N
1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:-
5 3 4
Sample Output:-
2
Sample Input:-
5 5 5
Sample Output:-
5, I have written this Solution Code: int LikesBoth(int N,int A, int B){
return (A+B-N);
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges.
<b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments.
Constraints:-
1 <= N <= 10000
1 <= A <= N
1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:-
5 3 4
Sample Output:-
2
Sample Input:-
5 5 5
Sample Output:-
5, I have written this Solution Code: int LikesBoth(int N,int A, int B){
return (A+B-N);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton is playing a Cricket match. He has a target of x runs in y overs to win the game. He is scoring at the run rate of z. Tell whether he will able to win match for his team?The first line contains the integer x denoting the target runs to win the match.
The following line contains the integer y denoting the number of overs left.
The following line contains the z denoting the current run rate.
<b>Constraints</b>
1 ≤ x ≤ 500
1 ≤ y ≤ 50
1 ≤ z ≤ 12
x,y and z are IntegersPrint "Newton's team will win" if he achieves the target otherwise print "Newton's team will lose"Sample Input:
300
50
6
Sample output:
Newton's team will win, I have written this Solution Code: import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
assert(x>= 1 && x<= 500);
int y = sc.nextInt();
assert(y>= 1 && y<= 50);
float z = sc.nextFloat();
assert(z>= 1 && z<= 12);
int currentScore = (int) (z * y );
int requiredScore = x;
if (currentScore >= requiredScore) {
System.out.println("Newton's team will win");
} else {
System.out.println("Newton's team will lose");
}
sc.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
double arr[] = new double[N];
String str[] = br.readLine().trim().split(" ");
for(int i=0;i<N;i++)
arr[i]=Integer.parseInt(str[i]);
double resistance=0;
int equResistance=0;
for(int i=0;i<N;i++)
arr[i]=Integer.parseInt(str[i]);
for(int i=0;i<N;i++)
{
resistance=resistance+(1/arr[i]);
}
equResistance = (int)Math.floor((1/resistance));
System.out.println(equResistance);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: r = input("")
r = int(r)
n = input("").split()
resistance=0.0
for i in range(0,r):
resistor = float(n[i])
resistance = resistance + (1/resistor)
print(int(1/resistance)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n; cin >> n;
double s = 0;
for(int i = 1; i <= n; i++){
double p; cin >> p;
s = s + (1/p);
}
s = 1/s;
cout << floor(s);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction.
Fibonacci series is a series where,
Fibonacci(1) = 0
Fibonacci(2) = 1
Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N.
Constraints:
1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1
3
Sample Output 1
Alive
Explanation: Fibonacci(3) = 1 which is odd.
Sample Input 2
4
Sample Output 1
Dead
Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(is);
int n=Integer.parseInt(br.readLine().trim());
if(n%3==1)
System.out.println("Dead");
else
System.out.println("Alive");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction.
Fibonacci series is a series where,
Fibonacci(1) = 0
Fibonacci(2) = 1
Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N.
Constraints:
1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1
3
Sample Output 1
Alive
Explanation: Fibonacci(3) = 1 which is odd.
Sample Input 2
4
Sample Output 1
Dead
Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: n = int(input().strip())
if n%3 == 1:
print("Dead")
else:
print("Alive"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction.
Fibonacci series is a series where,
Fibonacci(1) = 0
Fibonacci(2) = 1
Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N.
Constraints:
1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1
3
Sample Output 1
Alive
Explanation: Fibonacci(3) = 1 which is odd.
Sample Input 2
4
Sample Output 1
Dead
Explanation: Fibonacci(4) = 2 which is even., 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();
//////////////
typedef unsigned long long ull;
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
if(n%3==1)
cout<<"Dead";
else
cout<<"Alive";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S you have to remove all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, remove them as well. Repeat this untill no adjacent letter in the string is same.
Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.The input data consists of a single string S.
Constraints:
1 <= |S| <= 100000
S contains lowercase english letters only.Print the given string after it is processed. It is guaranteed that the result will contain at least one character.Sample Input
hhoowaaaareyyoouu
Sample Output
wre
Explanation:
First we remove "hh" then "oo" then "aa" then "yy" then "oo" then "uu" and we are left with "wre".
Now we cannot remove anything.
Sample Input:-
abcde
Sample Output:-
abcde
Sample Input:-
abcddcb
Sample Output:-
a, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
StringBuilder s = new StringBuilder();
String text=null;
while ((text = in.readLine ()) != null)
{
s.append(text);
}
int len=s.length();
for(int i=0;i<len-1;i++){
if(s.charAt(i)==s.charAt(i+1)){
int flag=0;
s.delete(i,i+2);
int left=i-1;
len=len-2;
i=i-2;
if(i<0){
i=-1;
}
}
}
System.out.println(s);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S you have to remove all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, remove them as well. Repeat this untill no adjacent letter in the string is same.
Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.The input data consists of a single string S.
Constraints:
1 <= |S| <= 100000
S contains lowercase english letters only.Print the given string after it is processed. It is guaranteed that the result will contain at least one character.Sample Input
hhoowaaaareyyoouu
Sample Output
wre
Explanation:
First we remove "hh" then "oo" then "aa" then "yy" then "oo" then "uu" and we are left with "wre".
Now we cannot remove anything.
Sample Input:-
abcde
Sample Output:-
abcde
Sample Input:-
abcddcb
Sample Output:-
a, I have written this Solution Code: s=input()
l=["aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk","ll","mm","nn","oo","pp","qq","rr","ss","tt","uu","vv","ww","xx","yy","zz"]
while True:
do=False
for i in range(len(l)):
if l[i] in s:
do=True
while l[i] in s:
s=s.replace(l[i],"")
if do==False:
break
print(s), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S you have to remove all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, remove them as well. Repeat this untill no adjacent letter in the string is same.
Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.The input data consists of a single string S.
Constraints:
1 <= |S| <= 100000
S contains lowercase english letters only.Print the given string after it is processed. It is guaranteed that the result will contain at least one character.Sample Input
hhoowaaaareyyoouu
Sample Output
wre
Explanation:
First we remove "hh" then "oo" then "aa" then "yy" then "oo" then "uu" and we are left with "wre".
Now we cannot remove anything.
Sample Input:-
abcde
Sample Output:-
abcde
Sample Input:-
abcddcb
Sample Output:-
a, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main(){
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
string s;
cin>>s;
int len=s.length();
char stk[410000];
int k = 0;
for (int i = 0; i < len; i++)
{
stk[k++] = s[i];
while (k > 1 && stk[k - 1] == stk[k - 2])
k -= 2;
}
for (int i = 0; i < k; i++)
cout << stk[i];
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are three sticks with integer lengths l<sub>1</sub>, l<sub>2</sub> and l<sub>3</sub>. You are asked to break exactly one of them into two pieces in such a way that:
- both pieces have positive (strictly greater than 0) integer length;
- the total length of the pieces is equal to the original length of the stick;
- it's possible to construct a rectangle from the resulting four sticks such that each stick is used as exactly one of its sides. A square is also considered a rectangle.
Determine if it's possible to do that.The input consists of 3 space- separated integers l<sub>1</sub>, l<sub>2</sub> and l<sub>3</sub>.
<b>Constraints</b>
1 ≤ l<sub>i</sub> ≤ 10<sup>8</sup>Print "Yes" if it's possible to break one of the sticks into two pieces with positive integer length in such a way that it's possible to construct a rectangle from the resulting four sticks. Otherwise, print "No".<b>Sample Input 1</b>
6 1 5
<b>Sample Output 1</b>
Yes
<b>Sample Input 2</b>
2 5 2
<b>Sample Output 2</b>
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
int main() {
int tt=1;
// cin >> tt;
while (tt--) {
int a, b, c;
cin >> a >> b >> c;
if (a == b + c || b == c + a || c == a + b) {
cout << "Yes" << '\n';
} else {
if ((a == b && c % 2 == 0) || (a == c && b % 2 == 0) || (b == c && a % 2 == 0)) {
cout << "Yes" << '\n';
} else {
cout << "No" << '\n';
}
}
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given N flags, initially set to 0. Now you have to perform two operations on them:
1. Increase(F) by 1: flag F is increased by 1.
2. max_flag: all flags are set to a maximum value of any flag.
A non-empty array arr[] will be given of size M. This array represents consecutive operations:
a) If arr[K] = F, such that 1 <= F <= N then operation K is Increase(F).
b) If arr[K] = N+1 then operation K is max_flag.
The goal is to calculate the value of every flag after all operations.The input line contains T, denoting the number of test cases.
Each test case contains two lines.
The first line contains an integer N, the number of flags, and an integer M, the size of the array 'arr'.The second line contains elements of the array 'arr' separated by space.
<b>Constraints:</b>
1 <= T <= 100
1 <= N, M <= 10^5
1 <= arr[i] <= N+1
Sum of N and M for each test case is less than or equal to 10^5For each testcase you need to print the updated array after all operations in new line.Sample Input:
1
5 7
3 4 4 6 1 4 4
Sample Output:
3 2 2 4 2
<b>Explanation:</b>
Testcase 1:
the values of the flags after each consecutive operation will be:
(0, 0, 1, 0, 0)
(0, 0, 1, 1, 0)
(0, 0, 1, 2, 0)
(2, 2, 2, 2, 2)
(3, 2, 2, 2, 2)
(3, 2, 2, 3, 2)
(3, 2, 2, 4, 2), I have written this Solution Code: t=int(input())
while t>0:
t-=1
n,m=map(int,input().split())
a=map(int,input().split())
b=[0]*(n+1)
for i in a:
if i==n+1:
v=max(b)
for i in range(1,n+1):
b[i]=v
else:b[i]+=1
for i in range(1,n+1):
print(b[i],end=' ')
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given N flags, initially set to 0. Now you have to perform two operations on them:
1. Increase(F) by 1: flag F is increased by 1.
2. max_flag: all flags are set to a maximum value of any flag.
A non-empty array arr[] will be given of size M. This array represents consecutive operations:
a) If arr[K] = F, such that 1 <= F <= N then operation K is Increase(F).
b) If arr[K] = N+1 then operation K is max_flag.
The goal is to calculate the value of every flag after all operations.The input line contains T, denoting the number of test cases.
Each test case contains two lines.
The first line contains an integer N, the number of flags, and an integer M, the size of the array 'arr'.The second line contains elements of the array 'arr' separated by space.
<b>Constraints:</b>
1 <= T <= 100
1 <= N, M <= 10^5
1 <= arr[i] <= N+1
Sum of N and M for each test case is less than or equal to 10^5For each testcase you need to print the updated array after all operations in new line.Sample Input:
1
5 7
3 4 4 6 1 4 4
Sample Output:
3 2 2 4 2
<b>Explanation:</b>
Testcase 1:
the values of the flags after each consecutive operation will be:
(0, 0, 1, 0, 0)
(0, 0, 1, 1, 0)
(0, 0, 1, 2, 0)
(2, 2, 2, 2, 2)
(3, 2, 2, 2, 2)
(3, 2, 2, 3, 2)
(3, 2, 2, 4, 2), I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
memset(a, 0, sizeof a);
int n, m;
cin >> n >> m;
int mx = 0, flag = 0;
for(int i = 1; i <= m; i++){
int p; cin >> p;
if(p == n+1){
flag = mx;
}
else{
a[p] = max(a[p], flag) + 1;
mx = max(mx, a[p]);
}
}
for(int i = 1; i <= n; i++){
a[i] = max(a[i], flag);
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: Rahul has given a linked list and he wants to move all 0’s to the front of the linked list. Help Rahul to fulfill his wish.
<b>Note:</b>
The order of all other elements except 0 should be the same after rearrangement.
For custom input/output, enter the list in reverse order, and the output will also be in reverse order.
Example:
1 1 2 0 3 0 0 is the linked list given to Rahul. First, enter the list in reverse order so the new list will become 0 0 3 0 2 1 1. According to Rahul's wish, all zeros should be moved to the front of the linked list. Hence the output will be 0 0 0 3 2 1 1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>moveZeroes()</b> that takes the head node as a parameter.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 100000
0 ≤ Node.data ≤ 100000
<b>Note:- </b>
The sum of all test cases doesn't exceed 10^5Return the head of the modified linked list.Input:
2
10
0 4 0 5 0 2 1 0 1 0
7
1 1 2 3 0 0 0
Output:
0 0 0 0 0 1 1 2 5 4
0 0 0 3 2 1 1, I have written this Solution Code: static public Node moveZeroes(Node head){
ArrayList<Integer> a=new ArrayList<>();
int c=0;
while(head!=null){
if(head.data==0){
c++;
}
else{
a.add(head.data);
}
head=head.next;
}
head=null;
for(int i=a.size()-1;i>=0;i--){
if(head==null){
head=new Node(a.get(i));
}
else{
Node temp=new Node(a.get(i));
temp.next=head;
head=temp;
}
}
while(c-->0){
Node temp=new Node(0);
temp.next=head;
head=temp;
}
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the first 2 terms A and B of an Arithmetic Series, tell the Nth term of the series.<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>nthAP()</b> that takes the integer A, B, and N as a parameter.
<b>Constraints:</b>
-10^3 <= A <= 10^3
-10^3 <= B <= 10^3
1 <= N <= 10^4Print the Nth term of AP series.Sample Input:
2 3 4
Sample Output:
5
Sample Input:
1 2 10
Sample output:
10, I have written this Solution Code: def nthAP(x, y, z):
res = x + (y-x) * (z-1)
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary sorted non-increasing array arr of size <b>N</b>. You need to print the count of <b>1's</b> in the binary array.
Try to solve the problem using binary searchThe input line contains T, denotes the number of testcases.
Each test case contains two lines. The first line contains N (size of binary array). The second line contains N elements of binary array separated by space.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^6
arr[i] = 0,1
<b>Sum of N over all testcases does not exceed 10^6</b>For each testcase in new line, print the count 1's in binary array.Input:
2
8
1 1 1 1 1 0 0 0
8
1 1 0 0 0 0 0 0
Output:
5
2
Explanation:
Testcase 1: Number of 1's in given binary array : 1 1 1 1 1 0 0 0 is 5.
Testcase 2: Number of 1's in given binary array : 1 1 0 0 0 0 0 0 is 2., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main (String[] args) throws IOException {
Reader sc=new Reader();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int count=search(a,0,n-1);
System.out.println(count);
}
}
public static int search(int[] a,int l,int h){
while(l<=h){
int mid=l+(h-l)/2;
if ((mid==h||a[mid+1]==0)&&(a[mid]==1))
return mid+1;
if (a[mid]==1)
l=mid+1;
else h=mid-1;
}
return 0;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary sorted non-increasing array arr of size <b>N</b>. You need to print the count of <b>1's</b> in the binary array.
Try to solve the problem using binary searchThe input line contains T, denotes the number of testcases.
Each test case contains two lines. The first line contains N (size of binary array). The second line contains N elements of binary array separated by space.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^6
arr[i] = 0,1
<b>Sum of N over all testcases does not exceed 10^6</b>For each testcase in new line, print the count 1's in binary array.Input:
2
8
1 1 1 1 1 0 0 0
8
1 1 0 0 0 0 0 0
Output:
5
2
Explanation:
Testcase 1: Number of 1's in given binary array : 1 1 1 1 1 0 0 0 is 5.
Testcase 2: Number of 1's in given binary array : 1 1 0 0 0 0 0 0 is 2., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 1e6 + 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];
int l = 0, h = n+1;
while(l+1 < h){
int m = (l + h) >> 1;
if(a[m] == 1)
l = m;
else
h = m;
}
cout << l << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary sorted non-increasing array arr of size <b>N</b>. You need to print the count of <b>1's</b> in the binary array.
Try to solve the problem using binary searchThe input line contains T, denotes the number of testcases.
Each test case contains two lines. The first line contains N (size of binary array). The second line contains N elements of binary array separated by space.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^6
arr[i] = 0,1
<b>Sum of N over all testcases does not exceed 10^6</b>For each testcase in new line, print the count 1's in binary array.Input:
2
8
1 1 1 1 1 0 0 0
8
1 1 0 0 0 0 0 0
Output:
5
2
Explanation:
Testcase 1: Number of 1's in given binary array : 1 1 1 1 1 0 0 0 is 5.
Testcase 2: Number of 1's in given binary array : 1 1 0 0 0 0 0 0 is 2., I have written this Solution Code: c=int(input())
for x in range(c):
size=int(input())
s=input()
print(s.count('1')), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We have A balls with the string S written on each of them and B balls with the string T written on each of them.
Alice has two boxes. One contains A cubes with the string S written and other contains B cubes with the string T written.
From these two boxes, Alice chooses one with the string U written on it and throws it away.
Find the number of cubes in each of the box.The first line contains two strings S and T.
The second line contains two integers A and B.
The third line contains a single integer U.
Constraints:
S, T, and U are strings consisting of lowercase English letters.
The lengths of S and T are each between 1 and 10 (inclusive).
S!=T
S=U or T=U.
1≤A, B≤10
A and B are integers.Find the number of cubes in each of the box.Sample Input 1:
red blue
3 4
red
Sample Output 1:
2 4
Explanation: Alice chose a cube with red written on it and threw it away. Now we have two cubes with the string S and four cubes with the string T.
Sample Input 2:
red blue
5 5
blue
Sample Output 2:
5 4
Explanation: Alice chose a cube with blue written on it and threw it away. Now we have five cubes with the string S and four cubes with the string T., I have written this Solution Code: s, t = [x for x in input().split()]
a, b = [int(x) for x in input().split()]
u = input()
if u == s:
print(a-1, b)
else:
print(a, b-1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We have A balls with the string S written on each of them and B balls with the string T written on each of them.
Alice has two boxes. One contains A cubes with the string S written and other contains B cubes with the string T written.
From these two boxes, Alice chooses one with the string U written on it and throws it away.
Find the number of cubes in each of the box.The first line contains two strings S and T.
The second line contains two integers A and B.
The third line contains a single integer U.
Constraints:
S, T, and U are strings consisting of lowercase English letters.
The lengths of S and T are each between 1 and 10 (inclusive).
S!=T
S=U or T=U.
1≤A, B≤10
A and B are integers.Find the number of cubes in each of the box.Sample Input 1:
red blue
3 4
red
Sample Output 1:
2 4
Explanation: Alice chose a cube with red written on it and threw it away. Now we have two cubes with the string S and four cubes with the string T.
Sample Input 2:
red blue
5 5
blue
Sample Output 2:
5 4
Explanation: Alice chose a cube with blue written on it and threw it away. Now we have five cubes with the string S and four cubes with the string T., I have written this Solution Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import static java.lang.Math.*;
import static java.lang.System.out;
public class Main {
void solve() {
String s= in.next();
String t= in.next();
int a= in.nextInt();
int b= in.nextInt();
String u= in.next();
if(s.equals(u)){
a--;
}
if(t.equals(u)){
b--;
}
sb.append(a).append(" ").append(b).append("\n");
}
int util(int[] pos, int j) {
int cnt=0;
int p=j;
while(p!=-1) {
cnt++;
p=pos[p];
if(p==j) return cnt;
}
return -1;
}
void start(){
sb= new StringBuffer();
solve();
out.print(sb);
}
FastReader in;
StringBuffer sb;
public static void main(String[] args) {
new Main().run();
}
void run(){
in= new FastReader();
start();
}
long nCr(int n, int r) {
if (r > n)
return 0;
long m = 1000000007;
long[] inv = new long[r + 1];
inv[0] = 1;
if(r+1>=2)
inv[1] = 1;
for (int i = 2; i <= r; i++) {
inv[i] = m - (m / i) * inv[(int) (m % i)] % m;
}
long ans = 1;
for (int i = 2; i <= r; i++) {
ans = (int) (((ans % m) * (inv[i] % m)) % m);
}
for (int i = n; i >= (n - r + 1); i--) {
ans = (int) (((ans % m) * (i % m)) % m);
}
return ans;
}
int lower_bound(ArrayList<Integer> a, int x) {
int l=-1,r=a.size();
while(l+1<r) {
int m=(l+r)>>>1;
if(a.get(m)>=x) r=m;
else l=m;
}
return r;
}
void bubbleSort(long[] arr){
int n= arr.length;
for(int i=n-1; i>0; i--){
for(int j=0; j<i; j++){
if(arr[i] < arr[j]){
swap(arr, i, j);
}
}
}
}
void swap(long[] arr, int i, int j){
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
long numberOfWays(long n, long k) {
if (n == 0)
return 1;
if (k == 0)
return 1;
if (n >= (int)Math.pow(2, k)) {
int curr_val = (int)Math.pow(2, k);
return numberOfWays(n - curr_val, k)
+ numberOfWays(n, k - 1);
}
else
return numberOfWays(n, k - 1);
}
boolean palindrome(String s){
int i=0, j= s.length()-1;
while(i<j){
if(s.charAt(i)!=s.charAt(j)) return false;
i++; j--;
}
return true;
}
int call(int[] A, int N, int K) {
int i = 0, j = 0, sum = 0;
int maxLen = Integer.MIN_VALUE;
while (j < N) {
sum += A[j];
if (sum < K) {
j++;
}
else if (sum == K) {
maxLen = Math.max(maxLen, j-i+1);
j++;
}
else if (sum > K) {
while (sum > K) {
sum -= A[i];
i++;
}
if(sum == K){
maxLen = Math.max(maxLen, j-i+1);
}
j++;
}
}
return maxLen;
}
int largestNum(int n)
{
int num = 0;
for (int i = 0; i <= 32; i++)
{
int x = (1 << i);
if ((x - 1) >= n)
num = (1 << i) - 1;
else
break;
}
return num;
}
static boolean isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
int call(int i,int j, int[][] mat, int[][] dp){
int m= mat.length;
int n= mat[0].length;
if(i>=m || j>=n){
return Integer.MIN_VALUE;
}
if(i==m-1 && j==n-1){
return mat[i][j];
}
if(dp[i][j] != -1){
return dp[i][j];
}
return dp[i][j] = max(call(i+1, j, mat, dp), call(i, j+1, mat, dp)) + mat[i][j];
}
int util(int i,int j, int[][] mat, int[][] dp){
int m= mat.length;
int n= mat[0].length;
if(i>=m || j>=n){
return Integer.MAX_VALUE;
}
if(i==m-1 && j==n-1){
return mat[i][j];
}
if(dp[i][j] != -1){
return dp[i][j];
}
return dp[i][j] = min(util(i+1, j, mat, dp), util(i, j+1, mat, dp)) + mat[i][j];
}
long power(long x, long y, long p) {
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int lower_bound(long[] a, long x) {
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
int upper_bound(ArrayList<Integer> arr, int key) {
int i=0, j=arr.size()-1;
if(j==-1){
return 0;
}
if (arr.get(j)<=key) return j+1;
if(arr.get(i)>key) return i;
while (i<j){
int mid= (i+j)/2;
if(arr.get(mid)<=key){
i= mid+1;
}else{
j=mid;
}
}
return i;
}
void sort(long[] A){
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
long tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
int[] intArr(int n){
int[] res= new int[n];
for(int i=0;i<n;i++){
res[i]= in.nextInt();
}
return res;
}
long[] longArr(int n){
long[] res= new long[n];
for(int i=0;i<n;i++){
res[i]= in.nextLong();
}
return res;
}
long MAX= 100000000;
int[] precomp;
void sieve(){
long n= MAX;
precomp = new int[(int) (n+1)];
boolean[] prime = new boolean[(int) (n+1)];
for(int i=0;i<=n;i++)
prime[i] = true;
for(long p = 2; p*p <=n; p++)
{
if(prime[(int) p])
{
for(long i = p*p; i <= n; i += p)
prime[(int) i] = false;
}
}
for(long i = 2; i <= n; i++)
{
if(prime[(int) i])
precomp[(int) i]= 1;
}
}
long REVERSE(long N) {
long rev=0;
long org= N;
while (N!=0){
long d= N%10;
rev = rev*10 +d;
N /= 10;
}
return rev;
}
long sumOfDigits(String n){
long sum= 0;
for (char c: n.toCharArray()){
sum += Integer.parseInt(String.valueOf(c));
}
return sum;
}
long[] revArray(long[] arr) {
int n= arr.length;
int i=0, j=n-1;
while (i<j){
long temp= arr[i];
arr[i]= arr[j];
arr[j]= temp;
i++;
j--;
}
return arr;
}
long gcd(long a, long b){
if (b==0)
return a;
return gcd(b, a%b);
}
long lcm(long a,long b){
return (a*b)/gcd(a,b);
}
static class Pair implements Comparable<Pair>{
long first;
long second;
Pair(long x, long y){
this.first=x;
this.second=y;
}
@Override
public int compareTo(Pair o) {
return 0;
}
}
public static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while (st==null || !st.hasMoreElements()){
try{
st=new StringTokenizer(br.readLine());
}catch (Exception e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
float nextFloat(){
return Float.parseFloat(next());
}
String nextLine(){
String str="";
try{
str=br.readLine();
}catch (Exception e){
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We have A balls with the string S written on each of them and B balls with the string T written on each of them.
Alice has two boxes. One contains A cubes with the string S written and other contains B cubes with the string T written.
From these two boxes, Alice chooses one with the string U written on it and throws it away.
Find the number of cubes in each of the box.The first line contains two strings S and T.
The second line contains two integers A and B.
The third line contains a single integer U.
Constraints:
S, T, and U are strings consisting of lowercase English letters.
The lengths of S and T are each between 1 and 10 (inclusive).
S!=T
S=U or T=U.
1≤A, B≤10
A and B are integers.Find the number of cubes in each of the box.Sample Input 1:
red blue
3 4
red
Sample Output 1:
2 4
Explanation: Alice chose a cube with red written on it and threw it away. Now we have two cubes with the string S and four cubes with the string T.
Sample Input 2:
red blue
5 5
blue
Sample Output 2:
5 4
Explanation: Alice chose a cube with blue written on it and threw it away. Now we have five cubes with the string S and four cubes with the string T., I have written this Solution Code: #include <iostream>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
string S, T;
cin >> S >> T;
int a, b;
cin >> a >> b;
string u;
cin >> u;
if (u == S)
--a;
else
--b;
cout << a << " " << b << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After sitting idle in home for around 2 months, Jiraya has finally come up with a super interesting problem on arrays (or maybe!).
You are given an array A of N integers. You need to choose an index i from 1 to N (inclusive) and divide this array into 2 parts, then find the maximum sum of contiguous subarray in both the parts of arrays and add the obtained values from the two arrays.
What is the maximum sum that you can obtain?
Note: The element at index i is not a part of any of the generated arrays, choosing an empty subarray is allowed, one of the generated array is empty if i=1 or i=N (its maximum subarray sum will be 0).
See sample for better understanding.The first line of input contains a single integer N.
The second line of input contains N integers A[1], A[2],. , A[N]
Constraints
2 <= N <= 200000
-1000000 <= A[i] <= 1000000Output a single integer, the answer to the above problem.
(The answer may not fit into integer data type)Sample Input
6
-5 -1 4 -3 5 -4
Sample Output
9
Explanation: We choose i = 4. The two arrays are [-5, -1, 4] and [5, -4]. The maximum sum of contiguous subarrays are 4 and 5 respectively. Therefore, the answer is 4 + 5 = 9.
Sample Input
5
-1 -1 -1 -1 -1
Sample Output
0
Explanation: We choose i = 3. The two arrays are [-1, -1] and [-1, -1]. The maximum sum of contiguous subarrays are 0 and 0 respectively (empty subarrays). Therefore, the answer is 0 + 0 = 0., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader bd=new BufferedReader(new InputStreamReader(System.in));
String st1=bd.readLine();
int n=Integer.parseInt(st1);
int arr[]=new int[n];
String[] st2=bd.readLine().split(" ");
for(int i=0; i<n; i++){
arr[i]=Integer.parseInt(st2[i]);
}
long sum_till_here_forward = 0;
long max_sum_forward = 0;
long sum_till_here_backward = 0;
long max_sum_backward = 0;
long sum_forward[] = new long[n+1];
long sum_backward[] = new long[n+1];
long maximum=0;
if(n==2){
maximum=Math.max(arr[0],arr[1]);
}
else{
for(int i=0; i<n; i++){
sum_till_here_forward += arr[i];
if(sum_till_here_forward > max_sum_forward){
max_sum_forward = sum_till_here_forward;
}
if(sum_till_here_forward < 0){
sum_till_here_forward = 0;
}
sum_forward[i+1] = max_sum_forward;
}
for(int i=n-1; i>=0; i--){
sum_till_here_backward += arr[i];
if(sum_till_here_backward > max_sum_backward){
max_sum_backward = sum_till_here_backward;
}
if(sum_till_here_backward < 0){
sum_till_here_backward=0;
}
sum_backward[i+1] = max_sum_backward;
}
for(int i=1; i<n; i++){
maximum=Math.max(maximum,(sum_forward[i-1]+sum_backward[i+1]));
}
}
System.out.print(maximum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After sitting idle in home for around 2 months, Jiraya has finally come up with a super interesting problem on arrays (or maybe!).
You are given an array A of N integers. You need to choose an index i from 1 to N (inclusive) and divide this array into 2 parts, then find the maximum sum of contiguous subarray in both the parts of arrays and add the obtained values from the two arrays.
What is the maximum sum that you can obtain?
Note: The element at index i is not a part of any of the generated arrays, choosing an empty subarray is allowed, one of the generated array is empty if i=1 or i=N (its maximum subarray sum will be 0).
See sample for better understanding.The first line of input contains a single integer N.
The second line of input contains N integers A[1], A[2],. , A[N]
Constraints
2 <= N <= 200000
-1000000 <= A[i] <= 1000000Output a single integer, the answer to the above problem.
(The answer may not fit into integer data type)Sample Input
6
-5 -1 4 -3 5 -4
Sample Output
9
Explanation: We choose i = 4. The two arrays are [-5, -1, 4] and [5, -4]. The maximum sum of contiguous subarrays are 4 and 5 respectively. Therefore, the answer is 4 + 5 = 9.
Sample Input
5
-1 -1 -1 -1 -1
Sample Output
0
Explanation: We choose i = 3. The two arrays are [-1, -1] and [-1, -1]. The maximum sum of contiguous subarrays are 0 and 0 respectively (empty subarrays). Therefore, the answer is 0 + 0 = 0., I have written this Solution Code: n=int(input())
l=list(map(int,input().split()))
left=[]
for i in range(n):
left.append(0)
curr_max=l[0]
max_so_far=l[0]
for i in range(1,n):
left[i]=max_so_far
curr_max = max(l[i], curr_max+l[i])
max_so_far = max(max_so_far, curr_max)
right=[]
for i in range(n):
right.append(0)
curr_max=l[n-1]
max_so_far=l[n-1]
for i in range(n-2,-1,-1):
right[i]=max_so_far
curr_max = max(l[i], curr_max+l[i])
max_so_far = max(max_so_far, curr_max)
ans=0
for i in range(n):
ans=max(ans,left[i]+right[i])
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After sitting idle in home for around 2 months, Jiraya has finally come up with a super interesting problem on arrays (or maybe!).
You are given an array A of N integers. You need to choose an index i from 1 to N (inclusive) and divide this array into 2 parts, then find the maximum sum of contiguous subarray in both the parts of arrays and add the obtained values from the two arrays.
What is the maximum sum that you can obtain?
Note: The element at index i is not a part of any of the generated arrays, choosing an empty subarray is allowed, one of the generated array is empty if i=1 or i=N (its maximum subarray sum will be 0).
See sample for better understanding.The first line of input contains a single integer N.
The second line of input contains N integers A[1], A[2],. , A[N]
Constraints
2 <= N <= 200000
-1000000 <= A[i] <= 1000000Output a single integer, the answer to the above problem.
(The answer may not fit into integer data type)Sample Input
6
-5 -1 4 -3 5 -4
Sample Output
9
Explanation: We choose i = 4. The two arrays are [-5, -1, 4] and [5, -4]. The maximum sum of contiguous subarrays are 4 and 5 respectively. Therefore, the answer is 4 + 5 = 9.
Sample Input
5
-1 -1 -1 -1 -1
Sample Output
0
Explanation: We choose i = 3. The two arrays are [-1, -1] and [-1, -1]. The maximum sum of contiguous subarrays are 0 and 0 respectively (empty subarrays). Therefore, the answer is 0 + 0 = 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 int long long
#define ld 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
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 200005;
// 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
vector<int> a;
int n;
vector<int> kadane(){
int cur = 0;
int mx = 0;
vector<int> vect(n);
for(int i=0; i<n; i++){
cur += a[i];
mx = max(mx, cur);
if(cur < 0)
cur = 0;
vect[i]=mx;
}
return vect;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
cin>>n;
for(int i=0; i<n; i++){
int x; cin>>x;
a.pb(x);
}
vector<int> v1 = kadane();
reverse(all(a));
vector<int> v2 = kadane();
reverse(all(v2));
int ans = 0;
For(i, 0, n){
if(i>0 && i<n-1)
ans = max(ans, v1[i-1]+v2[i+1]);
else if(i==0)
ans = max(ans, v2[i+1]);
else
ans = max(ans, v1[i-1]);
}
cout<<ans;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two sorted linked list of size s1 and s2(sizes may or may not be same), your task is to merge them such that resultant list is also sorted.<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>Merge()</b> that takes the head node of both the linked list as the parameter.
Use <b>insert()</b> function for inserting nodes in the linked list.
<b>Constraints:</b>
1 < = s1, s2 < = 1000
1 < = val < = 10000Return the head of the merged linked list, printing will be done by the driver codeSample Input:
5 6
1 2 3 4 5
3 4 6 8 9 10
Sample Output:
1 2 3 3 4 4 5 6 8 9 10, I have written this Solution Code: public static Node Merge (Node head1, Node head2){
Node head =null;
while(head1!=null && head2!=null){
if(head1.val<head2.val){
head=insert(head,head1.val);
head1=head1.next;
}
else{
head=insert(head,head2.val);
head2=head2.next;
}
}
while(head1!=null){
head=insert(head,head1.val);
head1=head1.next;
}
while(head2!=null){
head=insert(head,head2.val);
head2=head2.next;
}
return head;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton wants to play Holi with his friends. So he wants to buy three colors for which he needs some money from his father. For buying all three colors he needs at least 75 rupees. For buying 2 colors he needs at least 50 rupees. For buying at least 1 color he needs 25 rupees.
You have to check how many colors did Newton buy. If he buys all three colors print "Newton is very happy", if he buys only two colors print "Newton is happy", if he buys only one color print "Newton is sad" otherwise print "Newton won't play Holi".The first line contains the integer n denoting the amount of money Newton receives from his father.
<b>Constraints</b>
0 ≤ n ≤ 1000Print the output based on the suitable condition.Sample input:
60
Sample output:
Newton is happy
<b>Explanation</b>
Newton will get only two colors as he gets only 60 ruppes from his father., I have written this Solution Code: import java.util.Scanner;
class Solution {
public void num(int money){
if (money < 25) {
System.out.println("Newton won't play Holi");
}
else if (money < 50) {
System.out.println("Newton is sad");
}
else if (money < 75) {
System.out.println("Newton is happy");
}
else {
System.out.println("Newton is very happy");
}
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int money= scanner.nextInt();
Solution obj = new Solution();
obj.num(money);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int i=str.length()-1;
if(i==0){
int number=Integer.parseInt(str);
System.out.println(number);
}else{
while(str.charAt(i)=='0'){
i--;
}
for(int j=i;j>=0;j--){
System.out.print(str.charAt(j));
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: n=int(input())
def reverse(n):
return int(str(n)[::-1])
print(reverse(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
reverse(s.begin(),s.end());
int I;
for( I=0;I<s.length();I++){
if(s[I]!='0'){break;}
}
if(I==s.length()){cout<<0;return 0;}
for(int j=I;j<s.length();j++){
cout<<s[j];}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements and an integer D. Your task is to rotate the array D times in a circular manner from the right to left direction. Consider the examples for better understanding:-
Try to do without creating another arrayUser task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>rotate()</b> that takes the array, size of the array, and the integer d as a parameter.
Constraints:
1 <= T <= 25
2 <= N <= 10^4
1<=D<=10^5
1 <= A[i] <= 10^5For each test case, you just need to rotate the array by D times. The driver code will prin the rotated array in a new line.Sample Input:
2
8
4
1 2 3 4 5 6 7 8
10
3
1 2 3 4 5 6 7 8 9 10
Sample Output:
5 6 7 8 1 2 3 4
4 5 6 7 8 9 10 1 2 3
Explanation(might now be the optimal solution):
Testcase 1:
Follow the below steps:-
After the first rotation, the array becomes 2 3 4 5 6 7 8 1
After the second rotation, the array becomes 3 4 5 6 7 8 1 2
After the third rotation, the array becomes 4 5 6 7 8 1 2 3
After the fourth rotation, the array becomes 5 6 7 8 1 2 3 4
Hence the final result: 5 6 7 8 1 2 3 4, I have written this Solution Code: public static int gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}
public static void rotate(int arr[], int n, int d){
d = d % n;
int g_c_d = gcd(d, n);
for (int i = 0; i < g_c_d; i++) {
/* move i-th values of blocks */
int temp = arr[i];
int j = i;
boolean win=true;
while (win) {
int k = j + d;
if (k >= n)
k = k - n;
if (k == i)
break;
arr[j] = arr[k];
j = k;
}
arr[j] = temp;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Create 6 variables with names<code>varA, varB, varC, varD, varE, varF</code>
Store 6 different values of your choice in the variables such that the variables represent the given primitive types in the given order:
<code>varA</code>: Number
<code>varB</code>: String
<code>varC</code>: Boolean
<code>varD</code>: Undefined
<code>varE</code>: Object
<code>varF</code>: SymbolNo input is required, you just need to create the variables..No output is required for this question..console.log(typeof varA); //prints number
console.log(typeof varB); //prints stirng
console.log(typeof varC); //prints boolean
console.log(typeof varD); //prints undefined
console.log(typeof varE); //prints object
console.log(typeof varF); //prints symbol
, I have written this Solution Code: var varA = 69;
var varB = "hello";
var varC = true;
var varD;
var varE = {};
var varF = Symbol();, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You must be familiar with various types of operators. One of the most commonly used operators in any language are increment and decrement operators. Given two numbers X and Y. Your task is to print the value of X decremented by 1 and value of Y after incremented by 1.The first line of the input contains two integers X and Y.
<b>Constraints:</b>
1 ≤ X, Y ≤ 10000You need to perform the task as mentioned in the question, and finally, print the result separated by a space.Sample Input 1:
4 5
Sample Output 1:
3 6
Sample Input 2:
5 6
Sample Output 2:
4 7, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
x--;
y++;
System.out.print(x);
System.out.print(" ");
System.out.print(y);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You must be familiar with various types of operators. One of the most commonly used operators in any language are increment and decrement operators. Given two numbers X and Y. Your task is to print the value of X decremented by 1 and value of Y after incremented by 1.The first line of the input contains two integers X and Y.
<b>Constraints:</b>
1 ≤ X, Y ≤ 10000You need to perform the task as mentioned in the question, and finally, print the result separated by a space.Sample Input 1:
4 5
Sample Output 1:
3 6
Sample Input 2:
5 6
Sample Output 2:
4 7, I have written this Solution Code: def incremental_decremental(x, y):
x -= 1
y += 1
print(x, y, end =' ')
def main():
input1 = input().split()
x = int(input1[0])
y = int(input1[1])
#z = int(input1[2])
incremental_decremental(x, y)
if __name__ == '__main__':
main(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |