Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: for _ in range(int(input())):
n = input()
res = map(str, sorted(list( map(int,input().split()))))
print(' '.join(res)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Internet download speed is often expressed in bit per second whereas file size is expressed in Bytes. It is known that 1 Byte = 8 bits. Given file size in megabytes(MB) and internet speed in megabits per seconds(Mbps), find the time taken in seconds to download the file.The only line of input contains two integers denoting the file size in MB and download speed in Mbps.
1 <= file size <= 1000
1 <= download speed <= 1000Print a single integer denoting the time taken to download the file in seconds.
It is guaranteed that the result will be an integer.Sample Input:
10 16
Sample Output:
5, 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 f, s;
cin >> f >> s;
cout << (8*f)/s << endl;
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
} , In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Internet download speed is often expressed in bit per second whereas file size is expressed in Bytes. It is known that 1 Byte = 8 bits. Given file size in megabytes(MB) and internet speed in megabits per seconds(Mbps), find the time taken in seconds to download the file.The only line of input contains two integers denoting the file size in MB and download speed in Mbps.
1 <= file size <= 1000
1 <= download speed <= 1000Print a single integer denoting the time taken to download the file in seconds.
It is guaranteed that the result will be an integer.Sample Input:
10 16
Sample Output:
5, 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 f = sc.nextInt();
int s = sc.nextInt();
int ans = (8*f)/s;
System.out.print(ans);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Internet download speed is often expressed in bit per second whereas file size is expressed in Bytes. It is known that 1 Byte = 8 bits. Given file size in megabytes(MB) and internet speed in megabits per seconds(Mbps), find the time taken in seconds to download the file.The only line of input contains two integers denoting the file size in MB and download speed in Mbps.
1 <= file size <= 1000
1 <= download speed <= 1000Print a single integer denoting the time taken to download the file in seconds.
It is guaranteed that the result will be an integer.Sample Input:
10 16
Sample Output:
5, I have written this Solution Code: a = list(map(int,input().strip().split()))[:2]
print(int((a[0]*8)/a[1])), 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. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: // arr is unsorted array
// n is the number of elements in the array
function insertionSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void insertionSort(int[] arr){
for(int i = 0; i < arr.length-1; i++){
for(int j = i+1; j < arr.length; j++){
if(arr[i] > arr[j]){
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
}
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while(T > 0){
int n = scan.nextInt();
int arr[] = new int[n];
for(int i = 0; i<n; i++){
arr[i] = scan.nextInt();
}
insertionSort(arr);
for(int i = 0; i<n; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
T--;
System.gc();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: def InsertionSort(arr):
arr.sort()
return arr, 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:
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 a string S containing only characters 'a' and 'b'. Your task is to modify string by deleting characters such that there is no 'b' behind 'a' i. e there is no pair of indices (i, j) such that i < j and s[i] = 'b' and s[j]= 'a'.Input contains a single string S.
Constraints:-
1 <= |S| <= 100000
S[] = {a, b}Print the minimum number of operations requiredSample Input:-
abbabbbbbb
Sample Output:-
1
Explanation:-
resulting string:- abbbbbbbb
Sample Input:-
a
Sample Output:-
0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.next();
int b=0;
int remove=0;
if(s==null || s.isEmpty())
System.out.print(0);
else{
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='a'){
if(b>0){
remove++;
b--;
}
}
else{
b++;
}
}
System.out.print(remove);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S containing only characters 'a' and 'b'. Your task is to modify string by deleting characters such that there is no 'b' behind 'a' i. e there is no pair of indices (i, j) such that i < j and s[i] = 'b' and s[j]= 'a'.Input contains a single string S.
Constraints:-
1 <= |S| <= 100000
S[] = {a, b}Print the minimum number of operations requiredSample Input:-
abbabbbbbb
Sample Output:-
1
Explanation:-
resulting string:- abbbbbbbb
Sample Input:-
a
Sample Output:-
0, 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 101
#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);
}
int solve(string s){
int n = s.length();
int pre[n],suf[n];
int cnt=0,sum=0;
for(int i=0;i<n;i++){
if(s[i]=='b'){cnt++;}
if(s[n-i-1]=='a'){sum++;}
pre[i]=cnt;
suf[n-i-1]=sum;
}
int ans=min(pre[n-1],suf[0]);
for(int i=0;i<n-1;i++){
ans=min(pre[i]+suf[i+1],ans);
}
return ans;
}
signed main(){
string s;
cin>>s;
cout<<solve(s);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the heads of two singly linked lists head1 and head2, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null
For example, the following two linked lists begin to intersect at node c1<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>intersection()</b> that takes the head node of both lists as a parameter.
The first line of the test case contains:
<ul>
<li>the size of the 1st linked list</li>
<li>size of 2nd linked list</li>
<li>the size of the common part of two linked lists</li>
</ul>
The rest of the test case contains:
<ul>
<li>elements of 1st linked list</li>
<li>elements of 2nd linked list</li>
<li>common part of two linked lists</li>
</ul>Return the node of intersectionSample Input:-
4 3 4
1 2 3 4
5 6 7
9 10 11 12
Sample Output:-
9
Explanation:
1 -> 2 -> 3 -> 4
      |
       9 -> 10 -> 11 -> 12
      |
  5 -> 6 -> 7, I have written this Solution Code:
public static Node intersection(Node head1,Node head2){ int aLength = getLength(head1), bLength = getLength(head2);
Node currA = head1, currB = head2;
if (bLength > aLength)
for (int i = 0; i < bLength - aLength; i++) currB = currB.next;
if (aLength > bLength)
for (int i = 0; i < aLength - bLength; i++) currA = currA.next;
while (currA != null && currB != null) {
if (currA == currB) return currA;
currA = currA.next;
currB = currB.next;
}
return null;
}
private static int getLength(Node head) {
Node curr = head;
int len = 0;
while (curr != null) {
curr = curr.next;
len++;
}
return len;
}
, 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: Consider the integer sequence A = {1, 2, 3, ...., N} i.e. the first N natural numbers in order.
You are now given two integers, L and S. Determine whether there exists a subarray with length L and sum S after removing <b>at most one</b> element from A.
A <b>subarray</b> of an array is a non-empty sequence obtained by removing zero or more elements from the front of the array, and zero or more elements from the back of the array.The first line contains a single integer T, the number of test cases.
T lines follow. Each line describes a single test case and contains three integers: N, L, and S.
<b>Constraints:</b>
1 <= T <= 100
2 <= N <= 10<sup>9</sup>
1 <= L <= N-1
1 <= S <= 10<sup>18</sup> <b> (Note that S will not fit in a 32-bit integer) </b>For each testcase, print "YES" (without quotes) if a required subarray can exist, and "NO" (without quotes) otherwise.Sample Input:
3
5 3 11
5 3 5
5 3 6
Sample Output:
YES
NO
YES
Sample Explanation:
For the first test case, we can remove 3 from A to obtain A = {1, 2, 4, 5} where {2, 4, 5} is a required subarray of size 3 and sum 11., I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <sys/resource.h>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// DEFINE STATEMENTS
const long long INF = 1e18;
const int INFINT = INT_MAX/2;
#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 f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x, y) freopen(x, "r", stdin); freopen(y, "w", stdout);
#define out(x) cout << ((x) ? "YES\n" : "NO\n")
#define CASE(x, y) cout << "Case #" << x << ":" << " \n"[y]
#define start_clock() auto start_time = std::chrono::high_resolution_clock::now(); auto end_time = start_time;
#define measure() end_time = std::chrono::high_resolution_clock::now(); cerr << (end_time - start_time)/std::chrono::milliseconds(1) << "ms" << endl;
#define reset_clock() start_time = std::chrono::high_resolution_clock::now();
typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifdef LOCALY
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
// DEBUG FUNCTIONS END
// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // FOR RANDOM NUMBER GENERATION
ll mod_exp(ll a, ll b, ll c)
{
ll res=1; a=a%c;
while(b>0)
{
if(b%2==1)
res=(res*a)%c;
b/=2;
a=(a*a)%c;
}
return res;
}
ll norm(ll a,ll b)
{
return (((a = a%b) < 0) ? a + b : a);
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
g++; g--; //this line was added just to remove compiler warning
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct Graph
{
vector<vector<int>> adj;
Graph(int n): adj(n+1) {}
void add_edge(int a, int b, bool directed = false)
{
adj[a].pb(b);
if(!directed) adj[b].pb(a);
}
};
struct LCA
{
vll tin, tout, level;
vector<vll> up;
ll timer;
void _dfs(vector<vector<int>> &adj, ll x, ll par=-1)
{
up[x][0] = par;
REP(i, 1, 20)
{
if(up[x][i-1] == -1) break;
up[x][i] = up[up[x][i-1]][i-1];
}
tin[x] = ++timer;
for(auto &p: adj[x])
{
if(p != par)
{
level[p] = level[x]+1; _dfs(adj, p, x);
}
}
tout[x] = ++timer;
}
LCA(Graph &G, ll root)
{
int n = G.adj.size();
tin.resize(n); tout.resize(n); up.resize(n, vll(20, -1)); level.resize(n, 0);
timer = 0;
//does not handle forests, easy to modify to handle
_dfs(G.adj, root);
}
ll find_kth(ll x, ll k)
{
ll cur = x;
REP(i, 0, 20)
{
if((k>>i)&1) cur = up[cur][i];
if(cur == -1) break;
}
return cur;
}
bool is_ancestor(ll x, ll y)
{
return tin[x]<=tin[y]&&tout[x]>=tout[y];
}
ll find_lca(ll x, ll y)
{
if(is_ancestor(x, y)) return x;
if(is_ancestor(y, x)) return y;
ll best = x;
REPd(i, 19, 0)
{
if(up[x][i] == -1) continue;
else if(is_ancestor(up[x][i], y)) best = up[x][i];
else x = up[x][i];
}
return best;
}
ll dist(ll a, ll b)
{
return level[a] + level[b] - 2*level[find_lca(a, b)];
}
};
long long ap_sum(long long st, long long len) {
//diff is always 1
long long en = st + len - 1;
return (len * (st + en))/2;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
for(int i=0; i<t; i++) {
long long N, L, S;
cin >> N >> L >> S;
if(S < ap_sum(1, L) || S > ap_sum(N - L + 1, L)) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
return 0;
}
/*
*/, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){cout<<"FizzBuzz"<<" ";}
else if(i%5==0){cout<<"Buzz ";}
else if(i%3==0){cout<<"Fizz ";}
else{cout<<i<<" ";}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
fizzbuzz(x);
}
static void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");}
else if(i%5==0){System.out.print("Buzz ");}
else if(i%3==0){System.out.print("Fizz ");}
else{System.out.print(i+" ");}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: def fizzbuzz(n):
for i in range (1,n+1):
if (i%3==0 and i%5==0):
print("FizzBuzz",end=' ')
elif i%3==0:
print("Fizz",end=' ')
elif i%5==0:
print("Buzz",end=' ')
else:
print(i,end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){printf("FizzBuzz ");}
else if(i%5==0){printf("Buzz ");}
else if(i%3==0){printf("Fizz ");}
else{printf("%d ",i);}
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a 2D array of integers with m rows and n columns. You need to determine if the sum of all the elements in the array is divisible by a given integer x.The first line contains 2 integers m and n the matrix's number of rows and columns.
The following N lines contain M space- separated integers denoting the matrix.
The last line contains a single integer x.
<b>Constraints</b>
1 ≤ N, M ≤ 10<sup>3</sup>
1 ≤ x ≤ 10<sup>3</sup>Output a single integer, 1 if sum is divisible by x else 0.Input:
3 3
1 2 3
4 5 6
7 8 9
3
Output:
1
Explanation :
The sum of all elements of matrix is 45 which is divisible by 3. So, we print 1, I have written this Solution Code: import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int m = input.nextInt();
int n = input.nextInt();
int[][] array = new int[m][n];
for(int i=0; i<m; i++) {
for(int j=0; j<n; j++) {
array[i][j] = input.nextInt();
}
}
int x = input.nextInt();
int sum = 0;
for(int i=0; i<m; i++) {
for(int j=0; j<n; j++) {
sum += array[i][j];
}
}
if(sum % x == 0) {
System.out.println(1);
} else {
System.out.println(0);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: int LastDigit(int N){
return N%10;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: static int LastDigit(int N){
return N%10;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: int LastDigit(int N){
return N%10;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: def LastDigit(N):
return N%10, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given first term A and the common ratio R of a GP (Geometric Progression) and an integer N, your task is to calculate its Nth term.<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>NthGP()</b> that takes the integer A, R and N as parameter.
<b>Constraints</b>
1 <= A, R <= 100
1 <= N <= 10
Return the Nth term of the given GP.
<b>Note:</b> It is guaranteed that the Nth term of this GP will always fit in 10^9.Sample Input:
3 2
5
Sample Output:-
48
Sample Input:-
2 2
10
Sample Output:
1024
<b>Explanation:-</b>
For Test Case 1:- 3 6 12 24 48 96., I have written this Solution Code:
static int NthGP(int l, int b, int h){
int ans=l;
h--;
while(h-->0){
ans*=b;
}
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram is a single boy in his village, everyone in his family are searching a bride for him and recommending for Ram but Ram wants to <b>Die Single</b>, so for prevention of his marriage he came up a plan. He says that he will marry that girl only <b>If recommending member's name is a subsequence of girl name or girl's name is a subsequence of recommending member. </b>Don't worry Ram has a Huge Family. Your task is to determine wether Ram will <b>Die Single</b> or will be married.The first line of the input contains an integer T denoting number of test cases.
In each test case there contains two space separated strings R and G.
<b>Constraint's</b>
1 ≤ T ≤ 100
1 ≤ |R|, |G| ≤ 25000 (|X| denotes the length of the string X).
All names consist of english lower case letter's only.For each test case print "#DieSingle" if Ram's family can't find a perfect match, else print "#SadLife". (quotes are meant for clarity, please don't print them).<b>Sample Input</b>
2
nirali nirali
salie galie
<b>Sample Output</b>
#SadLife
#DieSingle
<b>Explanation</b>
Case 1: Any string is a subsequence of it self, as it is formed after removing "0" characters. Hence the answer is "#SadLife".
Case 2: "salie" can not be attained from "galie" as removing any character from "salie" would make the string length smaller than "galie", also there is no 'g' in "salie". Similar reasoning can be applied to see why "galie" can't be attained from "salie". Hence the answer is "#DieSingle"., I have written this Solution Code: def Marriage (Smaller, Bigger):
j=0
k=0
while j < len(Bigger) and k < len(Smaller):
if Bigger[j]==Smaller[k]:
k+=1
j+=1
if k==len(Smaller):
return "#SadLife"
return "#DieSingle"
t = int(input())
while t>0:
t-=1
a, b= input().split()
if len(a)==len(b):
if a==b:
print("#SadLife")
else:
print("#DieSingle")
continue
else:
if len(a)<len(b):
print(Marriage(a,b))
else:
print(Marriage(b, a)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram is a single boy in his village, everyone in his family are searching a bride for him and recommending for Ram but Ram wants to <b>Die Single</b>, so for prevention of his marriage he came up a plan. He says that he will marry that girl only <b>If recommending member's name is a subsequence of girl name or girl's name is a subsequence of recommending member. </b>Don't worry Ram has a Huge Family. Your task is to determine wether Ram will <b>Die Single</b> or will be married.The first line of the input contains an integer T denoting number of test cases.
In each test case there contains two space separated strings R and G.
<b>Constraint's</b>
1 ≤ T ≤ 100
1 ≤ |R|, |G| ≤ 25000 (|X| denotes the length of the string X).
All names consist of english lower case letter's only.For each test case print "#DieSingle" if Ram's family can't find a perfect match, else print "#SadLife". (quotes are meant for clarity, please don't print them).<b>Sample Input</b>
2
nirali nirali
salie galie
<b>Sample Output</b>
#SadLife
#DieSingle
<b>Explanation</b>
Case 1: Any string is a subsequence of it self, as it is formed after removing "0" characters. Hence the answer is "#SadLife".
Case 2: "salie" can not be attained from "galie" as removing any character from "salie" would make the string length smaller than "galie", also there is no 'g' in "salie". Similar reasoning can be applied to see why "galie" can't be attained from "salie". Hence the answer is "#DieSingle"., I have written this Solution Code:
import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0)
{
String a = sc.next();
String b = sc.next();
String s1,s2;
if(a.length()<b.length())
{
s1 = a;
s2 = b;
}
else{
s1 = b;
s2 = a;
}
int i=0,j=0;
while(i<s1.length()&&j<s2.length())
{
if(s1.charAt(i)==s2.charAt(j))
{
i++;
j++;
}
else
{
j++;
}
}
if(i==s1.length())
{
System.out.println("#SadLife");
}
else
{
System.out.println("#DieSingle");
}
t--;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram is a single boy in his village, everyone in his family are searching a bride for him and recommending for Ram but Ram wants to <b>Die Single</b>, so for prevention of his marriage he came up a plan. He says that he will marry that girl only <b>If recommending member's name is a subsequence of girl name or girl's name is a subsequence of recommending member. </b>Don't worry Ram has a Huge Family. Your task is to determine wether Ram will <b>Die Single</b> or will be married.The first line of the input contains an integer T denoting number of test cases.
In each test case there contains two space separated strings R and G.
<b>Constraint's</b>
1 ≤ T ≤ 100
1 ≤ |R|, |G| ≤ 25000 (|X| denotes the length of the string X).
All names consist of english lower case letter's only.For each test case print "#DieSingle" if Ram's family can't find a perfect match, else print "#SadLife". (quotes are meant for clarity, please don't print them).<b>Sample Input</b>
2
nirali nirali
salie galie
<b>Sample Output</b>
#SadLife
#DieSingle
<b>Explanation</b>
Case 1: Any string is a subsequence of it self, as it is formed after removing "0" characters. Hence the answer is "#SadLife".
Case 2: "salie" can not be attained from "galie" as removing any character from "salie" would make the string length smaller than "galie", also there is no 'g' in "salie". Similar reasoning can be applied to see why "galie" can't be attained from "salie". Hence the answer is "#DieSingle"., 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 <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
#define int long long
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) {
uniform_int_distribution<int64_t> generator(l, r);
return generator(rng);
}
class Solution {
public:
void dieSingle(string& S, string& T) {
if (S.length() > T.length()) {
swap(S, T);
}
int n = S.length();
int m = T.length();
int j = 0;
for (int i = 0; i < m; i++) {
if (T[i] == S[j]) {
j++;
}
}
if (j == n) {
cout << "#SadLife\n";
} else {
cout << "#DieSingle\n";
}
}
};
int32_t main() {
auto start = std::chrono::high_resolution_clock::now();
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt;
cin >> tt;
while (tt--) {
string s, t;
cin >> s >> t;
if (t > s) {
swap(t, s);
}
Solution sol = Solution();
sol.dieSingle(s, t);
}
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
cerr << "Time taken : " << ((long double)duration.count()) / ((long double)1e9) << "s\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to calculate the sum of all the odd integers present in the array.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
1 < = Arr[i] < = 10000Print the sum of all the odd integers present in the array.Sample Input:-
4
1 2 3 4
Sample Output:-
4
Sample Input:-
2 4 6 8
Sample Output:-
0, I have written this Solution Code: n = int(input())
num = input().split(" ")
sums=0
for i in range(0,n):
if int(num[i])%2 != 0:
sums = sums + int(num[i])
print(sums), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to calculate the sum of all the odd integers present in the array.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
1 < = Arr[i] < = 10000Print the sum of all the odd integers present in the array.Sample Input:-
4
1 2 3 4
Sample Output:-
4
Sample Input:-
2 4 6 8
Sample Output:-
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a;
int sum=0;
for(int i=0;i<n;i++){
cin>>a;
if(a&1){sum+=a;}}
cout<<sum;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to calculate the sum of all the odd integers present in the array.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
1 < = Arr[i] < = 10000Print the sum of all the odd integers present in the array.Sample Input:-
4
1 2 3 4
Sample Output:-
4
Sample Input:-
2 4 6 8
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 a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int sum=0;
for(int i=0;i<n;i++){
if(a[i]%2==1){
sum+=a[i];
}
}
System.out.print(sum);
}
}
, In this Programming Language: Java, 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: You are given N points on a horizontal axis. Find the number of ways you can choose 3 points such that maximum distance between those points is not greater than d.The first line contains two integers: N and d. The next line contains N space-separated integers x1, x2, ..., xN, — the x-coordinates of the points that Petya has got.
<b>Constraints:</b>
1 ≤ N ≤ 1e5
1 ≤ d ≤ 1e9
1 ≤ |x[i]| ≤ 1e9
It is guaranteed that the coordinates of the points in the input strictly increase.Print the number of ways to choose 3 points.Sample Input:
4 3
1 2 3 4
Sample Output:
4
Explanation:
1 2 3
1 2 4
2 3 4
1 3 4
are the required triplets
Sample Input:
4 2
-3 -2 -1 0
Sample Output:
2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line1 = br.readLine();
String[] line1Arr = line1.split(" ");
long n = Long.parseLong(line1Arr[0]);
long d = Long.parseLong(line1Arr[1]);
long[] valueArr = new long[(int)n];
String line2 = br.readLine();
String[] line2Arr = line2.split(" ");
for(int i=0;i<n;i++){
valueArr[i] = Long.parseLong(line2Arr[i]);
}
Arrays.sort(valueArr);
System.out.println(choosePoint(valueArr,n,d));
}
static long choosePoint(long[] a, long n, long d) {
long ways = 0;
if(d==n){
return 0;
}
for (int i = 0; i < n; i++) {
long higherIndex = upperLimit(a, 0, n, a[i] + d);
long numberOfElements = higherIndex - (i + 1);
if (numberOfElements >= 2) {
ways += (numberOfElements * (numberOfElements - 1) / 2);
}
}
return ways;
}
static long upperLimit(long[] a, long low, long high, long d) {
while(low < high) {
long middle = (long)low + (high - low) / 2;
if(a[(int)middle] > d)
high = middle;
else
low = middle + 1;
}
return low;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given N points on a horizontal axis. Find the number of ways you can choose 3 points such that maximum distance between those points is not greater than d.The first line contains two integers: N and d. The next line contains N space-separated integers x1, x2, ..., xN, — the x-coordinates of the points that Petya has got.
<b>Constraints:</b>
1 ≤ N ≤ 1e5
1 ≤ d ≤ 1e9
1 ≤ |x[i]| ≤ 1e9
It is guaranteed that the coordinates of the points in the input strictly increase.Print the number of ways to choose 3 points.Sample Input:
4 3
1 2 3 4
Sample Output:
4
Explanation:
1 2 3
1 2 4
2 3 4
1 3 4
are the required triplets
Sample Input:
4 2
-3 -2 -1 0
Sample Output:
2, I have written this Solution Code: import math
N,d = map(int,input().split())
arr = [int(i) for i in input().split()]
initial = 0
pre = 0
sumi = 0
while(initial<(N-1)):
low = initial
high = N-1
while(low<=high):
mid = (low+high)>>1
if arr[mid]-arr[initial]<=d:
ans = mid
low = mid+1
else:
high = mid-1
sumi += math.comb((ans-initial)+1,3)-math.comb((pre-initial)+1,3)
pre = ans
initial += 1
print(sumi), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given N points on a horizontal axis. Find the number of ways you can choose 3 points such that maximum distance between those points is not greater than d.The first line contains two integers: N and d. The next line contains N space-separated integers x1, x2, ..., xN, — the x-coordinates of the points that Petya has got.
<b>Constraints:</b>
1 ≤ N ≤ 1e5
1 ≤ d ≤ 1e9
1 ≤ |x[i]| ≤ 1e9
It is guaranteed that the coordinates of the points in the input strictly increase.Print the number of ways to choose 3 points.Sample Input:
4 3
1 2 3 4
Sample Output:
4
Explanation:
1 2 3
1 2 4
2 3 4
1 3 4
are the required triplets
Sample Input:
4 2
-3 -2 -1 0
Sample Output:
2, I have written this Solution Code:
#include<bits/stdc++.h>
using namespace std;
// Returns the number of triplets with the
// distance between farthest points <= L
long long countTripletsLessThanL(int n, long L, long * arr)
{
// sort the array
sort(arr, arr + n);
long long ways = 0;
for (int i = 0; i < n; i++) {
// find index of element greater than arr[i] + L
int indexGreater = upper_bound(arr, arr + n,
arr[i] + L) - arr;
// find Number of elements between the ith
// index and indexGreater since the Numbers
// are sorted and the elements are distinct
// from the points btw these indices represent
// points within range (a[i] + 1 and a[i] + L)
// both inclusive
long long numberOfElements = indexGreater - (i + 1);
// if there are at least two elements in between
// i and indexGreater find the Number of ways
// to select two points out of these
if (numberOfElements >= 2) {
ways += (numberOfElements
* (numberOfElements - 1) / (long long )2);
}
}
return ways;
}
// Driver Code
int main()
{
int n;
cin>>n;
long l;
cin>>l;
long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
cout<<countTripletsLessThanL(n, l, a);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args){
FastReader read = new FastReader();
int a = read.nextInt();
int b = read.nextInt();
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(){
InputStreamReader inr = new InputStreamReader(System.in);
br = new BufferedReader(inr);
}
String next(){
while(st==null || !st.hasMoreElements())
try{
st = new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
long nextLong(){
return Long.parseLong(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split())
print(a+b)
print(a-b)
print(a*b)
print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 ≤ |<i>s</i>| ≤ 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1
abbb
Sample Output 1
2
Explanation:
The possible palindromes are:
1. abba
2. bbbb
========================================================================
Sample Input 2
abba
Sample 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 br = new BufferedReader(new InputStreamReader(System.in));
char str[] = br.readLine().toCharArray();
int ans = 0;
char arr[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
Set<String> set = new HashSet<>();
for(int i=0;i<str.length;i++){
char p = str[i];
for(char ch:arr){
if(ch==p) continue;
str[i] = ch;
if(isPallindrome(str)){
if(set.contains(String.valueOf(str))==false){
set.add(String.valueOf(str));
ans++;
}
}
str[i] = p;
}
}
System.out.println(ans);
}
static boolean isPallindrome(char[] str){
int i = 0;
int j = str.length-1;
while(i<j){
if(str[i]!=str[j]) return false;
i++;
j--;
}
return true;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 ≤ |<i>s</i>| ≤ 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1
abbb
Sample Output 1
2
Explanation:
The possible palindromes are:
1. abba
2. bbbb
========================================================================
Sample Input 2
abba
Sample Output 2
0
, I have written this Solution Code: n=input()
n=list(n)
ln=len(n)
cnt=0
for i in range(ln//2):
if not(n[i]==n[ln-i-1]):
cnt+=1
if(cnt==1):
print(2)
elif(cnt==0 and ln%2==1):
print(25)
else:
print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 ≤ |<i>s</i>| ≤ 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1
abbb
Sample Output 1
2
Explanation:
The possible palindromes are:
1. abba
2. bbbb
========================================================================
Sample Input 2
abba
Sample Output 2
0
, I have written this Solution Code: #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.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>;
#define endl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define sz(x) ((ll)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x = min(x,y)
#define maxi(x,y) x = max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(0, 1e9);
// DEBUG FUNCTIONS START
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void deb() {cerr << "\n";}
template <typename T, typename... V> void deb(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; deb(v...);}
// DEBUG FUNCTIONS END
const int N = 2e5 + 5;
void solve(){
string s;
cin >> s;
int n = sz(s);
int x = 0;
rep(i, 0, n / 2){
x += s[i] != s[n - 1 - i];
}
if(x == 1){
cout << 2 << endl;
}
else if(x > 1){
cout << 0 << endl;
}
else{
if(n & 1){
cout << 25 << endl;
}
else{
cout << 0 << endl;
}
}
}
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
cout << fixed << setprecision(15);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
int powm(int a, int b){
int res = 1;
while (b) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
, 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: The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stock’s price for all n days.
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day(including), for which the price of the stock on the current day is less than or equal to its price on the given day.
For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}.
Explanation to the given example:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6.The first line of each test case is N, N is the size of the array. The second line of each test case contains N input A[i].
1 ≤ N ≤ 100000
1 ≤ A[i] ≤ 100000For each test case, print the span values for all days.Input
7
100 80 60 70 60 75 85
Output
1 1 1 2 1 4 6
Input
6
10 4 5 90 120 80
Output
1 1 2 4 5 1
Explanation:
Test case 1:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int size = Integer.parseInt(br.readLine());
String st = br.readLine();
String[] stArr = st.trim().split(" ");
int[] arr = new int[size];
for(int i=0; i<size; i++){
arr[i] = Integer.parseInt(stArr[i]);
}
Stack<Integer> stack = new Stack<>();
StringBuilder sb=new StringBuilder("");
for(int i=0; i<size; i++){
int count = 0;
if(stack.isEmpty()){
stack.push(i);
sb.append("1 ");
} else if(arr[stack.peek()] > arr[i]){
stack.push(i);
sb.append("1 ");
} else{
while(!stack.isEmpty() && arr[stack.peek()] <= arr[i]){
stack.pop();
}
if(stack.isEmpty()){
count = i+1;
} else{
count = i - stack.peek();
}
sb.append(count+" ");
stack.push(i);
}
}
System.out.print(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stock’s price for all n days.
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day(including), for which the price of the stock on the current day is less than or equal to its price on the given day.
For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}.
Explanation to the given example:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6.The first line of each test case is N, N is the size of the array. The second line of each test case contains N input A[i].
1 ≤ N ≤ 100000
1 ≤ A[i] ≤ 100000For each test case, print the span values for all days.Input
7
100 80 60 70 60 75 85
Output
1 1 1 2 1 4 6
Input
6
10 4 5 90 120 80
Output
1 1 2 4 5 1
Explanation:
Test case 1:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6., I have written this Solution Code: n = int(input())
lst = list(map(int, input().strip().split()))
S = [0]*n
st = []
st.append(0)
for i in range(n):
while( len(st) > 0 and lst[st[-1]] <= lst[i]):
st.pop()
S[i] = i + 1 if len(st) <= 0 else (i - st[-1])
st.append(i)
for i in range(0, n):
print (S[i], end =" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stock’s price for all n days.
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day(including), for which the price of the stock on the current day is less than or equal to its price on the given day.
For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}.
Explanation to the given example:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6.The first line of each test case is N, N is the size of the array. The second line of each test case contains N input A[i].
1 ≤ N ≤ 100000
1 ≤ A[i] ≤ 100000For each test case, print the span values for all days.Input
7
100 80 60 70 60 75 85
Output
1 1 1 2 1 4 6
Input
6
10 4 5 90 120 80
Output
1 1 2 4 5 1
Explanation:
Test case 1:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int n; cin >> n;
stack<int> s;
a[0] = inf;
s.push(0);
for(int i = 1; i <= n; i++){
cin >> a[i];
while(!s.empty() && a[s.top()] <= a[i])
s.pop();
cout << i - s.top() << " ";
s.push(i);
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You take part in <b>N</b> quizzes and in the i<sup>th</sup> quiz you get a score of Q<sub>i</sub>. Your friends are very competitive with you and they ask you the strength of your quiz scores. Strength of an array is defined as the following:
The maximum growth Q<sub>j</sub> - Q<sub>i</sub> (Q<sub>j</sub> > Q<sub>i</sub>) between two quizzes i and j such that i < j and there is no quiz <b>k</b> such that <b>i < k < j</b> and <b>Q<sub>k</sub> > Q<sub>i</sub></b>.
<b>If there is no such pair of indexes, print -1. </b>
Print the strength of your quiz marks in order to impress your friends.First line contains a single integer N, the number of quizzes.
The second line contains N space seperated integers Q<sub>1</sub>, Q<sub>2</sub>,. , Q<sub>N</sub> the score in each quiz.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= Q<sub>i</sub> <= 10<sup>9</sup>Print the strength of your quiz marks.Sample Input:
6
7 10 7 2 1 8
Sample Output:
7
Explaination:
There is a growth of 7 from Q<sub>5</sub> (= 1) to Q<sub>6</sub>(= 8). There is no growth in the array greater than this., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int N=Integer.parseInt(br.readLine());
String[] str=br.readLine().split(" ");
int[] arr=new int[N];
Deque<Integer> dq=new LinkedList<Integer>();
for(int i=0;i<N;i++)
{
arr[i]=Integer.parseInt(str[i]);
}
int res;
for(int i=1;i<N;i++)
{
res=arr[i]-arr[i-1];
while(!dq.isEmpty() && dq.getLast()<res)
{
dq.removeLast();
}
dq.addLast(res);
}
System.out.print(dq.getFirst());
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You take part in <b>N</b> quizzes and in the i<sup>th</sup> quiz you get a score of Q<sub>i</sub>. Your friends are very competitive with you and they ask you the strength of your quiz scores. Strength of an array is defined as the following:
The maximum growth Q<sub>j</sub> - Q<sub>i</sub> (Q<sub>j</sub> > Q<sub>i</sub>) between two quizzes i and j such that i < j and there is no quiz <b>k</b> such that <b>i < k < j</b> and <b>Q<sub>k</sub> > Q<sub>i</sub></b>.
<b>If there is no such pair of indexes, print -1. </b>
Print the strength of your quiz marks in order to impress your friends.First line contains a single integer N, the number of quizzes.
The second line contains N space seperated integers Q<sub>1</sub>, Q<sub>2</sub>,. , Q<sub>N</sub> the score in each quiz.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= Q<sub>i</sub> <= 10<sup>9</sup>Print the strength of your quiz marks.Sample Input:
6
7 10 7 2 1 8
Sample Output:
7
Explaination:
There is a growth of 7 from Q<sub>5</sub> (= 1) to Q<sub>6</sub>(= 8). There is no growth in the array greater than this., 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;
vector<int> a(n);
for(auto &i : a) cin >> i;
int ans = -1;
stack<int> s;
for(int i = n - 1; i >= 0; i--){
while(s.size() > 0 && s.top() <= a[i]){
s.pop();
}
if(s.size()) ans = max(ans, s.top() - a[i]);
s.push(a[i]);
}
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 a sorted array A having N integer elements, find if there exists any pair of elements such that (A[i], A[j]) have the sum equal to X (i < j)The first line of input contains T, denoting the number of testcases. The first line of each test case contains N size of array and X. Second line contains elements of array separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 100000
1 <= X <= 1000
1 <= A[i] <= 1000000For each test case you need to print "Yes" if pair exists otherwise "No".Input:
2
5 4
1 2 3 4 5
5 6
2 3 5 7 8
Output:
Yes
No, I have written this Solution Code: t=int(input())
while(t>0):
n,s=[int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
i=0;j=n-1;c=0;
while i<j:
if((arr[i]+arr[j])==s):
c=1
break
if((arr[i]+arr[j])<s):
i+=1
else:
j-=1
if c==1:
print("Yes")
else:
print("No")
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array A having N integer elements, find if there exists any pair of elements such that (A[i], A[j]) have the sum equal to X (i < j)The first line of input contains T, denoting the number of testcases. The first line of each test case contains N size of array and X. Second line contains elements of array separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 100000
1 <= X <= 1000
1 <= A[i] <= 1000000For each test case you need to print "Yes" if pair exists otherwise "No".Input:
2
5 4
1 2 3 4 5
5 6
2 3 5 7 8
Output:
Yes
No, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main(String args[])throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0)
{
String s[] = read.readLine().trim().split("\\s+");
int n = Integer.parseInt(s[0]);
int k = Integer.parseInt(s[1]);
int arr[] = new int[n];
String st[] = read.readLine().trim().split("\\s+");
for(int i = 0; i < n; i++)
{
arr[i] = Integer.parseInt(st[i]);
}
System.out.println(isPair(arr, n, k)? "Yes" : "No");
}
}
static boolean isPair(int A[], int N, int X)
{
int i = 0; // represents first pointer
int j = N - 1; // represents second pointer
while (i < j) {
// If we find a pair
if (A[i] + A[j] == X)
return true;
else if (A[i] + A[j] < X)
i++;
else j--;
}
return false;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array A having N integer elements, find if there exists any pair of elements such that (A[i], A[j]) have the sum equal to X (i < j)The first line of input contains T, denoting the number of testcases. The first line of each test case contains N size of array and X. Second line contains elements of array separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 100000
1 <= X <= 1000
1 <= A[i] <= 1000000For each test case you need to print "Yes" if pair exists otherwise "No".Input:
2
5 4
1 2 3 4 5
5 6
2 3 5 7 8
Output:
Yes
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
vector<long> pos,neg;
int n;
cin>>n;
long x;
cin>>x;
long long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int i=0,j=n-1;
while(i!=j){
if((a[i]+a[j])>x){j--;}
else if((a[i]+a[j])<x){i++;}
else {cout<<"Yes"<<endl;goto f;}
}
cout<<"No"<<endl;
f:;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton has shifted to a new house and it came to his notice that there is only one socket in his house !!!
Newton does a lot of experiments using electricity and wants at least B sockets in his house.
Furthermore, he has an ample amount of extension cords and each extension has A sockets and takes one socket. In others words, an extension cord extends one socket into A sockets. You need to tell Newton how many extension cords will be required so that he can have at least B sockets.The first and the only line of the input contains 2 single integers A and B
<b>Constraints:</b>
1) 2 ≤ A ≤ 200
2) 1 ≤ B ≤ 200Print the answerSample Input 1:
4 10
Sample Output 1:
3
Sample Input 2:
8 9
Sample Output 2:
2
<b>Explanation 1:</b>
3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.
, I have written this Solution Code: ///#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<bitset>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#define pi acos(-1.0)
#define nl "\n"
/*data type ------------------------------------*/
#define ulli unsigned long long int
#define lli long long int
#define ld long double
/*---------------------------------------------*/
/*container -----------------------------------*/
#define vint vector<int>
#define vll vector<long long>
#define vlli vector<long long int>
#define vchar vector<char>
/*---------------------------------------------*/
/*container input and output-------------------*/
#define inv(v) for(auto& i:v) cin>>i
#define outv(v) for(auto& i:v) cout<<i<<" "
/*---------------------------------------------*/
/*container function --------------------------*/
#define sum(a) ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define Sort(a) ( sort((a).begin(), (a).end()))
#define Sort_d(a) ( sort(a.begin(), a.end(), greater<int>()))
/*---------------------------------------------*/
#define precision(n) fixed<<setprecision(n)
#define fast ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
/*my function ------------------------------------*/
#define max2(x,y) ((x>y)?x:y)
#define min2(x,y) ((x<y)?x:y)
#define lcm(x,y) ((x*y)/(__gcd(x,y)))
#define mod 1000000007
/*bit manipulation---------------------------------*/
#define twopower(n) (1<<n)
#define MAX INT_MAX
#define MIN INT_MIN
#define ishigh(num, position) ((num&(1<<position))>0? 1:0)
#define ll_count_high(num) (__builtin_popcountll(num))
#define int_count_high(num) (__builtin_popcount(num))
#define toupper(char) (char & '_')
//cout<<(char)toupper('a')<<nl; out:A
#define tolower(char) (char | ' ')
//cout<<(char)tolower('B')<<nl; out:b
/*-------------------------------------------------*/
/*string convert_int_to_string(int number)
{
stringstream convert;
convert<<number;
string s = convert.str();
return s;
}*/
//find big factorial using python-3
/*
#User function Template for python3
import math
class Solution:
def factorial(self, N):
x = math.factorial(N)
list = []
s = str(x)
for j in s:
list.append(int(j))
return list
#{
# Driver Code Starts
#Initial Template for Python 3
if __name__ == '__main__':
t=int(input())
for _ in range(t):
N = int(input())
ob = Solution()
ans = ob.factorial(N);
for i in ans:
print(i,end="")
print()
*/
/*vector<lli>All_perfect_square(lli range)
{
vector<lli>perfect_square;
for(lli x = 0; x*x<=range; x++)
{
perfect_square.push_back(x*x);
}
return perfect_square;
}*/
/*lli find_near_perfect_square(vector<lli>&vect, lli number)
{
//use binary search
lli ans = -1;
lli left = 0, right = vect.size()-1, mid = (left+right)/2;
while(left<=right)
{
if(vect[mid]>=number){ans = vect[mid];right = mid-1; mid = (left+right)/2;}
else {left = mid+1;mid = (left+right)/2;}
}
return ans;
}*/
//sieve algorithm
/*vector<int>all_prime;
long long int index_array[5000] = {0};
void seive(int N)
{
index_array[0] = 1;
index_array[1] = 1;
all_prime.push_back(2);
for(long long int i = 3; i<=N; i+=2)
{
if(index_array[i]==0)
{
all_prime.push_back(i);
for(long long int j = i*i; j<=N; j+=i*2)
{
index_array[j] = 1;
}
}
}
}
*/
//find x power y using bit manipulation. complexity O(log N)
/*int bitwise_pow(int a, int n)
{
int ans = 1;// Stores final answer
while (n > 0) {
bool last_bit = (n & 1);
// Check if current LSB is set
if (last_bit){ans = ans * a;}
a = a * a;
n = n >> 1;// Right shift
}
return ans;
}
*/
/*bool isPrime(int n)
{
if (n <= 1)
return false;
// Check from 2 to square root of n
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
lli N = 100000;
*/
/*vint ar;
vint ar2;
int p = 1;
int check(int n)
{
//cout<<n<<endl;
int sz = ar.size(), sz2 = ar2.size(), no = 0;
for(int i = p; i<n; i*=n)
{
cout<<"i = "<<i<<nl;
no = 0;
for(int j = 0; j<sz; j++)
{
if(ar[j]%i==0){no = 1;break;}
}
if(n%i==0&&no==0)return i;
}
return 0;
}
void solve_the_problem()
{
int n, cnt = 0, ans = 0, x;cin>>n;
string s;cin>>s;
for(int i = 1; i<=n; i++)
{
if(s[i-1]=='0')
{
x = check(i);
//cout<<x<<nl;
if(x==0)
{
ans+=i;
}
else ans+=x;
cout<<ans<<nl;
}
else ar.push_back(i);
}
cout<<ans<<nl;
ar.clear();
p = 1;
// cout<<"......"<<endl;
// outv(ar);
// cout<<nl;
}
*/
void solve_the_problem(int T)
{
int a, b, cnt = 0;
cin>>a>>b;
int soket = 1;
while(soket<b)
{
soket--;
soket+=a;
cnt++;
}
cout<<cnt<<nl;
}
int main()
{
//int t; cin>>t;
int t = 1;
for(int i = 1; i<=t; i++) solve_the_problem(t);
}
, In this Programming Language: C++, 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, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: n = int(input())
if (n%4==0 and n%100!=0 or n%400==0):
print("YES")
elif n==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, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>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 n = scanner.nextInt();
LeapYear(n);
}
static void LeapYear(int year){
if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");}
else {
System.out.println("NO");}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: str1 = input()
str2 = ''
for i in range(len(str1)):
if(i % 2 == 0):
str2 = str2 + str1[i]+" "
print(str2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String s = sc.next();
for(int i = 0;i<s.length();i++){
if(i%2==0){
System.out.print(s.charAt(i)+" ");
}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: // str is input
function oddChars(str) {
// write code here
// do not console.log
// return the output as a string
return str.split('').filter((v,idx)=> idx % 2 === 0).join(' ')
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
for(int i=0;i<s.length();i++){
if(!(i&1)){cout<<s[i]<<" ";}
}
}
, 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 elements. Find the maximum value of GCD(Arr[i], Arr[j]) where i != j.First line of input contains a single integer N.
Second line of input contains N space separated integers, denoting array Arr.
Constraints:
2 <= N <= 100000
1 <= Arr[i] <= 100000Print the maximum value of GCD(Arr[i], Arr[j]) where i != j.Sample Input 1
5
2 4 5 2 2
Sample Output 1
2
Explanation: We can select index 1 and index 4, GCD(2, 2) = 2
Sample Input 2
6
4 3 4 1 6 5
Sample Output 2
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int result(int a[],int n)
{
int maxe =0;
for(int i=0;i<n;i++)
maxe = Math.max(maxe,a[i]);
int count[]=new int[maxe+1];
for(int i=0;i<n;i++)
{
for(int j=1;j<Math.sqrt(a[i]);j++)
{
if(a[i]%j==0)
{
count[j]++;
if (j != a[i] / j)
count[a[i] / j]++;
}
}
}
for(int i=maxe;i>0;i--)
{
if(count[i]>1)
return i;
}
return 1;
}
public static void main (String[] args) throws IOException{
InputStreamReader i = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(i);
int n = Integer.parseInt(br.readLine());
int a[] = new int[n];
String str = br.readLine();
String[] strs = str.trim().split(" ");
for (int j = 0; j < n; j++)
{
a[j] = Integer.parseInt(strs[j]);
}
System.out.println(result(a,n));
}
}, 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 elements. Find the maximum value of GCD(Arr[i], Arr[j]) where i != j.First line of input contains a single integer N.
Second line of input contains N space separated integers, denoting array Arr.
Constraints:
2 <= N <= 100000
1 <= Arr[i] <= 100000Print the maximum value of GCD(Arr[i], Arr[j]) where i != j.Sample Input 1
5
2 4 5 2 2
Sample Output 1
2
Explanation: We can select index 1 and index 4, GCD(2, 2) = 2
Sample Input 2
6
4 3 4 1 6 5
Sample Output 2
4, 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 v[100001]={};
int n;
cin>>n;
for(int i=1;i<=n;++i){
int d;
cin>>d;
for(int j=1;j*j<=d;++j){
if(d%j==0){
v[j]++;
if(j!=d/j)
v[d/j]++;
}
}
}
for(int i=100000;i>=1;--i)
if(v[i]>1){
cout<<i;
return 0;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Join the user table with the post such that we get the list of all users with their posts such that the users who didn’t post anything contains NULL for the corresponding post fields. The fields in the final table should be (username, full_name, post_title).
<schema>[{'name': 'profile', 'columns': [{'name': 'username', 'type': 'varchar (24)'}, {'name': 'full_name', 'type': 'varchar (72)'}, {'name': 'headline', 'type': 'varchar (72)'}]},{'name': 'post', 'columns': [{'name': 'id', 'type': 'int'}, {'name': 'username', 'type': 'varchar(24)'}, {'name': 'post_title', 'type': 'varchar (72)'}, {'name': 'post_description', 'type': 'text'}, {'name': 'datetime_created', 'type': 'datetime'}, {'name': 'number_of_likes', 'type': 'int'}, {'name': 'photo', 'type': 'blob'}]}]</schema>nannannan, I have written this Solution Code: SELECT profile.username, full_name, post_title FROM profile LEFT JOIN post on profile.username = post.username , In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N.
The second line of input contains N integers, denoting the array height.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>
1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:-
5
5 4 1 2 1
Sample Output:-
2
<b>Explanation:</b>
We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., 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>
#define rep(i,n) for (int i=0; i<(n); i++)
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
int ans=0;
int v=0;
for(int i=1;i<n;++i){
if(a[i]>a[i-1])
v=0;
else
++v;
ans=max(ans,v);
}
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 an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N.
The second line of input contains N integers, denoting the array height.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>
1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:-
5
5 4 1 2 1
Sample Output:-
2
<b>Explanation:</b>
We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(br.readLine());
String s= br.readLine();
int[] arr= new int[num];
String[] s1 = s.split(" ");
int ccount = 0, pcount = 0;
for(int i=0;i<(num);i++)
{
arr[i]=Integer.parseInt(s1[i]);
if(i+1 < num){
arr[i+1] = Integer.parseInt(s1[i+1]);}
if(((i+1)< num) && (arr[i]>=arr[i+1]) ){
ccount++;
}else{
if(ccount > pcount){
pcount = ccount;
}
ccount = 0;
}
}
System.out.print(pcount);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N.
The second line of input contains N integers, denoting the array height.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>
1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:-
5
5 4 1 2 1
Sample Output:-
2
<b>Explanation:</b>
We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., I have written this Solution Code: N = int(input())
arr = iter(map(int,input().strip().split()))
jumps = []
jump = 0
temp = next(arr)
for i in arr:
if i<=temp:
jump += 1
temp = i
continue
temp = i
jumps.append(jump)
jump = 0
jumps.append(jump)
print(max(jumps)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠ 0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, 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();
String[] str = s.split(" ");
float a=Float.parseFloat(str[0]);
float b=Float.parseFloat(str[1]);
float c=Float.parseFloat(str[2]);
float div = (float)(b*b-4*a*c);
if(div>0.0){
float alpha= (-b+(float)Math.sqrt(div))/(2*a);
float beta= (-b-(float)Math.sqrt(div))/(2*a);
System.out.printf("%.2f\n",alpha);
System.out.printf("%.2f",beta);
}
else{
float rp=-b/(2*a);
float ip=(float)Math.sqrt(-div)/(2*a);
System.out.printf("%.2f+i%.2f\n",rp,ip);
System.out.printf("%.2f-i%.2f\n",rp,ip);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠ 0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, I have written this Solution Code: import math
a,b,c = map(int, input().split(' '))
disc = (b ** 2) - (4*a*c)
sq = disc ** 0.5
if disc > 0:
print("{:.2f}".format((-b + sq)/(2*a)))
print("{:.2f}".format((-b - sq)/(2*a)))
elif disc == 0:
print("{:.2f}".format(-b/(2*a)))
elif disc < 0:
r1 = complex((-b + sq)/(2*a))
r2 = complex((-b - sq)/(2*a))
print("{:.2f}+i{:.2f}".format(r1.real, abs(r1.imag)))
print("{:.2f}-i{:.2f}".format(r2.real, abs(r2.imag))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠ 0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-19 02:44:22
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int main() {
float a, b, c;
float root1, root2, imaginary;
float discriminant;
scanf("%f%f%f", &a, &b, &c);
discriminant = (b * b) - (4 * a * c);
switch (discriminant > 0) {
case 1:
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("%.2f\n%.2f", root1, root2);
break;
case 0:
switch (discriminant < 0) {
case 1:
root1 = root2 = -b / (2 * a);
imaginary = sqrt(-discriminant) / (2 * a);
printf("%.2f + i%.2f\n%.2f - i%.2f", root1, imaginary, root2, imaginary);
break;
case 0:
root1 = root2 = -b / (2 * a);
printf("%.2f\n%.2f", root1, root2);
break;
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: a, b, v = map(int, input().strip().split(" "))
c = abs(a-b)
t = c//v
print(t), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
System.out.print(Time(n,m,k));
}
static int Time(int A, int B, int S){
if(B>A){
return (B-A)/S;
}
return (A-B)/S;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number X (X>=0) is called strange if the sum of its digits is divisible by 9. Given an integer N, your task is to find the Nth strange number.The input contains a single line containing the value of N.
Constraints:-
1 <= N <= 1000Print the Nth strange number.Sample Input:-
3
Sample Output:-
18
Explanation:-
0, 9, and 18 are the first three strange numbers.
Sample Input:-
2
Sample Output:-
9, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int ans = 9 * (x-1);
System.out.print(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number X (X>=0) is called strange if the sum of its digits is divisible by 9. Given an integer N, your task is to find the Nth strange number.The input contains a single line containing the value of N.
Constraints:-
1 <= N <= 1000Print the Nth strange number.Sample Input:-
3
Sample Output:-
18
Explanation:-
0, 9, and 18 are the first three strange numbers.
Sample Input:-
2
Sample Output:-
9, 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 1000001
#define MOD 1000000000000007
#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);
}
int cnt[max1];
signed main(){
int n;
cin>>n;
out((n-1)*9);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number X (X>=0) is called strange if the sum of its digits is divisible by 9. Given an integer N, your task is to find the Nth strange number.The input contains a single line containing the value of N.
Constraints:-
1 <= N <= 1000Print the Nth strange number.Sample Input:-
3
Sample Output:-
18
Explanation:-
0, 9, and 18 are the first three strange numbers.
Sample Input:-
2
Sample Output:-
9, I have written this Solution Code: a=int(input())
print(9*(a-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a Java program to perform following operations:
1. Input an arraylist of size n
2. Sort the arraylist
3. Search for value 2 in arraylist , if present print out its index else print out -1.First line of input contains value of n.
second line of input contains n space-separated integers.
Constraints:-
1 < = N < = 1000
1 < = Arr[i] < = 100000 Print index of 2 if present else print out -1.Sample Input:-
6
1 2 3 4 5 6
Sample output:-
1
Explanation:
2 is present at index value 1 in the sorted arraylist., I have written this Solution Code: import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
list.add(sc.nextInt());
}
Collections.sort(list);
int index = Collections.binarySearch(list, 2);
if (index >= 0) {
System.out.println(index);
} else {
System.out.println("-1");
}
sc.close();
}
}, 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: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array.
The second line of each test case contains N space separated integers denoting array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^6
<b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input:
3
10
2 3 4 5 6 7 8 9 10 1
5
3 4 5 1 2
8
10 20 30 45 50 60 4 6
Output:
1
1
4
Explanation:
Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1.
Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1.
Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: def findMin(arr, low, high):
if high < low:
return arr[0]
if high == low:
return arr[low]
mid = int((low + high)/2)
if mid < high and arr[mid+1] < arr[mid]:
return arr[mid+1]
if mid > low and arr[mid] < arr[mid - 1]:
return arr[mid]
if arr[high] > arr[mid]:
return findMin(arr, low, mid-1)
return findMin(arr, mid+1, high)
T =int(input())
for i in range(T):
N = int(input())
arr = list(input().split())
for k in range(len(arr)):
arr[k] = int(arr[k])
print(findMin(arr,0,N-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array.
The second line of each test case contains N space separated integers denoting array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^6
<b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input:
3
10
2 3 4 5 6 7 8 9 10 1
5
3 4 5 1 2
8
10 20 30 45 50 60 4 6
Output:
1
1
4
Explanation:
Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1.
Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1.
Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
int l = 0, h = n+1;
if(a[1] < a[n]){
cout << a[1] << endl;
continue;
}
while(l+1 < h){
int m = (l + h) >> 1;
if(a[m] >= a[1])
l = m;
else
h = m;
}
cout << a[h] << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array.
The second line of each test case contains N space separated integers denoting array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^6
<b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input:
3
10
2 3 4 5 6 7 8 9 10 1
5
3 4 5 1 2
8
10 20 30 45 50 60 4 6
Output:
1
1
4
Explanation:
Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1.
Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1.
Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
public static void main (String[] args) {
//code
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for(int j=0;j<t;j++){
int al = s.nextInt();
int a[] = new int[al];
for(int i=0;i<al;i++){
a[i] = s.nextInt();
}
binSearchSmallest(a);
}
}
public static void binSearchSmallest(int a[]) {
int s=0;
int e = a.length - 1;
int mid = 0;
while(s<=e){
mid = (s+e)/2;
if(a[s]<a[e]){
System.out.println(a[s]);
return;
}
if(a[mid]>=a[s]){
s=mid+1;
}
else{
e=mid;
}
if(s == e){
System.out.println(a[s]);
return;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the <b>minimum</b> element in it.The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array.
The second line of each test case contains N space separated integers denoting array elements.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^6
<b>Sum of "N" over all testcases does not exceed 10^5</b>Corresponding to each test case, in a new line, print the minimum element in the array.Input:
3
10
2 3 4 5 6 7 8 9 10 1
5
3 4 5 1 2
8
10 20 30 45 50 60 4 6
Output:
1
1
4
Explanation:
Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1.
Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1.
Testcase 3: The array is rotated and the minimum element present is 4., I have written this Solution Code: // arr is the input array
function findMin(arr,n) {
// write code here
// do not console.log
// return the number
let min = arr[0]
for(let i=1;i<arr.length;i++){
if(min > arr[i]){
min = arr[i]
}
}
return min
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the marks of N students, your task is to calculate the average of the marks obtained.First line of input contains a single integer N. The next line contains N space separated integers containing the marks of the students.
Constraints:-
1 <= N <= 1000
1 <= marks <= 1000Print the floor of the average of marks obtained.Sample Input:-
4
1 2 3 4
Sample Output:-
2
Sample Input:-
3
5 5 5
Sample Output:-
5, I have written this Solution Code: n=int(input())
a=list(map(int,input().split()))
print(sum(a)//n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the marks of N students, your task is to calculate the average of the marks obtained.First line of input contains a single integer N. The next line contains N space separated integers containing the marks of the students.
Constraints:-
1 <= N <= 1000
1 <= marks <= 1000Print the floor of the average of marks obtained.Sample Input:-
4
1 2 3 4
Sample Output:-
2
Sample Input:-
3
5 5 5
Sample Output:-
5, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.*;
class Main {
public static void main (String[] args)throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
System.out.print(Average_Marks(a,n));
}
static int Average_Marks(int marks[],int N){
int sum=0;
for(int i=0;i<N;i++){
sum+=marks[i];
}
return sum/N;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a series and a number N, your task is to print the Nth number of the given series.
Series:- 24, 37, 50, 63, 76,. .. .<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>NthNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the Nth number.Sample Input:-
1
Sample Output:-
24
Sample Input:-
3
Sample Output:-
50, I have written this Solution Code: int NthNumber(int N){
return 24+(N-1)*13;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a series and a number N, your task is to print the Nth number of the given series.
Series:- 24, 37, 50, 63, 76,. .. .<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>NthNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the Nth number.Sample Input:-
1
Sample Output:-
24
Sample Input:-
3
Sample Output:-
50, I have written this Solution Code: int NthNumber(int N){
return 24+(N-1)*13;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a series and a number N, your task is to print the Nth number of the given series.
Series:- 24, 37, 50, 63, 76,. .. .<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>NthNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the Nth number.Sample Input:-
1
Sample Output:-
24
Sample Input:-
3
Sample Output:-
50, I have written this Solution Code: def NthNumber(N):
return 24+(N-1)*13
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a series and a number N, your task is to print the Nth number of the given series.
Series:- 24, 37, 50, 63, 76,. .. .<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>NthNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the Nth number.Sample Input:-
1
Sample Output:-
24
Sample Input:-
3
Sample Output:-
50, I have written this Solution Code: static int NthNumber(int N){
return 24+(N-1)*13;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A string is called AB string if it's of length at least 2 and all it's characters are A except the last character which is B.
You have an empty string s, you can do the following operation any number of times.
Choose any position of s and insert any AB string in that position.
You are given a string t of some length containing only A and B. Find out if it is possible to convert s to t after some operations.First line contains N denoting the length of t.
Next line contains t.
<b>Constraints</b>
1 <= N <= 10<sup>5</sup>
t contains only A and B.Output "YES" or "NO".Input:
5
AAABB
Output:
YES
Explanation :
"" => "AAB" => "AA "AB" B" => "AAABB"
Input:
3
ABB
Output:
NO
, I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
int n=Integer.parseInt(in.next());
String s=in.next();
int cnt=0;
int f=0;
for(int i=n-1;i>=0;i--){
if(s.charAt(i) == 'A'){
if(cnt == 0){
if(f == 0){
f=-1;
break;
}
}
else cnt--;
}
else{
cnt++;
f=1;
}
}
if(f == -1 || cnt != 0){
out.print("NO");
}
else out.print("YES");
out.close();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void println(int i) {
writer.println(i);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "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 an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: function simpleArrangement(n, arr) {
// write code here
// do not console.log
// return the output as an array
const newArr = []
// for (let i = 0; i < n; i++) {
// arr[i] += (arr[arr[i]] % n) * n;
// }
// Second Step: Divide all values by n
for (let i = 0; i < n; i++) {
newArr.push(arr[arr[i]])
}
return newArr
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: n = int(input())
a = input().split()
print(" ".join(a[int(x)] for x in a)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String s = br.readLine();
String[] str = s.split(" ");
int arr[] = new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(str[i]);
}
for(int i =0;i<n;i++){
System.out.print(arr[arr[i]]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
long long n,k;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cout<<a[a[i]]<<" ";
}
}
, In this Programming Language: C++, 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.