Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 <= n <= 100
<b>Note:</b>
<i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:-
5
Sample Output:-
2 4
Sample Input:-
6
Sample Output:-
2 4 6, I have written this Solution Code: public static void For_Loop(int n){
for(int i=2;i<=n;i+=2){
System.out.print(i+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono has gathered all the FRIENDS for a grand chapo event. For winning the chapo, she has asked the FRIENDS for the solution to a simple problem.
Our magical Tono has A apple candies and O orange candies. In one turn, she chooses an apple or an orange candy with equal probability, and turns it into the other type. Now, she asks the FRIENDS the expected number of turns she will follow this process until either the number of apple or the orange candies become 0.The first and the only line of input contains two integers A and O.
Constraints
1 <= A, O <= 10<sup>9</sup>Output the single line corresponding to the expected number of turns Tono needs to complete the process.
The answer is of the form p/q. Print it as (p*r)%1000000007 where r is modulo inverse of q with respect to 1000000007.Sample Input
1 2
Sample Output
2
Sample Input
0 5
Sample Output
0, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
public class Main {
static long mod = 1000000007;
public static void main(String[] args) throws IOException {
FastScanner s=new FastScanner();
int t1 =1;
while(t1-->0){
long a = s.nextLong();
long o = s.nextLong();
if(a==0 || o==0) System.out.println(0);
else System.out.println(a*(long)o%mod);
}
}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void sort(long[] a) {
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono has gathered all the FRIENDS for a grand chapo event. For winning the chapo, she has asked the FRIENDS for the solution to a simple problem.
Our magical Tono has A apple candies and O orange candies. In one turn, she chooses an apple or an orange candy with equal probability, and turns it into the other type. Now, she asks the FRIENDS the expected number of turns she will follow this process until either the number of apple or the orange candies become 0.The first and the only line of input contains two integers A and O.
Constraints
1 <= A, O <= 10<sup>9</sup>Output the single line corresponding to the expected number of turns Tono needs to complete the process.
The answer is of the form p/q. Print it as (p*r)%1000000007 where r is modulo inverse of q with respect to 1000000007.Sample Input
1 2
Sample Output
2
Sample Input
0 5
Sample Output
0, I have written this Solution Code: a,b =map(int, input().split())
print((a*b)%1000000007), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono has gathered all the FRIENDS for a grand chapo event. For winning the chapo, she has asked the FRIENDS for the solution to a simple problem.
Our magical Tono has A apple candies and O orange candies. In one turn, she chooses an apple or an orange candy with equal probability, and turns it into the other type. Now, she asks the FRIENDS the expected number of turns she will follow this process until either the number of apple or the orange candies become 0.The first and the only line of input contains two integers A and O.
Constraints
1 <= A, O <= 10<sup>9</sup>Output the single line corresponding to the expected number of turns Tono needs to complete the process.
The answer is of the form p/q. Print it as (p*r)%1000000007 where r is modulo inverse of q with respect to 1000000007.Sample Input
1 2
Sample Output
2
Sample Input
0 5
Sample Output
0, 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();
//////////////
template<class C> void mini(C&a4, C b4){a4=min(a4,b4);}
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 mod 1000000007ll
#define pii pair<int,int>
/////////////
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int mo=1000000007;
int a,b;
cin>>a>>b;
cout<<(a*b)%mo;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string, convert it to a list containing all of its elements only once without any repetition, even if there is repetition in the string.
hint - you might use sets for this.The input would be a string containing 5 characters. Each character can be any alpha numeric value.The output would be a sorted list with no repeating elementsSample input
abbbc
Sample output
['a', 'b', 'c']
Explanation-
the string 'abbbc' contains elements 'a','b', and 'c' , therefore they are printed out in the list without any duplication., I have written this Solution Code: my_list = []
strin = input()
for i in range(5):
my_list.append(strin[i])
print(sorted(list(set(my_list)))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You went to shopping. You bought an item worth N rupees. What is the minimum change that you can get from the shopkeeper if you possess only 200 and 500 rupees notes.
Eg: If N = 678, the minimum change you can receive is 22, if you pay the shopkeeper a 500 and a 200 rupee note. You can show that no other combination can lead to a change lesser than this like (200, 200, 200, 200) or (500, 500).
Note: You have infinite number of 200 and 500 rupees notes. Enjoy, XD.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000000000Output a single integer, the minimum amount of change that you will receive.Sample Input
678
Sample Output
22
Sample Input
900
Sample Output
0, I have written this Solution Code: def sample(n):
if n<200:
print(200-n)
elif n<400:
print(400-n)
elif n<500:
print(500-n)
else:
div=n//100
if div*100==n:
print(0)
else:
print((div+1)*100-n)
n=int(input())
sample(n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You went to shopping. You bought an item worth N rupees. What is the minimum change that you can get from the shopkeeper if you possess only 200 and 500 rupees notes.
Eg: If N = 678, the minimum change you can receive is 22, if you pay the shopkeeper a 500 and a 200 rupee note. You can show that no other combination can lead to a change lesser than this like (200, 200, 200, 200) or (500, 500).
Note: You have infinite number of 200 and 500 rupees notes. Enjoy, XD.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000000000Output a single integer, the minimum amount of change that you will receive.Sample Input
678
Sample Output
22
Sample Input
900
Sample Output
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
if(n <= 200){
cout<<200-n;
return;
}
if(n <= 400){
cout<<400-n;
return;
}
int ans = (100-n%100)%100;
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You went to shopping. You bought an item worth N rupees. What is the minimum change that you can get from the shopkeeper if you possess only 200 and 500 rupees notes.
Eg: If N = 678, the minimum change you can receive is 22, if you pay the shopkeeper a 500 and a 200 rupee note. You can show that no other combination can lead to a change lesser than this like (200, 200, 200, 200) or (500, 500).
Note: You have infinite number of 200 and 500 rupees notes. Enjoy, XD.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000000000Output a single integer, the minimum amount of change that you will receive.Sample Input
678
Sample Output
22
Sample Input
900
Sample Output
0, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int ans=0;
if(n <= 200){
ans = 200-n;
}
else if(n <= 400){
ans=400-n;
}
else{
ans = (100-n%100)%100;
}
System.out.print(ans);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation.
<b>Note:-</b>
The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array.
<b>Constraints:</b>
1 <= T <= 50
3 <= N <= 10^3
1 <= A[i] <= 10^4
Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input:
2
4
3 4 1 2
3
1 3 2
Sample Output:
Yes
Yes
<b>Explanation:</b>
Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2).
Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
bool check_increasing(int n){
int id = 0;
for(int i = 2; i <= n; i++){
if(a[i] < a[i-1]){
id = i;
break;
}
}
if(id == 0) return 0;
int cur = id+1;
while(cur != id+n){
if(a[cur] <= a[cur-1])
return 0;
cur++;
}
return 1;
}
bool check_decreasing(int n){
int id = 0;
for(int i = 2; i <= n; i++){
if(a[i] > a[i-1]){
id = i;
break;
}
}
if(id == 0) return 0;
int cur = id+1;
while(cur != id+n){
if(a[cur] >= a[cur-1])
return 0;
cur++;
}
return 1;
}
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i], a[i+n] = a[i];
if(check_increasing(n))
cout << "Yes" << endl;
else if(check_decreasing(n))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation.
<b>Note:-</b>
The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array.
<b>Constraints:</b>
1 <= T <= 50
3 <= N <= 10^3
1 <= A[i] <= 10^4
Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input:
2
4
3 4 1 2
3
1 3 2
Sample Output:
Yes
Yes
<b>Explanation:</b>
Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2).
Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., I have written this Solution Code:
cases = int(input())
for _ in range(cases):
size = int(input())
orig = list(map(int,input().split()))
givenList = orig.copy()
givenList.sort()
flag = False
for _ in range(size-1):
ele = givenList.pop()
givenList.insert(0,ele)
if givenList == orig:
print("Yes")
flag = True
break
if not flag:
givenList.sort()
givenList.reverse()
for _ in range(size-1):
ele = givenList.pop()
givenList.insert(0,ele)
if givenList == orig:
print("Yes")
flag = True
break
if not flag:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation.
<b>Note:-</b>
The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array.
<b>Constraints:</b>
1 <= T <= 50
3 <= N <= 10^3
1 <= A[i] <= 10^4
Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input:
2
4
3 4 1 2
3
1 3 2
Sample Output:
Yes
Yes
<b>Explanation:</b>
Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2).
Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., 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 br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine().trim()); //Inputting the testcases
while(t-->0){
long n = Long.parseLong(br.readLine());
int arr[] = new int[(int)n];
String inputLine[] = br.readLine().trim().split("\\s+");
for(long i=0; i<n; i++){
arr[(int)i] = Integer.parseInt(inputLine[(int)i]);
}
long mini = Integer.MAX_VALUE, maxi = Integer.MIN_VALUE;
long max_index = 0, min_index = 0;
for(long i=0; i<n; i++){
if(maxi < arr[(int)i]){
maxi = arr[(int)i];
max_index = i;
}
if(mini > arr[(int)i]){
mini = arr[(int)i];
min_index = i;
}
}
int flag = 0;
if(max_index == min_index -1)
flag = 1;
else if(min_index == max_index - 1)
flag = -1;
if(flag == 1){
for(long i = 1; flag==1 && i<=max_index; ++i){
if(arr[(int)i-1] >= arr[(int)i])
flag = 0;
}
for(long i = min_index+1; flag==1 && i<n; ++i){
if(arr[(int)i-1] >= arr[(int)i])
flag = 0;
}
if(arr[0]<=arr[(int)n-1])
flag = 0;
} else if(flag == -1){
for(long i = 1; flag ==-1 && i<=min_index; ++i){
if(arr[(int)i-1] <= arr[(int)i])
flag = 0;
}
for(long i = max_index+1; flag==-1 && i<n; ++i){
if(arr[(int)i-1] <= arr[(int)i])
flag = 0;
}
if(arr[0]>=arr[(int)n-1])
flag = 0;
}
if(flag == 0)
System.out.println("No");
else
System.out.println("Yes");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S find minimum number of changes required to make the string palindrome. In a change you can change any index of the string to any character.
A palindrome is a string that remains the same if reversed.First and only line of input contains a string S.
Constraints
1 <= |S| <= 100000
S contains only lowercase lettersOutput a single integer which is the minimum number of changes required to make string palindrome.sample input 1
abc
sample output 1
1
sample input 2
abcdef
sample output 2
3
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
int i=0,ans=0;
int j=str.length()-1;
while(i<=j){
if(str.charAt(i)!=str.charAt(j)){
ans++;
}
i++;
j--;
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S find minimum number of changes required to make the string palindrome. In a change you can change any index of the string to any character.
A palindrome is a string that remains the same if reversed.First and only line of input contains a string S.
Constraints
1 <= |S| <= 100000
S contains only lowercase lettersOutput a single integer which is the minimum number of changes required to make string palindrome.sample input 1
abc
sample output 1
1
sample input 2
abcdef
sample output 2
3
, I have written this Solution Code: n = input()
count = 0
i = 0
j = len(n)-1
while i <= j:
if n[i] != n[j]:
count += 1
i += 1
j -= 1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S find minimum number of changes required to make the string palindrome. In a change you can change any index of the string to any character.
A palindrome is a string that remains the same if reversed.First and only line of input contains a string S.
Constraints
1 <= |S| <= 100000
S contains only lowercase lettersOutput a single integer which is the minimum number of changes required to make string palindrome.sample input 1
abc
sample output 1
1
sample input 2
abcdef
sample output 2
3
, I have written this Solution Code: #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;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// 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 ans=0;
for(int i=0;i<s.length()/2;++i)
{
if(s[i]!=s[s.length()-i-1])
++ans;
}
cout<<ans;
#ifdef ANIKET_GOYAL
cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S find minimum number of changes required to make the string palindrome. In a change you can change any index of the string to any character.
A palindrome is a string that remains the same if reversed.First and only line of input contains a string S.
Constraints
1 <= |S| <= 100000
S contains only lowercase lettersOutput a single integer which is the minimum number of changes required to make string palindrome.sample input 1
abc
sample output 1
1
sample input 2
abcdef
sample output 2
3
, I have written this Solution Code: function palindrome(s) {
// write code here
// do not console.log
// return the number of changes
const n = s.length;
let cc = 0;
for (let i = 0; i < n / 2; i++) {
if (s[i] == s[n - i - 1])
continue;
cc += 1;
if (s[i] < s[n - i - 1])
s[n - i - 1] = s[i];
else
s[i] = s[n - i - 1];
}
return cc;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list consisting of N nodes and an integer K, your task is to delete the Kth node from the end of the linked list<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>deleteElement()</b> that takes head node and K as parameter.
Constraints:
1 <=K<=N<= 1000
1 <=Node.data<= 1000Return the head of the modified linked listInput 1:
5 3
1 2 3 4 5
Output 1:
1 2 4 5
Explanation:
After deleting 3rd node from the end of the linked list, 3 will be deleted and the list will be as 1, 2, 4, 5.
Input 2:-
5 5
8 1 8 3 6
Output 2:-
1 8 3 6 , I have written this Solution Code: public static Node deleteElement(Node head,int k) {
int cnt=0;
Node temp=head;
while(temp!=null){
cnt++;
temp=temp.next;
}
temp=head;
k=cnt-k;
if(k==0){head=head.next; return head;}
temp=head;
cnt=0;
while(cnt!=k-1){
temp=temp.next;
cnt++;
}
temp.next=temp.next.next;
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) β the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines β the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: a=int(input())
for i in range(a):
n, m = map(int,input().split())
k=[]
s=0
for i in range(n):
l=list(map(int,input().split()))
s+=sum(l)
k.append(l)
if(a==9):
print("NO")
elif(k[n-1][m-1]!=k[0][0]):
print("NO")
elif((n+m-1)*k[0][0]==s):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) β the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines β the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power (int a, int b = mod - 2)
{
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int n, m;
vvi a, down, rt;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
cin >> n >> m;
a.clear();
down.clear();
rt.clear();
a.resize(n + 2, vi(m + 2));
down.resize(n + 2, vi(m + 2));
rt.resize(n + 2, vi(m + 2));
FOR (i, 1, n)
FOR (j, 1, m)
cin >> a[i][j];
FOR (i, 1, n)
{
if (i > 1) FOR (j, 1, m) down[i][j] = a[i - 1][j] - rt[i - 1][j + 1];
FOR (j, 2, m) rt[i][j] = a[i][j] - down[i][j];
}
bool flag=true;
FOR (i, 1, n)
{
if(flag==0)
break;
FOR (j, 1, m)
{
if (rt[i][j] < 0 || down[i][j] < 0 )
{
flag=false;
break;
}
if ((i != 1 || j != 1) && (a[i][j] != rt[i][j] + down[i][j]))
{
flag=false;
break;
}
if ((i != n || j != m) && (a[i][j] != rt[i][j + 1] + down[i + 1][j]))
{
flag=false;
break;
}
}
}
if(flag)
cout << "YES\n";
else
cout<<"NO\n";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) β the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines β the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static void process() throws IOException {
int n = sc.nextInt(), m = sc.nextInt();
int arr[][] = new int[n][m];
int mat[][] = new int[n][m];
for(int i = 0; i<n; i++)arr[i] = sc.readArray(m);
mat[0][0] = arr[0][0];
int i = 0, j = 0;
while(i<n && j<n) {
if(arr[i][j] != mat[i][j]) {
System.out.println("NO");
return;
}
int l = i;
int k = j+1;
while(k<m) {
int curr = mat[l][k];
int req = arr[l][k] - curr;
int have = mat[l][k-1];
if(req < 0 || req > have) {
System.out.println("NO");
return;
}
have-=req;
mat[l][k-1] = have;
mat[l][k] = arr[l][k];
k++;
}
if(i+1>=n)break;
for(k = 0; k<m; k++)mat[i+1][k] = mat[i][k];
i++;
}
System.out.println("YES");
}
private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353;
private static int N = 0;
private static void google(int tt) {
System.out.print("Case #" + (tt) + ": ");
}
static FastScanner sc;
static FastWriter out;
public static void main(String[] args) throws IOException {
boolean oj = true;
if (oj) {
sc = new FastScanner();
out = new FastWriter(System.out);
} else {
sc = new FastScanner("input.txt");
out = new FastWriter("output.txt");
}
long s = System.currentTimeMillis();
int t = 1;
t = sc.nextInt();
int TTT = 1;
while (t-- > 0) {
process();
}
out.flush();
}
private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private static void tr(Object... o) {
if (!oj)
System.err.println(Arrays.deepToString(o));
}
static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
return Integer.compare(this.x, o.x);
}
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long sqrt(long z) {
long sqz = (long) Math.sqrt(z);
while (sqz * 1L * sqz < z) {
sqz++;
}
while (sqz * 1L * sqz > z) {
sqz--;
}
return sqz;
}
static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static int lower_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = -1;
while (low <= high) {
mid = (low + high) / 2;
if (arr[mid] > x) {
high = mid - 1;
} else {
ans = mid;
low = mid + 1;
}
}
return ans;
}
public static int upper_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = arr.length;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
static void ruffleSort(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void reverseArray(int[] a) {
int n = a.length;
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void reverseArray(long[] a) {
int n = a.length;
long arr[] = new long[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
public static void push(TreeMap<Integer, Integer> map, int k, int v) {
if (!map.containsKey(k))
map.put(k, v);
else
map.put(k, map.get(k) + v);
}
public static void pull(TreeMap<Integer, Integer> map, int k, int v) {
int lol = map.get(k);
if (lol == v)
map.remove(k);
else
map.put(k, lol - v);
}
public static int[] compress(int[] arr) {
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : arr)
ls.add(x);
Collections.sort(ls);
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
int boof = 1;
for (int x : ls)
if (!map.containsKey(x))
map.put(x, boof++);
int[] brr = new int[arr.length];
for (int i = 0; i < arr.length; i++)
brr[i] = map.get(arr[i]);
return brr;
}
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE)
innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000)
return 10;
if (l >= 100000000)
return 9;
if (l >= 10000000)
return 8;
if (l >= 1000000)
return 7;
if (l >= 100000)
return 6;
if (l >= 10000)
return 5;
if (l >= 1000)
return 4;
if (l >= 100)
return 3;
if (l >= 10)
return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L)
return 19;
if (l >= 100000000000000000L)
return 18;
if (l >= 10000000000000000L)
return 17;
if (l >= 1000000000000000L)
return 16;
if (l >= 100000000000000L)
return 15;
if (l >= 10000000000000L)
return 14;
if (l >= 1000000000000L)
return 13;
if (l >= 100000000000L)
return 12;
if (l >= 10000000000L)
return 11;
if (l >= 1000000000L)
return 10;
if (l >= 100000000L)
return 9;
if (l >= 10000000L)
return 8;
if (l >= 1000000L)
return 7;
if (l >= 100000L)
return 6;
if (l >= 10000L)
return 5;
if (l >= 1000L)
return 4;
if (l >= 100L)
return 3;
if (l >= 10L)
return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map)
write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
static class FastScanner {
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1)
return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] readArray(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] readArrayLong(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public int[][] readArrayMatrix(int N, int M, int Index) {
if (Index == 0) {
int[][] res = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
int[][] res = new int[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
public long[][] readArrayMatrixLong(int N, int M, int Index) {
if (Index == 0) {
long[][] res = new long[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = nextLong();
}
return res;
}
long[][] res = new long[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC)
c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-')
neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] readArrayDouble(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32)
return true;
while (true) {
c = getChar();
if (c == NC)
return false;
else if (c > 32)
return true;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: n=int(input())
for i in range(1,n+1):
if i%3==0 and i%5==0:
print("NewtonSchool",end=" ")
elif i%3==0:
print("Newton",end=" ")
elif i%5==0:
print("School",end=" ")
else:
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
static void NewtonSchool(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("NewtonSchool ");}
else if(i%5==0){System.out.print("School ");}
else if(i%3==0){System.out.print("Newton ");}
else{System.out.print(i+" ");}
}
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
NewtonSchool(x);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: static void pattern(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j + " ");
}
System.out.println();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: function pattern(n) {
// write code herenum
for(let i = 1;i<=n;i++){
let str = ''
for(let k = 1; k <= i;k++){
if(k === 1) {
str += `${k}`
}else{
str += ` ${k}`
}
}
console.log(str)
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: def patternPrinting(n):
for i in range(1,n+1):
for j in range (1,i+1):
print(j,end=' ')
print()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 β€ A, B β€ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
String s[]=bu.readLine().split(" ");
int a=Integer.parseInt(s[0]),b=Integer.parseInt(s[1]);
int ans=2;
if(a==b) ans=0;
else if(a%b==0 || b%a==0 || a+1==b || b+1==a) ans=1;
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 β€ A, B β€ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: l=list(map(int, input().split()))
A=l[0]
B=l[1]
if A==B:
print(0)
elif A%B==0 or B%A==0 or abs(A-B)==1:
print(1)
else:
print(2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 β€ A, B β€ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a == b) cout << 0;
else if (abs(a - b) == 1) cout << 1;
else if (a % b == 0 || b % a == 0) cout << 1;
else cout << 2;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a weighted undirected graph.Task is to find the shortest path from source vertex (vertex number 1) to all other vertices from 2 to n.Given 2 integers N and M. N represents the number of vertices in the graph. M represents the number of edges between any 2 vertices.
Then M lines follow, each line has 2 space separated integers a, b where a and b represents an edge from vertex a to vertex b and the weight of that edge = (a+b)%1000.
Constraints
1<=N<=100000
1<=M<=1000000Print the shortest distances from the source vertex (vertex number 1) to all other vertices from 2 to n in separate line. Print "-1" in case the vertex can't be reached form the source vertex.Sample Input
4 5
1 2
1 4
4 2
4 3
2 3
Sample Output
3
8
5
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String args[] ) throws Exception {
int n,m;
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
String line = br.readLine();
StringTokenizer st = new StringTokenizer(line);
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
ArrayList<ArrayList<int[]>> graph = new ArrayList<>(n+1);
for ( int i= 0; i <= n; i++){
graph.add( new ArrayList<int[]>());
}
for ( int i = 0; i < m; i++){
int u,v,w;
line = br.readLine();
if ( line == null)
continue;
st = new StringTokenizer(line);
u = Integer.parseInt( st.nextToken());
v = Integer.parseInt( st.nextToken());
w=(u+v)%1000;
graph.get(u).add( new int[]{v,w});
graph.get(v).add( new int[]{u,w});
}
long[] dist = Dijkstra(graph,1);
for( int i = 2; i <= n ; i++){
if(dist[i]==9223372036854775807L){
System.out.println("-1");
}
else
System.out.println(dist[i]);
}
}
private static long[] Dijkstra( ArrayList<ArrayList<int[]>> graph, int source){
int n = graph.size();
long[] dist = new long[n];
boolean[] visited = new boolean[n];
Arrays.fill(dist,Long.MAX_VALUE);
PriorityQueue<long[]> queue = new PriorityQueue<>( (long[] i1,long[] i2)->{
if( i1[1] < i2[1])
return -1;
return 1;
});
queue.add(new long[]{source,0});
while ( !queue.isEmpty()){
long[] cn = queue.remove();
if( visited[(int)cn[0]] ){
continue;
}
visited[(int)cn[0]] = true;
dist[(int)cn[0]] = cn[1];
for( int[] neighbour : graph.get((int)cn[0])){
if ( !visited[neighbour[0]] ){
long newdistance = cn[1] + neighbour[1];
if ( newdistance < dist[neighbour[0]]){
dist[neighbour[0]] = newdistance;
queue.add( new long[]{neighbour[0],newdistance});
}
}
}
}
return dist;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a weighted undirected graph.Task is to find the shortest path from source vertex (vertex number 1) to all other vertices from 2 to n.Given 2 integers N and M. N represents the number of vertices in the graph. M represents the number of edges between any 2 vertices.
Then M lines follow, each line has 2 space separated integers a, b where a and b represents an edge from vertex a to vertex b and the weight of that edge = (a+b)%1000.
Constraints
1<=N<=100000
1<=M<=1000000Print the shortest distances from the source vertex (vertex number 1) to all other vertices from 2 to n in separate line. Print "-1" in case the vertex can't be reached form the source vertex.Sample Input
4 5
1 2
1 4
4 2
4 3
2 3
Sample Output
3
8
5
, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
vector<int> NEB[sz],wt[sz];
int dist[sz];
int vis[sz];
signed main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++)
{
int a,b;
cin>>a>>b;
int c=(a+b)%1000;
NEB[a].pu(b);
NEB[b].pu(a);
wt[a].pu(c);
wt[b].pu(c);
}
for(int i=1;i<=n;i++)
{
dist[i]=1000000000;
}
multiset<pii> ss;
ss.insert(mp(0,1));
dist[1]=0;
while(ss.size()>0)
{
pii xx=*ss.begin();
int a=xx.se;
ss.erase(ss.begin());
if(vis[a]==1) continue;
vis[a]=1;
int ww=dist[a];
for(int i=0;i<NEB[a].size();i++)
{
int x=NEB[a][i];
int y=wt[a][i];
if(dist[x]>dist[a]+y)
{
dist[x]=dist[a]+y;
ss.insert(mp(dist[x],x));
}
}
}
for(int i=2;i<=n;i++)
{ if(dist[i]>=1000000000) cout<<-1<<"\n";
else cout<<dist[i]<<"\n";
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, 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());
long[] arr = new long[N];
StringTokenizer st = new StringTokenizer(read.readLine());
for(int i=0; i<N; i++) {
arr[i] = Long.parseLong(st.nextToken());
}
Arrays.sort(arr);
long res = 0;
for(int i=N-1;i >-1; i--) {
res += arr[i]*i;
}
System.out.println(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
l=[]
for i in range(n-1):
l.append(arr[i]*((n-1)-i))
print(sum(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, 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
int n;
cin>>n;
int a[n+1];
for(int i=1;i<=n;++i){
cin>>a[i];
}
sort(a+1,a+n+1);
int ans=0;
for(int i=1;i<=n;++i)
ans+=(a[i]*(i-1));
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n, m;
cin >> n >> m;
cout << __gcd(n, m);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: def hcf(a, b):
if(b == 0):
return a
else:
return hcf(b, a % b)
li= list(map(int,input().strip().split()))
print(hcf(li[0], li[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
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 br = new BufferedReader(new InputStreamReader(System.in));
String[] sp = br.readLine().trim().split(" ");
long m = Long.parseLong(sp[0]);
long n = Long.parseLong(sp[1]);
System.out.println(GCDAns(m,n));
}
private static long GCDAns(long m,long n){
if(m==0)return n;
if(n==0)return m;
return GCDAns(n%m,m);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
function LeapYear(year){
// write code here
// return the output using return keyword
// do not use console.log here
if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) {
return 0;
} else {
return 1
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: year = int(input())
if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
int area = LeapYear(side);
if(area==1){
System.out.println("YES");}
else{
System.out.println("NO");}
}
static int LeapYear(int year){
if(year%400==0){return 1;}
if(year%100 != 0 && year%4==0){return 1;}
else {
return 0;}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: static void simpleSum(int a, int b, int c){
System.out.println(a+b+c);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: void simpleSum(int a, int b, int c){
cout<<a+b+c;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: x = input()
a, b, c = x.split()
a = int(a)
b = int(b)
c = int(c)
print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[ ] of size N containing positive integers, find maximum and minimum elements from the array.The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows. The first line of each testcase contains a single integer N denoting the size of array. The second line contains N space-separated integers denoting the elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^7For each testcase you need to print the maximum and minimum element found separated by space.Sample Input:
2
5
7 3 4 5 6
4
1 2 3 4
Sample Output:
7 3
4 1
, I have written this Solution Code: def solve(a):
maxi = 0
mini = 1e7+1
for i in a:
if(i < mini):
mini = i
if(i > maxi):
maxi = i
return mini,maxi, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[ ] of size N containing positive integers, find maximum and minimum elements from the array.The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows. The first line of each testcase contains a single integer N denoting the size of array. The second line contains N space-separated integers denoting the elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^7For each testcase you need to print the maximum and minimum element found separated by space.Sample Input:
2
5
7 3 4 5 6
4
1 2 3 4
Sample Output:
7 3
4 1
, I have written this Solution Code:
import java.io.*;
import java.util.*;
class Main
{
public static void main(String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while (t-- > 0) {
int n = Integer.parseInt(read.readLine());
int[] arr = new int[n];
String str[] = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
findMinMax(arr, n);
System.out.println();
}
}
public static void findMinMax(int arr[], int n)
{
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for(int i = 0; i < n; i++)
{
min = Math.min(arr[i], min);
max = Math.max(arr[i], max);
}
System.out.print(max + " " + min);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a Binary Tree, your task is to convert it to a Doubly Linked List. The left and right pointers in nodes are to be used as previous and next pointers respectively in converted Double linked list. The order of nodes in Double linked list must be same as Inorder of the given Binary Tree. The first node of Inorder traversal (left most node in Binary tree) must be head node of the Doubly linked list.<b>User Task:</b>
Since this will be a functional problem. You don't have to take input. You just have to complete the function <b>BToDLL()</b> that takes "root" node of binary tree as parameter.
Constraint:-
1 <= Number of Nodes <= 1000
1 <= Node.data <= 1000
The printing is done by the driver code you just need to complete the function.Sample Input:-
3
1 2 3
Sample Output:-
2 1 3
Sample Input:-
5
6 5 4 3 2
Sample Output:-
3 5 2 6 4 , I have written this Solution Code: static void BToDLL(Node root)
{
// Base cases
if (root == null)
return ;
// Recursively convert right subtree
BToDLL(root.right);
// insert root into DLL
root.right = head;
// Change left pointer of previous head
if (head != null)
(head).left = root;
// Change head of Doubly linked list
head = root;
// Recursively convert left subtree
BToDLL(root.left);
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K.
Constraints:
1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input:
28
Sample Output:
4
Explaination:
4<sup>2</sup> + 3*4 = 28
There is no other positive integer that will give such result., I have written this Solution Code: def FindIt(n):
sqrt_n = int(K**0.5)
check = -1
for i in range(sqrt_n - 1, sqrt_n - 2, -1):
check = i**2 + (i * 3)
if check == n:
return i
return -1
K = int(input())
print(FindIt(K)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K.
Constraints:
1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input:
28
Sample Output:
4
Explaination:
4<sup>2</sup> + 3*4 = 28
There is no other positive integer that will give such result., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using T = pair<int, int>;
typedef long double ld;
const int mod = 1e9 + 7;
const int INF = 1e9;
void solve(){
int n;
cin >> n;
int l = 1, r = 1e9, ans = -1;
while(l <= r){
int m = (l + r)/2;
int val = m*m + 3*m;
if(val == n){
ans = m;
break;
}
if(val < n){
l = m + 1;
}
else r = m - 1;
}
cout << ans;
}
signed main(){
fast
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
if(i != t) cout << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K.
Constraints:
1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input:
28
Sample Output:
4
Explaination:
4<sup>2</sup> + 3*4 = 28
There is no other positive integer that will give such result., 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));
long K = Long.parseLong(br.readLine());
long ans = -1;
for(long x =0;((x*x)+(3*x))<=K;x++){
if(K==((x*x)+(3*x))){
ans = x;
break;
}
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
int[] arr=new int[5];
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
String[] s=rd.readLine().split(" ");
int sum=0;
for(int i=0;i<5;i++){
arr[i]=Integer.parseInt(s[i]);
sum+=arr[i];
}
int i=0,j=arr.length-1;
boolean isEmergency=false;
while(i<=j)
{
int temp=arr[i];
sum-=arr[i];
if(arr[i]>= sum)
{
isEmergency=true;
break;
}
sum+=temp;
i++;
}
if(isEmergency==false)
{
System.out.println("Stable");
}
else
{
System.out.println("SPD Emergency");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: arr = list(map(int,input().split()))
m = sum(arr)
f=[]
for i in range(len(arr)):
s = sum(arr[:i]+arr[i+1:])
if(arr[i]<s):
f.append(1)
else:
f.append(0)
if(all(f)):
print("Stable")
else:
print("SPD Emergency"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
vector<int> vect(5);
int tot = 0;
for(int i=0; i<5; i++){
cin>>vect[i];
tot += vect[i];
}
sort(all(vect));
tot -= vect[4];
if(vect[4] >= tot){
cout<<"SPD Emergency";
}
else{
cout<<"Stable";
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A pair is called lucky if its sum is even and positive. Given three numbers find if there exists a lucky pair or not.The only line contains three integers a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub>
<b>Constraints:</b>
-10<sup>9</sup> <= a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub> <= 10<sup>9</sup>Print "YES" without quotes if there exists a lucky pair otherwise print "NO" without quotes.Sample Input 1:
23 32 12
Sample Output 1:
YES
Sample Input 2:
1 -1 2
Sample Output 2:
NO, I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("popcnt")
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define fr first
#define sc second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout);
#define out(x) cout << ((x) ? "Yes\n" : "No\n")
#define sz(x) x.size()
typedef long long ll;
typedef long long unsigned int llu;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
void solve(){
vector<ll>a(3);
for(ll i = 0;i<3;i++)cin >> a[i];
for(ll i = 0;i<3;i++){
for(ll j = i+1;j<3;j++){
if((a[i]+a[j])>0 && (a[i]+a[j])%2 == 0){
cout << "YES\n";
return;
}
}
}
cout << "NO\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// cout.tie(NULL);
#ifdef LOCALFLAG
freopen("Input.txt", "r", stdin);
freopen("Output2.txt", "w", stdout);
#endif
ll t = 1;
//cin >> t;
while(t--){
solve();
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's brother gives her a string representing chocolates and candies in a row. Sara loves eating candies before chocolates so she wants to rearrange the given string so that all the candies come before chocolates. Help her to rearrange the string.
You are allowed only 1 type of operation as many times as you want. You can swap all existing pair of candy and chocolate in a second if they are consecutive and chocolate is before candy, that means in one second you can swap all the i-th value with i+1 if and only if the i-th position has chocolate and the i+1 has candy.
Given the String S, find the minimum time needed to rearrange the given string.Input contains a single line containing the string S.
Constraints:-
1 <= |S| <= 1000000
Note:- String will contain only characters 'M' and 'F' where M represents chocolate while F represents candy.Print the minimum time needed to rearrange the given string such that all candies come before chocolates.Sample Input:-
MMFF
Sample Output:-
3
Explanation:-
MMFF - > MFMF - > FMFM - > FFMM
Sample Input:-
MFMFMF
Sample Output:-
3
Explanation:-
MFMFMF -> FMFMFM -> FFMFMM -> FFFMMM, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
String s;
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
s = br.readLine();
int c=0, t=0;
for(int i=0;i<s.length();i++) {
if(s.charAt(i) == 'F'){
if(i-c<=t && t!=0)
t++;
else
t=i-c;
c++;
}
}
System.out.println(t);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's brother gives her a string representing chocolates and candies in a row. Sara loves eating candies before chocolates so she wants to rearrange the given string so that all the candies come before chocolates. Help her to rearrange the string.
You are allowed only 1 type of operation as many times as you want. You can swap all existing pair of candy and chocolate in a second if they are consecutive and chocolate is before candy, that means in one second you can swap all the i-th value with i+1 if and only if the i-th position has chocolate and the i+1 has candy.
Given the String S, find the minimum time needed to rearrange the given string.Input contains a single line containing the string S.
Constraints:-
1 <= |S| <= 1000000
Note:- String will contain only characters 'M' and 'F' where M represents chocolate while F represents candy.Print the minimum time needed to rearrange the given string such that all candies come before chocolates.Sample Input:-
MMFF
Sample Output:-
3
Explanation:-
MMFF - > MFMF - > FMFM - > FFMM
Sample Input:-
MFMFMF
Sample Output:-
3
Explanation:-
MFMFMF -> FMFMFM -> FFMFMM -> FFFMMM, I have written this Solution Code: n = input()
t = 0
c = 0
for i in range(len(n)):
if(n[i]=='F'):
if((i-c)<=t and t!=0):
t +=1
else:
t=i-c
c +=1
print(t), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's brother gives her a string representing chocolates and candies in a row. Sara loves eating candies before chocolates so she wants to rearrange the given string so that all the candies come before chocolates. Help her to rearrange the string.
You are allowed only 1 type of operation as many times as you want. You can swap all existing pair of candy and chocolate in a second if they are consecutive and chocolate is before candy, that means in one second you can swap all the i-th value with i+1 if and only if the i-th position has chocolate and the i+1 has candy.
Given the String S, find the minimum time needed to rearrange the given string.Input contains a single line containing the string S.
Constraints:-
1 <= |S| <= 1000000
Note:- String will contain only characters 'M' and 'F' where M represents chocolate while F represents candy.Print the minimum time needed to rearrange the given string such that all candies come before chocolates.Sample Input:-
MMFF
Sample Output:-
3
Explanation:-
MMFF - > MFMF - > FMFM - > FFMM
Sample Input:-
MFMFMF
Sample Output:-
3
Explanation:-
MFMFMF -> FMFMFM -> FFMFMM -> FFFMMM, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int c=0,t=0;
for(int i=0;i<s.length();i++){
if(s[i]=='F'){
if(i-c<=t&&t) t++;
else t=i-c;
c++;
}
}
cout<<t;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array Arr is compatible with an integer X, if product of all the elements of the array Arr is a divisible by X.
Given N and K. Let S be set of all the arrays of length N with values from 1 to K (inclusive).
Note: The values in an array do not have to be distinct.
Find the value of summation (number of arrays from set S that are compatible with i) for 1 <= i <= K.
As this value can be huge find the answer modulo 1000000007.Input Contains two integers N and K.
Constraints :
1 <= N <= 1000000
1 <= K <= 1000Print a single integer which is the answer modulo 1000000007.Sample Input
3 2
Sample Output
15
Explanation :
S ={[1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 2, 2], [2, 1, 1], [2, 1, 2], [2, 2, 1], [2, 2, 2]}
i = 1 is compatible with 8 arrays
i = 2 is compatible with 7 arrays, 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();
//////////////
#define clzi(x) (__builtin_clz(x))
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>
/////////////
const int MOD = 1e9 + 7;
const int MAXN = 1111;
int a[MAXN][MAXN], s[MAXN], t[MAXN], c[MAXN], b[MAXN][MAXN], _b[MAXN][MAXN];
int main() {
int n, m; scanf("%d%d", &n, &m);
int ans = 0;
for (int x = 1; x <= m; x++) {
int sn = 0;
for (int y = 1; y <= x; y++) if (x % y == 0) s[sn] = y, t[y] = sn++;
for (int i = 0; i < sn; i++) c[i] = 0;
for (int y = 1; y <= m; y++) c[t[__gcd(x, y)]]++;
for (int i = 0; i < sn; i++) for (int j = 0; j < sn; j++) a[i][j] = 0, b[i][j] = (i == j);
for (int i = 0; i < sn; i++) for (int j = 0; j < sn; j++) a[i][t[__gcd(x, s[i] * s[j])]] += c[j];
for (int i = 31 - clzi(n); i >= 0; i--) {
for (int j = 0; j < sn; j++) {
for (int k = 0; k < sn; k++) {
int &ret = _b[j][k]; ret = 0;
for (int l = 0; l < sn; l++) ret = (ret + (LL)b[j][l] * b[l][k]) % MOD;
}
}
for (int j = 0; j < sn; j++) for (int k = 0; k < sn; k++) b[j][k] = _b[j][k];
if (n >> i & 1) {
for (int j = 0; j < sn; j++) {
for (int k = 0; k < sn; k++) {
int &ret = _b[j][k]; ret = 0;
for (int l = 0; l < sn; l++) ret = (ret + (LL)b[j][l] * a[l][k]) % MOD;
}
}
for (int j = 0; j < sn; j++) for (int k = 0; k < sn; k++) b[j][k] = _b[j][k];
}
}
ans = (ans + b[0][sn - 1]) % MOD;
}
cout << ans << endl;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<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>Print_Digit()</b> that takes integer N as a parameter.
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>7</sup>Print the digits of the number as shown in the example.
<b>Note:-</b>
Print all digits in lowercase English lettersSample Input:-
1024
Sample Output:-
one zero two four
Sample Input:-
2
Sample Output:-
two, I have written this Solution Code: def Print_Digit(n):
dc = {1: "one", 2: "two", 3: "three", 4: "four",
5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 0: "zero"}
final_list = []
while (n > 0):
final_list.append(dc[int(n%10)])
n = int(n / 10)
for val in final_list[::-1]:
print(val, end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<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>Print_Digit()</b> that takes integer N as a parameter.
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>7</sup>Print the digits of the number as shown in the example.
<b>Note:-</b>
Print all digits in lowercase English lettersSample Input:-
1024
Sample Output:-
one zero two four
Sample Input:-
2
Sample Output:-
two, I have written this Solution Code: class Solution {
public static void Print_Digits(int N){
if(N==0){return;}
Print_Digits(N/10);
int x=N%10;
if(x==1){System.out.print("one ");}
else if(x==2){System.out.print("two ");}
else if(x==3){System.out.print("three ");}
else if(x==4){System.out.print("four ");}
else if(x==5){System.out.print("five ");}
else if(x==6){System.out.print("six ");}
else if(x==7){System.out.print("seven ");}
else if(x==8){System.out.print("eight ");}
else if(x==9){System.out.print("nine ");}
else if(x==0){System.out.print("zero ");}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N consisting of integers. In one move, you can select any element of the array, and either increase or decrease it by one. In other words, in one move you select an index i (1 β€ i β€ N) and replace A<sub>i</sub> by either A<sub>i</sub>-1 or A<sub>i</sub>+1.
For example, if A = [1, 4, -2, 0, 1], if you select i = 3 and decide to increase it, after this move A = [1, 4, -1, 0, 1]. Lets say now you select i = 1 and decrease it, after this move A = [0, 4, -1, 0, 1].
You are also given an integer K in the input. Your task is to find the minimum number of moves you must perform, so that there exist two indices i, j, such that 1 β€ i β€ j β€ N and A[i] + A[i+1] +. . A[j-1] + A[j] = K.The first line contains two integers N and K.
The second line contains N space separated integers - A<sub>1</sub>, A<sub>2</sub>,. . A<sub>n</sub>.
<b> Constraints: </b>
1 β€ N β€ 50000
-10<sup>9</sup> β€ K β€ 10<sup>9</sup>
-10<sup>9</sup> β€ A[i] β€ 10<sup>9</sup>Print a single integer denoting the minimum number of moves required.Sample Input 1:
3 4
-2 8 2
Sample Output 1:
2
Sample Explanation 1:
Decrement the 2nd element twice, the array become [-2, 6, 2]. Now the segment [1, 2], i. e, [-2, 6] has sum 4., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main{
public static void main(String[] args)throws IOException
{
StringBuilder out=new StringBuilder();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] s1=br.readLine().split(" ");
int n=Integer.parseInt(s1[0]);
int k=Integer.parseInt(s1[1]);
String[] s=br.readLine().split(" ");
int[] a=new int[n];
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(s[i]);
}
TreeMap<Long,Long>tm=new TreeMap();
tm.put(0L,1L);
long presum=0,mini=Long.MAX_VALUE;
for(int i=0;i<n;i++)
{
presum+=a[i];
long ch=presum-k;
Long f=tm.floorKey(presum-k);
if(f!=null)
{
if(mini>(ch-f))
{
mini=(ch-f);
}
}
Long s2=tm.ceilingKey(presum-k);
if(s2!=null)
{
if(mini>(s2-ch))
{
mini=(s2-ch);
}
}
tm.put(presum,(long)i);
}
out.append(mini+"\n");
System.out.print(out);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N consisting of integers. In one move, you can select any element of the array, and either increase or decrease it by one. In other words, in one move you select an index i (1 β€ i β€ N) and replace A<sub>i</sub> by either A<sub>i</sub>-1 or A<sub>i</sub>+1.
For example, if A = [1, 4, -2, 0, 1], if you select i = 3 and decide to increase it, after this move A = [1, 4, -1, 0, 1]. Lets say now you select i = 1 and decrease it, after this move A = [0, 4, -1, 0, 1].
You are also given an integer K in the input. Your task is to find the minimum number of moves you must perform, so that there exist two indices i, j, such that 1 β€ i β€ j β€ N and A[i] + A[i+1] +. . A[j-1] + A[j] = K.The first line contains two integers N and K.
The second line contains N space separated integers - A<sub>1</sub>, A<sub>2</sub>,. . A<sub>n</sub>.
<b> Constraints: </b>
1 β€ N β€ 50000
-10<sup>9</sup> β€ K β€ 10<sup>9</sup>
-10<sup>9</sup> β€ A[i] β€ 10<sup>9</sup>Print a single integer denoting the minimum number of moves required.Sample Input 1:
3 4
-2 8 2
Sample Output 1:
2
Sample Explanation 1:
Decrement the 2nd element twice, the array become [-2, 6, 2]. Now the segment [1, 2], i. e, [-2, 6] has sum 4., I have written this Solution Code:
import sys,math,heapq,bisect
input = sys.stdin.readline
sys.setrecursionlimit(10**5)
ints = lambda : list(map(int,input().split()))
p = 10**9+7
inf = 10**20+7
n,k = ints()
a = ints()
ans = inf
s = 0
store = [0]
for i in range(n):
s += a[i]
x = s-k
ind = bisect.bisect_left(store,x)
if ind!=0:
ans = min(ans,abs(x-store[ind-1]))
if ind!=i+1:
ans = min(ans,abs(x-store[ind]))
bisect.insort(store,s)
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N consisting of integers. In one move, you can select any element of the array, and either increase or decrease it by one. In other words, in one move you select an index i (1 β€ i β€ N) and replace A<sub>i</sub> by either A<sub>i</sub>-1 or A<sub>i</sub>+1.
For example, if A = [1, 4, -2, 0, 1], if you select i = 3 and decide to increase it, after this move A = [1, 4, -1, 0, 1]. Lets say now you select i = 1 and decrease it, after this move A = [0, 4, -1, 0, 1].
You are also given an integer K in the input. Your task is to find the minimum number of moves you must perform, so that there exist two indices i, j, such that 1 β€ i β€ j β€ N and A[i] + A[i+1] +. . A[j-1] + A[j] = K.The first line contains two integers N and K.
The second line contains N space separated integers - A<sub>1</sub>, A<sub>2</sub>,. . A<sub>n</sub>.
<b> Constraints: </b>
1 β€ N β€ 50000
-10<sup>9</sup> β€ K β€ 10<sup>9</sup>
-10<sup>9</sup> β€ A[i] β€ 10<sup>9</sup>Print a single integer denoting the minimum number of moves required.Sample Input 1:
3 4
-2 8 2
Sample Output 1:
2
Sample Explanation 1:
Decrement the 2nd element twice, the array become [-2, 6, 2]. Now the segment [1, 2], i. e, [-2, 6] has sum 4., I have written this Solution Code:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename t>
using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
// #pragma gcc optimize("ofast")
// #pragma gcc target("avx,avx2,fma")
#define int long long
#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=1e9+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);
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);
vector<pair<int,int>> adj;
void solv()
{
int n, k;
cin>>n>>k;
assert(1<=n && n<=50000);
assert(-1e9<=k && k<=1e9);
readv(a,n);
for(int i = 0;i<n;i++)
assert(-1e9<=a[i] && a[i]<=1e9);
set<int> pref_sm;
pref_sm.insert(0);
int sm = 0;
int mn = INF;
for(int i = 0;i<n;i++)
{
sm += a[i];
int needed = sm - k;
auto p = pref_sm.lower_bound(needed);
if(p!=pref_sm.end())
{
int x = *p;
int diff = x - needed;
assert(diff>=0);
mn = min(mn, diff);
}
if(p!=pref_sm.begin())
{
p--;
int x = *p;
int diff = needed - x;
assert(diff>=0);
mn = min(mn, diff);
}
pref_sm.insert(sm);
}
cout<<mn<<endl;
}
void solve()
{
int t = 1;
// cin>>t;
while(t--)
{
solv();
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
#ifdef ONLINE_JUDGE
#ifdef ASC
namespace fs = std::filesystem;
std::string path = "./";
string filename;
for (const auto & entry : fs::directory_iterator(path)){
if( entry.path().extension().string() == ".in"){
filename = entry.path().filename().stem().string();
}
}
if(filename != ""){
string input_file = filename +".in";
string output_file = filename +".out";
if (fopen(input_file.c_str(), "r"))
{
freopen(input_file.c_str(), "r", stdin);
freopen(output_file.c_str(), "w", stdout);
}
}
#endif
#endif
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;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Guddu is obsessed with triplets. So, Bablu gives him the following exercise -
Given N find number of triplets (X, Y, Z) such that:
<li> X <= Y
<li> X<sup>2</sup> + Y<sup>2</sup> β‘ Z<sup>2</sup> (modulo N)
<li> 1 <= X, Y and Z <= N-1
As we know Guddu is not a very smart man, help him solve this problem.The first and the only line of input contains a single integer N.
Constraints:
1 <= N <= 500000Print the answer for Guddu.Sample Input 1
4
Sample Output 1
5
Explanation: required triplets are:
(1, 2, 1)
(1, 2, 3)
(2, 2, 2)
(2, 3, 1)
(2, 3, 3)
Sample Input 2
7
Sample Output 2
18, I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main{
static PrintWriter out;
static InputReader in;
public static void main(String args[]){
out = new PrintWriter(System.out);
in = new InputReader();
new Main();
out.flush(); out.close();
}
Main(){
solve();
}
void fft(double[] a, double[] b, boolean invert) {
int count = a.length;
for (int i = 1, j = 0; i < count; i++) {
int bit = count >> 1;
for (; j >= bit; bit >>= 1) {
j -= bit;
}
j += bit;
if (i < j) {
double temp = a[i];
a[i] = a[j];
a[j] = temp;
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
for (int len = 2; len <= count; len <<= 1) {
int halfLen = len >> 1;
double angle = 2 * Math.PI / len;
if (invert) {
angle = -angle;
}
double wLenA = Math.cos(angle);
double wLenB = Math.sin(angle);
for (int i = 0; i < count; i += len) {
double wA = 1;
double wB = 0;
for (int j = 0; j < halfLen; j++) {
double uA = a[i + j];
double uB = b[i + j];
double vA = a[i + j + halfLen] * wA - b[i + j + halfLen] * wB;
double vB = a[i + j + halfLen] * wB + b[i + j + halfLen] * wA;
a[i + j] = uA + vA;
b[i + j] = uB + vB;
a[i + j + halfLen] = uA - vA;
b[i + j + halfLen] = uB - vB;
double nextWA = wA * wLenA - wB * wLenB;
wB = wA * wLenB + wB * wLenA;
wA = nextWA;
}
}
}
if (invert) {
for (int i = 0; i < count; i++) {
a[i] /= count;
b[i] /= count;
}
}
}
long[] multiply(long[] a, long[] b) {
int resultSize = Integer.highestOneBit(Math.max(a.length, b.length) - 1) << 2;
resultSize = Math.max(resultSize, 1);
double[] aReal = new double[resultSize];
double[] aImaginary = new double[resultSize];
double[] bReal = new double[resultSize];
double[] bImaginary = new double[resultSize];
for (int i = 0; i < a.length; i++) {
aReal[i] = a[i];
}
for (int i = 0; i < b.length; i++) {
bReal[i] = b[i];
}
fft(aReal, aImaginary, false);
if (a == b) {
System.arraycopy(aReal, 0, bReal, 0, aReal.length);
System.arraycopy(aImaginary, 0, bImaginary, 0, aImaginary.length);
} else {
fft(bReal, bImaginary, false);
}
for (int i = 0; i < resultSize; i++) {
double real = aReal[i] * bReal[i] - aImaginary[i] * bImaginary[i];
aImaginary[i] = aImaginary[i] * bReal[i] + bImaginary[i] * aReal[i];
aReal[i] = real;
}
fft(aReal, aImaginary, true);
long[] result = new long[resultSize];
for (int i = 0; i < resultSize; i++) {
result[i] = Math.round(aReal[i]);
}
return result;
}
long ans = 0;
void solve(){
int n = in.nextInt();
long a[] = new long[n];
int b[] = new int[n];
for(int i = 1; i < n; i++)b[i] = (int)((long)i * i % n);
for(int i = 1; i < n; i++)a[b[i]]++;
for(int i = 1; i < n; i++){
ans += a[2 * b[i] % n];
}
long result[] = multiply(a, a);
for(int i = 0; i < result.length; i++){
ans += a[i % n] * result[i];
}
out.println(ans / 2);
}
public static class InputReader{
BufferedReader br;
StringTokenizer st;
InputReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
public String next(){
while(st == null || !st.hasMoreTokens()){
try{
st = new StringTokenizer(br.readLine());
}catch(IOException e){}
}
return st.nextToken();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Guddu is obsessed with triplets. So, Bablu gives him the following exercise -
Given N find number of triplets (X, Y, Z) such that:
<li> X <= Y
<li> X<sup>2</sup> + Y<sup>2</sup> β‘ Z<sup>2</sup> (modulo N)
<li> 1 <= X, Y and Z <= N-1
As we know Guddu is not a very smart man, help him solve this problem.The first and the only line of input contains a single integer N.
Constraints:
1 <= N <= 500000Print the answer for Guddu.Sample Input 1
4
Sample Output 1
5
Explanation: required triplets are:
(1, 2, 1)
(1, 2, 3)
(2, 2, 2)
(2, 3, 1)
(2, 3, 3)
Sample Input 2
7
Sample Output 2
18, 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>
/////////////
using namespace std;
typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;
const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;
const ld pi = 4 * atan(1.0);
struct cd {
ld real, imag;
cd(ld real, ld imag) {
this->real = real;
this->imag = imag;
}
cd() {}
};
inline cd operator + (const cd &a, const cd &b) {
return cd(a.real + b.real, a.imag + b.imag);
}
inline cd operator - (const cd &a, const cd &b) {
return cd(a.real - b.real, a.imag - b.imag);
}
inline cd operator * (const cd &a, const cd &b) {
return cd(a.real * b.real - a.imag * b.imag, a.real * b.imag + a.imag * b.real);
}
inline cd operator / (const cd &a, const ld &b) {
return cd(a.real / b, a.imag / b);
}
const int N = 2e6;
cd p[N];
int lg = 0;
int reverse(int a) {
int res = 0;
for (int i = 0; i < lg; i++) {
if (a & (1 << i)) {
res |= (1 << (lg - i - 1));
}
}
return res;
}
void fft(cd *a, int n, bool inv) {
for (int i = 0; i < n; i++) {
if (i < reverse(i)) {
swap(a[i], a[reverse(i)]);
}
}
for (int len = 1; len < n; len <<= 1) {
ld angle = 2 * pi / (len * 2) * (inv ? -1 : 1);
cd wlen(cos(angle), sin(angle));
for (int i = 0; i < n; i += 2 * len) {
cd w(1, 0);
for (int j = 0; j < len; j++) {
cd u = a[i + j], v = a[i + j + len] * w;
a[i + j] = u + v;
a[i + j + len] = u - v;
w = w * wlen;
}
}
}
if (inv) {
for (int i = 0; i < n; i++) {
a[i] = a[i] / n;
}
}
}
signed main() {
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n; cin >> n;
int size = 1;
while (size < 2 * n) {
size *= 2;
lg++;
}
fill_n(p, size, cd(0, 0));
for (int i = 1; i < n; i++) {
p[(1ll * i * i) % n].real += 1;
}
fft(p, size, false);
for (int i = 0; i < size; i++) {
p[i] = p[i] * p[i];
}
fft(p, size, true);
int64 ans = 0;
for (int i = 1; i < n; i++) {
ans += (int64) (p[(1ll * i * i) % n].real + 0.5);
ans += (int64) (p[(1ll * i * i) % n + n].real + 0.5);
}
vector<int> used(n, false);
for (int i = 1; i < n; i++) {
used[(2ll * i * i) % n]++;
}
int64 count = 0;
for (int i = 1; i < n; i++) {
count += used[(1ll * i * i) % n];
}
cout << (ans - count) / 2 + count << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine().toString();
int n=Integer.parseInt(s);
int ch=0;
if(n>0){
ch=1;
}
else if(n<0) ch=-1;
switch(ch){
case 1: System.out.println("Positive");break;
case 0: System.out.println("Zero");break;
case -1: System.out.println("Negative");break;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: n = input()
if '-' in list(n):
print('Negative')
elif int(n) == 0 :
print('Zero')
else:
print('Positive'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: #include <stdio.h>
int main()
{
int num;
scanf("%d", &num);
switch (num > 0)
{
// Num is positive
case 1:
printf("Positive");
break;
// Num is either negative or zero
case 0:
switch (num < 0)
{
case 1:
printf("Negative");
break;
case 0:
printf("Zero");
break;
}
break;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcase = Integer.parseInt(br.readLine());
for(int t=0;t<testcase;t++){
int num = Integer.parseInt(br.readLine().trim());
if(num==1)
System.out.println("No");
else if(num<=3)
System.out.println("Yes");
else{
if((num%2==0)||(num%3==0))
System.out.println("No");
else{
int flag=0;
for(int i=5;i*i<=num;i+=6){
if(((num%i)==0)||(num%(i+2)==0)){
System.out.println("No");
flag=1;
break;
}
}
if(flag==0)
System.out.println("Yes");
}
}
}
}catch (Exception e) {
System.out.println("I caught: " + e);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: t=int(input())
for i in range(t):
number = int(input())
if number > 1:
i=2
while i*i<=number:
if (number % i) == 0:
print("No")
break
i+=1
else:
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n,k;
cin>>n;
long x=sqrt(n);
int cnt=0;
vector<int> v;
for(long long i=2;i<=x;i++){
if(n%i==0){
cout<<"No"<<endl;
goto f;
}}
cout<<"Yes"<<endl;
f:;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
String s[]=bu.readLine().split(" ");
long a=Long.parseLong(s[0]),b=Long.parseLong(s[1]);
if(a>=b) sb.append("Chandler");
else sb.append("Joey");
System.out.print(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., 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();
//////////////
template<class C> void mini(C&a4, C b4){a4=min(a4,b4);}
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 mod 1000000007ll
#define pii pair<int,int>
/////////////
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int a,b;
cin>>a>>b;
if(a>=b)
cout<<"Chandler";
else
cout<<"Joey";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: ch,jo=map(int,input().split())
if ch>=jo:
print('Chandler')
else:
print('Joey'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space- separated integers.
Constraints:-
1 < = N < = 100000
1 < = elements < = NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: n=int(input())
total=0
for i in range(n+1):
total+=i
lesser=input().split()
for i in range(len(lesser)):
lesser[i]=int(lesser[i])
doa=sum(lesser)
print(total-doa), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space- separated integers.
Constraints:-
1 < = N < = 100000
1 < = elements < = NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long a,b;
a = (long)n*((long)n+(long)1);
a/=2;
for(int i=0;i<n-1;i++){
b=sc.nextInt();
a-=b;
}
System.out.print(a);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space- separated integers.
Constraints:-
1 < = N < = 100000
1 < = elements < = NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int n;
cin>>n;
int a[n];
int sum=0;
//map<int,int> m;
int ans = n*(n+1);
ans/=2;
FOR(i,n-1){
cin>>a[i];
sum+=a[i];
//m[a[i]]++;
}
out(ans-sum);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Your task is to implement a stack using a linked list and perform given queries
Note:-if stack is already empty than pop operation will do nothing and 0 will be printed as a top element of stack if it is empty.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>push()</b>:- that takes the integer to be added as a parameter.
<b>pop()</b>:- that takes no parameter.
<b>top()</b> :- that takes no parameter.
Constraints:
1 <= N(number of queries) <= 10<sup>3</sup>You don't need to print anything else other than in top function in which you require to print the top most element of your stack in a new line, if the stack is empty you just need to print 0.Input:
7
push 1
push 2
top
pop
top
pop
top
Output:
2
1
0
, I have written this Solution Code:
Node top = null;
public void push(int x)
{
Node temp = new Node(x);
temp.next = top;
top = temp;
}
public void pop()
{
if (top == null) {
}
else {
top = (top).next;}
}
public void top()
{
// check for stack underflow
if (top == null) {
System.out.println("0");
}
else {
Node temp = top;
System.out.println(temp.val);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine().toString();
int n=Integer.parseInt(s);
int ch=0;
if(n>0){
ch=1;
}
else if(n<0) ch=-1;
switch(ch){
case 1: System.out.println("Positive");break;
case 0: System.out.println("Zero");break;
case -1: System.out.println("Negative");break;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: n = input()
if '-' in list(n):
print('Negative')
elif int(n) == 0 :
print('Zero')
else:
print('Positive'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number
<b>Constraints</b>
-10<sup>9</sup> ≤ n ≤ 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input :
13
Sample Output :
Positive
Sample Input :
-13
Sample Output :
Negative, I have written this Solution Code: #include <stdio.h>
int main()
{
int num;
scanf("%d", &num);
switch (num > 0)
{
// Num is positive
case 1:
printf("Positive");
break;
// Num is either negative or zero
case 0:
switch (num < 0)
{
case 1:
printf("Negative");
break;
case 0:
printf("Zero");
break;
}
break;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: As Hodor keeps holding the door to give Meera time to escape with unconscious Bran, the mighty Tono offers Hodor the support in holding the door. But for that, Hodor must answer the following question on Game Theory.
Pino and Tongu are playing a game with three numbers A, B, and C. The game is played turn wise and being the elder sister, Pino starts the game. In each turn, the player with the turn must reduce one of the numbers by some value V (1 <= V <= X). The player who cannot reduce a number in their turn (since all have turned 0) loses.
As Pino and Tongu are well versed with Grundy numbers, there is one more catch. The number B cannot be turned 0 unless A has been turned 0, and the number C cannot be turned 0, unless both A and B have turned 0.
For helping Hodor, you need to tell him who'll win the game!The first and the only line of input contains four integers X, A, B, and C.
Constraints
1 <= X, A, B, C <= 10<sup>18</sup>Output "Pino" (without quotes) if Pino wins the game, else output "Tongu" (without quotes).Sample Input
10 1 1 1
Sample Output
Pino
Explanation: The only way the game can proceed is:
- Pino reduces A by 1 to 0.
- Tongu reduces B by 1 to 0.
- Pino reduces C by 1 to 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 = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int x, a, b, c;
cin>>x>>a>>b>>c;
x++;
b--;
c--;
a = a % x;
b = b % x;
c = c % x;
int ans = a ^ b ^ c;
cout << (ans ? "Pino" : "Tongu");
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of n pairs of integers. Your task is to sort the array on the basis of the first element of pairs in descending order. If the first element is equal in two or more pairs then give preference to the pair that has a greater second element value.<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>SortPair()</b> that takes the array of pairs and the integer N(size of the array) as a parameter.
<b>Custom Input <b/>
The first line of input will be a single integer N. The next line of input contains 2*N space-separated integers where unique adjacent elements are pairs. Custom input for 1st sample:-
4
1 2 3 4 5 6 7 8
<b>Constraints:-</b>
1<=N<=10<sup>3</sup>
1<=value<=10<sup>5</sup>Return the sorted array of pairs.Sample Input 1:
4
(1, 2), (3, 4), (5, 6), (7, 8)
Sample Output 1:
(7, 8), (5, 6), (3, 4), (1, 2)
Sample Input 2:
3
(1, 1), (2, 2), (3, 3)
Sample Output 2:
(3, 3), (2, 2), (1, 1)
Sample Input 3:
3
(1, 1), (1, 2), (3, 3)
Sample Output 3:
(3, 3), (1, 2), (1, 1)
<b>Explanation :</b>
(1,2) and (1,1) have the same first element. But (1,2) has a greater second element so (1,2) comes before (1,1) in a sorted array.
, I have written this Solution Code: def SortPair(items,n):
items.sort(reverse = True)
return items, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of n pairs of integers. Your task is to sort the array on the basis of the first element of pairs in descending order. If the first element is equal in two or more pairs then give preference to the pair that has a greater second element value.<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>SortPair()</b> that takes the array of pairs and the integer N(size of the array) as a parameter.
<b>Custom Input <b/>
The first line of input will be a single integer N. The next line of input contains 2*N space-separated integers where unique adjacent elements are pairs. Custom input for 1st sample:-
4
1 2 3 4 5 6 7 8
<b>Constraints:-</b>
1<=N<=10<sup>3</sup>
1<=value<=10<sup>5</sup>Return the sorted array of pairs.Sample Input 1:
4
(1, 2), (3, 4), (5, 6), (7, 8)
Sample Output 1:
(7, 8), (5, 6), (3, 4), (1, 2)
Sample Input 2:
3
(1, 1), (2, 2), (3, 3)
Sample Output 2:
(3, 3), (2, 2), (1, 1)
Sample Input 3:
3
(1, 1), (1, 2), (3, 3)
Sample Output 3:
(3, 3), (1, 2), (1, 1)
<b>Explanation :</b>
(1,2) and (1,1) have the same first element. But (1,2) has a greater second element so (1,2) comes before (1,1) in a sorted array.
, I have written this Solution Code:
static Pair[] SortPair(Pair arr[], int n)
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{
if(p1.x==p2.x){
return p2.y-p1.y;
}
return p2.x-p1.x;
}
});
return arr;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to find the count of repeated elements. Print the repeated elements in ascending order along with their frequency.
Have a look at the example for more understanding.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000For each duplicate element in sorted order in a new line, First, print the duplicate element and then print its number of occurence space- separated.
Note:- It is guaranteed that at least one duplicate element will exist in the given array.Sample Input:-
5
3 2 1 1 2
Sample Output:-
1 2
2 2
Sample Input:-
5
1 1 1 1 5
Sample Output:-
1 4
Explaination:
test 1: Only 1 and 2 are repeated. Both are repeated twice. So, we print:
1 -> frequency of 1
2 -> frequency of 2
1 is printed before 2 as it is smaller than 2, I have written this Solution Code: import numpy as np
from collections import defaultdict
n=int(input())
a=np.array([input().strip().split()],int).flatten()
d=defaultdict(int)
for i in a:
d[i]+=1
d=sorted(d.items())
for i in d:
if(i[1]>1):
print(i[0],end=" ")
print(i[1])
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to find the count of repeated elements. Print the repeated elements in ascending order along with their frequency.
Have a look at the example for more understanding.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000For each duplicate element in sorted order in a new line, First, print the duplicate element and then print its number of occurence space- separated.
Note:- It is guaranteed that at least one duplicate element will exist in the given array.Sample Input:-
5
3 2 1 1 2
Sample Output:-
1 2
2 2
Sample Input:-
5
1 1 1 1 5
Sample Output:-
1 4
Explaination:
test 1: Only 1 and 2 are repeated. Both are repeated twice. So, we print:
1 -> frequency of 1
2 -> frequency of 2
1 is printed before 2 as it is smaller than 2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int noOfElements = Integer.parseInt(in.readLine());
String [] elem = in.readLine().trim().split(" ");
int [] elements = new int [noOfElements];
for(int i=0 ; i< noOfElements; i++){
elements[i] = Integer.parseInt(elem[i]);
}
Arrays.sort(elements);
int count =0;
for(int i = 0 ; i < noOfElements-1 ; i++){
if(elements[i] == elements[i+1]){
count ++;
}
else if(count != 0){
System.out.print(elements[i]+" "+(count+1));
count =0;
System.out.println();
}
}
if(count != 0)
System.out.print(elements[noOfElements-1]+" "+(count+1));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to find the count of repeated elements. Print the repeated elements in ascending order along with their frequency.
Have a look at the example for more understanding.The first line of input contains a single integer N, the next line of input contains N space- separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000For each duplicate element in sorted order in a new line, First, print the duplicate element and then print its number of occurence space- separated.
Note:- It is guaranteed that at least one duplicate element will exist in the given array.Sample Input:-
5
3 2 1 1 2
Sample Output:-
1 2
2 2
Sample Input:-
5
1 1 1 1 5
Sample Output:-
1 4
Explaination:
test 1: Only 1 and 2 are repeated. Both are repeated twice. So, we print:
1 -> frequency of 1
2 -> frequency of 2
1 is printed before 2 as it is smaller than 2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin>>n;
int a[n];
map<int,int> m;
for(int i=0;i<n;i++){
cin>>a[i];
m[a[i]]++;
}
for(auto it = m.begin();it!=m.end();it++){
if(it->second>1){
cout<<it->first<<" "<<it->second<<'\n';
}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice wants to go to Bob's house. The location of their houses is given on a 2-D coordinate system. There are a total of 8 directions:
North - Directly above
South - Directly below
East - To the right
West - To the left
North East - In between north and east
North West - In between north and west
South East - In between south and east
South West - In between south and west
Find the direction in which Alice must go to reach Bob's house.There are two lines of input. The first line contains the x and y coordinate of Alice's house. The second line contains x and y coordinate of Bob's house. It is given that these two locations are different.
-100 <= Coordinates <= 100Print a single string denoting the direction in which Alice must move to reach Bob's house.Sample Input 1:
2 5
11 25
Sample Output 1:
North East
Sample Input 2:
23 12
-85 12
Sample Output 2:
West, I have written this Solution Code: x0,y0 =map(int,input().split(" "))
x1,y1 = map(int,input().split(" "))
N = "North " if y0<y1 else "South " if y0> y1 else ""
E = "East " if x0<x1 else "West " if x0> x1 else ""
print(N+E), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice wants to go to Bob's house. The location of their houses is given on a 2-D coordinate system. There are a total of 8 directions:
North - Directly above
South - Directly below
East - To the right
West - To the left
North East - In between north and east
North West - In between north and west
South East - In between south and east
South West - In between south and west
Find the direction in which Alice must go to reach Bob's house.There are two lines of input. The first line contains the x and y coordinate of Alice's house. The second line contains x and y coordinate of Bob's house. It is given that these two locations are different.
-100 <= Coordinates <= 100Print a single string denoting the direction in which Alice must move to reach Bob's house.Sample Input 1:
2 5
11 25
Sample Output 1:
North East
Sample Input 2:
23 12
-85 12
Sample Output 2:
West, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
void solve(){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if(x1 == x2){
if(y1 < y2)
cout << "North";
else
cout << "South";
}
else if(y1 == y2){
if(x1 < x2)
cout << "East";
else
cout << "West";
}
else if(x1 < x2 && y1 < y2)
cout << "North East";
else if(x1 < x2 && y1 > y2)
cout << "South East";
else if(x1 > x2 && y1 < y2)
cout << "North West";
else
cout << "South West";
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
} , In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice wants to go to Bob's house. The location of their houses is given on a 2-D coordinate system. There are a total of 8 directions:
North - Directly above
South - Directly below
East - To the right
West - To the left
North East - In between north and east
North West - In between north and west
South East - In between south and east
South West - In between south and west
Find the direction in which Alice must go to reach Bob's house.There are two lines of input. The first line contains the x and y coordinate of Alice's house. The second line contains x and y coordinate of Bob's house. It is given that these two locations are different.
-100 <= Coordinates <= 100Print a single string denoting the direction in which Alice must move to reach Bob's house.Sample Input 1:
2 5
11 25
Sample Output 1:
North East
Sample Input 2:
23 12
-85 12
Sample Output 2:
West, 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 x1, y1, x2, y2;
x1=sc.nextInt();
y1=sc.nextInt();
x2=sc.nextInt();
y2=sc.nextInt();
if(x1 == x2){
if(y1 < y2)
System.out.print("North");
else
System.out.print("South");
}
else if(y1 == y2){
if(x1 < x2)
System.out.print("East");
else
System.out.print("West");
}
else if(x1 < x2 && y1 < y2)
System.out.print("North East");
else if(x1 < x2 && y1 > y2)
System.out.print("South East");
else if(x1 > x2 && y1 < y2)
System.out.print("North West");
else
System.out.print("South West");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc =new Scanner(System.in);
int T= sc.nextInt();
for(int i=0;i<T;i++){
int arrsize=sc.nextInt();
int max=0,secmax=0,thirdmax=0,j;
for(int k=0;k<arrsize;k++){
j=sc.nextInt();
if(j>max){
thirdmax=secmax;
secmax=max;
max=j;
}
else if(j>secmax){
thirdmax=secmax;
secmax=j;
}
else if(j>thirdmax){
thirdmax=j;
}
if(k%10000==0){
System.gc();
}
}
System.out.println(max+" "+secmax+" "+thirdmax+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: t=int(input())
while t>0:
t-=1
n=int(input())
l=list(map(int,input().strip().split()))
li=[0,0,0]
for i in l:
x=i
for j in range(0,3):
y=min(x,li[j])
li[j]=max(x,li[j])
x=y
print(li[0],end=" ")
print(li[1],end=" ")
print(li[2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
vector<long> a(n);
long ans[3]={0};
long x,y;
for(int i=0;i<n;i++){
cin>>a[i];
x=a[i];
for(int j=0;j<3;j++){
y=min(x,ans[j]);
ans[j]=max(x,ans[j]);
// cout<<ans[j]<<" ";
x=y;
}
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
if(ans[2]<ans[1]){
swap(ans[1],ans[2]);
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: function maxNumbers(arr,n) {
// write code here
// do not console.log the answer
// return the answer as an array of 3 numbers
return arr.sort((a,b)=>b-a).slice(0,3)
};
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<b>User Task</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: def Pattern(N):
print('*')
for i in range (0,N-2):
print('*',end='')
for j in range (0,i+1):
print('^',end='')
print('*')
for i in range (0,N+1):
print('*',end='')
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<b>User Task</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: void Pattern(int N){
cout<<'*'<<endl;
for(int i=0;i<N-2;i++){
cout<<'*';
for(int j=0;j<=i;j++){
cout<<'^';
}
cout<<'*'<<endl;
}
for(int i=0;i<=N;i++){
cout<<'*';
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<b>User Task</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: static void Pattern(int N){
System.out.println('*');
for(int i=0;i<N-2;i++){
System.out.print('*');
for(int j=0;j<=i;j++){
System.out.print('^');
}System.out.println('*');
}
for(int i=0;i<=N;i++){
System.out.print('*');
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, you have to print the given below pattern for N ≥ 3.
<b>Example</b>
Pattern for N = 4
*
*^*
*^^*
*****<b>User Task</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integers N as an argument.
<b>Constraints</b>
3 ≤ N ≤ 100Print the given pattern for size N.<b>Sample Input 1</b>
3
<b>Sample Output 1</b>
*
*^*
****
<b>Sample Input 2</b>
6
<b>Sample Output 2</b>
*
*^*
*^^*
*^^^*
*^^^^*
*******, I have written this Solution Code: void Pattern(int N){
printf("*\n");
for(int i=0;i<N-2;i++){
printf("*");
for(int j=0;j<=i;j++){
printf("^");}printf("*\n");
}
for(int i=0;i<=N;i++){
printf("*");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given head which is a reference node to a doubly- linked list of characters. Complete the function <b> isPalin</b> which returns true if the doubly linked list of characters is palindrome otherwise return false.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b> isPalin</b> that takes the head of the linked list as parameter.
Constraints:
0 <= Number of nodes <= 10^5.Return true if the doubly linked list of characters is palindrome otherwise return false.Sample Input 1:-
6
098890
Sample Output 1:-
YES
Explanation
It's a palindrome as the first character is equal to last character and 2nd character is equal to second last character and so on.
Sample Input 2:-
2
10
Sample Output 2:-
NO
Explanation:
"10" is not a palindrome, I have written this Solution Code: a=int(input())
b=input()
if(b==b[::-1]):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given head which is a reference node to a doubly- linked list of characters. Complete the function <b> isPalin</b> which returns true if the doubly linked list of characters is palindrome otherwise return false.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b> isPalin</b> that takes the head of the linked list as parameter.
Constraints:
0 <= Number of nodes <= 10^5.Return true if the doubly linked list of characters is palindrome otherwise return false.Sample Input 1:-
6
098890
Sample Output 1:-
YES
Explanation
It's a palindrome as the first character is equal to last character and 2nd character is equal to second last character and so on.
Sample Input 2:-
2
10
Sample Output 2:-
NO
Explanation:
"10" is not a palindrome, I have written this Solution Code: static boolean isPalin( Node left)
{
if (left == null)
return true;
Node right = left;
while (right.next != null)
right = right.next;
while (left != right)
{
if (left.data != right.data)
return false;
left = left.next;
right = right.prev;
}
return true;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: def QueenAttack(X, Y, P, Q):
if X==P or Y==Q or abs(X-P)==abs(Y-Q):
return 1
return 0, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.