Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given one element K your task is to print the maximum element from the array which is less than or equal to the given element(Floor), and the minimum element from the array which is greater than or equal to the given element(Ceil).<b>In case of Java only</b>
<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>floorAndCeil()</b> that takes the array a[], integer N and integer k as arguments.
<b>Custom Input</b>
The first line of input contains a single integer N. The Second line of input contains N space-separated integers depicting the values of the array. The third line of input contains a single integer Q. The next Q line of input contains a single integer the value of K.
Constraints:-
1 <= N <= 100000
1 <= K, Arr[i] <= 1000000000000
1 <= Q <= 10000In a new line Print two space-separated integers depicting the values of Floor and Ceil of the given number. If the floor or ceil of the element does not exist print -1.Sample Input:-
5
2 5 6 11 15
5
2
4
8
1
16
Sample Output:-
2 2
2 5
6 11
-1 2
15 -1, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int n;
cin>>n;
vector<int> v;
int x;
FOR(i,n){
cin>>x;
v.EB(x);}
int q;
cin>>q;
while(q--){
cin>>x;
auto it = lower_bound(v.begin(),v.end(),x);
if(it==v.begin()){
if(*it==x){
cout<<x<<" "<<x;
}
else{
cout<<-1<<" "<<*it;
}
}
else if (it==v.end()){
it--;
cout<<*it<<" -1";
}
else{
if(*it==x){
cout<<x<<" "<<x;
}
else{
it--;
cout<<*it<<" ";
it++;
cout<<*it;}
}
END;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: function easySorting(arr)
{
for(let i = 1; i < 5; i++)
{
let str = arr[i];
let j = i-1;
while(j >= 0 && (arr[j].toString().localeCompare(str)) > 0 )
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = str;
}
return arr;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
map<string,int> m;
string s;
for(int i=0;i<5;i++){
cin>>s;
m[s]++;
}
for(auto it=m.begin();it!=m.end();it++){
while(it->second>0){
cout<<it->first<<" ";
it->second--;}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: inp = input("").split(" ")
print(" ".join(sorted(inp))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static void printArray(String str[])
{
for (String string : str)
System.out.print(string + " ");
}
public static void main (String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
int len = 5;
String[] str = new String[len];
str = br.readLine().split(" ");
Arrays.sort(str, String.CASE_INSENSITIVE_ORDER);
printArray(str);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Create a class Teacher with name, age, and salary attributes, where salary must be a private attribute that cannot be accessed outside the class.
Print the details of the teacher including salary.The first line contains the name, the second line contains the age and the third line contains the salary of the teacher.
<b>Constraints:</b>
20<=age<=80Prints the details of the teacher in the following format:
Name:
Age:
Salary:Sample Input:
raj
22
20000
Sample Output:
Name: raj
Age: 22
Salary: 20000, I have written this Solution Code: class Teacher():
def __init__(self, name, age, salary):
self.name = name
self.age = age
# private variable
self.__salary = salary
def show_details(self):
print("Name:", self.name)
print("Age:", self.age)
#access private attribute inside the class
print("Salary:", self.__salary)
name=input()
age=int(input())
salary=int(input())
teacher = Teacher(name,age,salary)
teacher.show_details(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Create a class Teacher with name, age, and salary attributes, where salary must be a private attribute that cannot be accessed outside the class.
Print the details of the teacher including salary.The first line contains the name, the second line contains the age and the third line contains the salary of the teacher.
<b>Constraints:</b>
20<=age<=80Prints the details of the teacher in the following format:
Name:
Age:
Salary:Sample Input:
raj
22
20000
Sample Output:
Name: raj
Age: 22
Salary: 20000, I have written this Solution Code: import java.io.*;
import java.util.*;
class Teacher{
String name;
int age;
private int salary;
Teacher(String name , int age , int salary){
this.name = name;
this.age = age;
this.salary = salary;
}
public void details(){
System.out.println("Name: "+this.name);
System.out.println("Age: "+ this.age);
System.out.print("Salary: "+this.salary);
}
}
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
int age = sc.nextInt();
int salary = sc.nextInt();
Teacher obj = new Teacher (name , age , salary);
obj.details();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You will be given a <code>list of employees</code> with their information in a <code>JSON format as an argument</code>. Your task is to implement a JavaScript function, <code>performEmployeeOperations</code>, that performs the following tasks:
<ol>
<li>Find the <code>employee with the highest salary</code> and store it in the <code>highestSalaryEmployee</code>. Note, the <code>highestSalaryEmployee</code> logic has already been provided in the boilerplate. For the rest of the operations, you might have to look into array loop methods, like reduce, filter, map, etc.</li>
<li>The <code>employeesByDepartment</code> returns an <code>object</code> of employees grouped by department. The <code>department should be the key</code> and an <code>array of employees with their information as value</code>.</li>
<li>The <code>averageAgeByDepartment</code> returns an <code>object</code>, with the <code>department as key</code> and the <code>average age of that department as value</code>.</li>
<li><code>employeesWithLongestName</code> returns an <code>array</code> with the <code>employee(s) information having the longest name(s)</code>.</li>
</ol>
<code>Note:</code>
**Remove the extra spaces from the list while inserting the list of employees in the input section.**The <code>performEmployeeOperations</code> function will take in an <code>array of objects in JSON format</code>. Each Object will have a <code>name</code>, <code>age</code>, <code>department</code>, and <code>salary</code> property.The <code>performEmployeeOperations</code> function should return an <code>object</code> of <code>highestSalaryEmployee</code>, <code>employeesByDepartment</code>, <code>averageAgeByDepartment</code>, <code>employeesWithLongestName</code>.
<code>highestSalaryEmployee</code> should store the <code>object of the employee having the highest salary</code>.
<code>employeesByDepartment</code> should return an <code>object</code>.
<code>averageAgeByDepartment</code> should return an <code>object</code>.
<code>employeesWithLongestName</code> should return an <code>array of object</code>.const employees = [{"name":"John","age":30,"department":"HR","salary":50000},{"name":"Jane","age":28,"department":"IT","salary":60000},{"name":"Mark","age":35,"department":"HR","salary":55000},{"name":"Alice","age":32,"department":"Finance","salary":65000},{"name":"Charlie","age":40,"department":"IT","salary":70000}]
const operations = performEmployeeOperations(employees);
console.log(operations.highestSalaryEmployee); // Output: { name: 'Charlie', age: 40, department: 'IT', salary: 70000 }
console.log(operations.employeesByDepartment);
// Output:
{
HR: [
{ name: 'John', age: 30, department: 'HR', salary: 50000 },
{ name: 'Mark', age: 35, department: 'HR', salary: 55000 }
],
IT: [
{ name: 'Jane', age: 28, department: 'IT', salary: 60000 },
{ name: 'Charlie', age: 40, department: 'IT', salary: 70000 }
],
Finance: [ { name: 'Alice', age: 32, department: 'Finance', salary: 65000 } ]
}
console.log(operations.averageAgeByDepartment); //Output: { HR: 32.5, IT: 34, Finance: 32 }
console.log(operations.employeesWithLongestName); //Output: [ { name: 'Charlie', age: 40, department: 'IT', salary: 70000 } ], I have written this Solution Code: function performEmployeeOperations(employees) {
const highestSalaryEmployee = employees.reduce((acc, emp) => emp.salary > acc.salary ? emp : acc, employees[0]);
const employeesByDepartment = employees.reduce((acc, emp) => {
if (!acc[emp.department]) {
acc[emp.department] = [];
}
acc[emp.department].push(emp);
return acc;
}, {});
const averageAgeByDepartment = Object.keys(employeesByDepartment).reduce((acc, department) => {
const employeesInDepartment = employeesByDepartment[department];
const totalAge = employeesInDepartment.reduce((sum, emp) => sum + emp.age, 0);
const averageAge = totalAge / employeesInDepartment.length;
acc[department] = averageAge;
return acc;
}, {});
const longestNameLength = Math.max(...employees.map(emp => emp.name.length));
const employeesWithLongestName = employees.filter(emp => emp.name.length === longestNameLength);
return {
highestSalaryEmployee,
employeesByDepartment,
averageAgeByDepartment,
employeesWithLongestName
};
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
def checkSpecial_M_Visor(N,M) :
# Final result of summation of divisors
i=2;
count=0
while i<=N :
if(N%i==0):
count=count+1
i=i+2
if(count == M):
return "Yes"
return "No"
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
static String checkSpecial_M_Visor(int N, int M)
{
int temp=0;
for(int i = 2; i <=N; i+=2)
{
if(N%i==0)
temp++;
}
if(temp==M)
return "Yes";
else return "No";
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
string checkSpecial_M_Visor(int N,int M){
int count=0;
for(int i=2;i<=N;i+=2){
if(N%i==0){
count++;
}
}
if(count==M){return "Yes";}
return "No";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code: const char* checkSpecial_M_Visor(int N,int M){
int count=0;
for(int i=2;i<=N;i+=2){
if(N%i==0){
count++;
}
}
char* ans;
if(count==M){return "Yes";}
return "No";
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: given a tuple of 6 elements, find a tuple which contains k smallest and k largest elements of the given tuple.
i.e., for example if k=2, the resulting tuple would have 2 smallest and 2 largest numbers from the original tuple.
the resulting tuple should be sorted.
k would be given as the first input, then the user would enter the six elements of the tupleEnter a integer in each line.
2 - k value (it can be 1,2 or 3)
3
4
5
2
6
7
2 is the value of k
So we need 2 smallest and 2 largest elements of the tuple
And the resulting tuple would be sorted 4 elements.
Input:
2 -->(2 is the value of k)
3
4
5
2
6
7
Output:
(2, 3, 6, 7), I have written this Solution Code: k= int(input())
b= int(input())
c= int(input())
d= int(input())
e= int(input())
f= int(input())
g= int(input())
test_tup = (b,c,d,e,f,g)
test_tup = list(test_tup)
temp = sorted(test_tup)
res = tuple(temp[:k] + temp[-k:])
print(str(res))
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: static void Icecreams (int N, int D){
int x=N;
while(D-->0){
x-=x/2;
x*=3;
}
System.out.println(x);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){
int x=N;
while(D--){
x-=x/2;
x*=3;
}
cout << x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){
int x=N;
while(D--){
x-=x/2;
x*=3;
}
printf("%d", x);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: def Icecreams(N,D):
ans = N
while D > 0:
ans = ans - ans//2
ans = ans*3
D = D-1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N.
N lines follow each containing N space-separated integers.
<b>Constraints</b>
2 <= N <= 100
1 <= Mat[i][j] <= 10000Output 2*N+1 lines.
First N lines should contain the Matrix rotated by 90 degrees.
Then print a blank line.
Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1:
2
3 4
7 6
Sample Output 1:
7 3
6 4
6 7
4 3
Sample Input 2:
2
1 2
3 4
Sample Output 2:
3 1
4 2
4 3
2 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
// Function to rotate the matrix 90 degree clockwise
void rotate90Clockwise(int a[][N],int n)
{
// Traverse each cycle
for (int i = 0; i < n / 2; i++) {
for (int j = i; j < n - i - 1; j++) {
// Swap elements of each cycle
// in clockwise direction
int temp = a[i][j];
a[i][j] = a[n - 1 - j][i];
a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j];
a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i];
a[j][n - 1 - i] = temp;
}
}
}
// Function for print matrix
void printMatrix(int arr[][N],int n)
{
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cout << arr[i][j] << " ";
cout << '\n';
}
}
// Driver code
int main()
{
int n;
cin>>n;
int arr[n][N];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}}
rotate90Clockwise(arr,n);
printMatrix(arr,n);
cout<<endl;
rotate90Clockwise(arr,n);
printMatrix(arr,n);
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N.
N lines follow each containing N space-separated integers.
<b>Constraints</b>
2 <= N <= 100
1 <= Mat[i][j] <= 10000Output 2*N+1 lines.
First N lines should contain the Matrix rotated by 90 degrees.
Then print a blank line.
Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1:
2
3 4
7 6
Sample Output 1:
7 3
6 4
6 7
4 3
Sample Input 2:
2
1 2
3 4
Sample Output 2:
3 1
4 2
4 3
2 1, 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][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
a[i][j]= sc.nextInt();
}
}
//rotating by 90 degree
for (int i = 0; i < n / 2; i++) {
for (int j = i; j < n - i - 1; j++) {
int temp = a[i][j];
a[i][j] = a[n - 1 - j][i];
a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j];
a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i];
a[j][n - 1 - i] = temp;
}
}
for(int i =0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
//rotating by 90 degree
for (int i = 0; i < n / 2; i++) {
for (int j = i; j < n - i - 1; j++) {
int temp = a[i][j];
a[i][j] = a[n - 1 - j][i];
a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j];
a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i];
a[j][n - 1 - i] = temp;
}
}
System.out.println();
for(int i =0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N.
N lines follow each containing N space-separated integers.
<b>Constraints</b>
2 <= N <= 100
1 <= Mat[i][j] <= 10000Output 2*N+1 lines.
First N lines should contain the Matrix rotated by 90 degrees.
Then print a blank line.
Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1:
2
3 4
7 6
Sample Output 1:
7 3
6 4
6 7
4 3
Sample Input 2:
2
1 2
3 4
Sample Output 2:
3 1
4 2
4 3
2 1, I have written this Solution Code: x=int(input())
l1=[]
for i in range(x):
a1=list(map(int,input().split()))
l1.append(a1)
for j in range(x):
for i in range(1,x+1):
print(l1[-i][j], end=" ")
print()
print()
for i in range(1,x+1):
for j in range(1,x+1):
print(l1[-i][-j], end=" ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b>
There will be two functions:
<ul>
<li>verticalFive(): Print stars in vertical order</li>
<li>horizontalFive(): Print stars in horizontal order</l>
</ul><b>User Task:</b>
Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>.
Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function.
<b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input:
Sample Output:
*
*
*
*
*
* * * * *, I have written this Solution Code: static void verticalFive(){
System.out.println("*");
System.out.println("*");
System.out.println("*");
System.out.println("*");
System.out.println("*");
}
static void horizontalFive(){
System.out.print("* * * * *");
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b>
There will be two functions:
<ul>
<li>verticalFive(): Print stars in vertical order</li>
<li>horizontalFive(): Print stars in horizontal order</l>
</ul><b>User Task:</b>
Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>.
Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function.
<b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input:
Sample Output:
*
*
*
*
*
* * * * *, I have written this Solution Code: def vertical5():
for i in range(0,5):
print("*",end="\n")
#print()
def horizontal5():
for i in range(0,5):
print("*",end=" ")
vertical5()
print(end="\n")
horizontal5(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array A of size N and value K. The elements of the array A contains positive integers. You have to print all the elements which are greater than K in the array in sorted order (including K as well if present in the array A), and print all the elements which are smaller than K in sorted order both of them in separate lines. If the elements greater than or equal to K are not present in the array then print "-1". Similarly, in the case of smaller elements print -1 if elements smaller than K doesn’t exist. If a number appears more than once print number more than once.First line of input contains number of testcases T. For each testcase, there are two lines, first of which contains N and K separated by space, next line contains N space separated integers.
Constraints:
1 <= T <= 100
1 <= N <= 100000
1 <= K <= 1000000
1 <= A[i] <= 1000000
Sum of N over all test cases do not exceed 100000For each testcase, print the required elements(if any), else print "-1" (without quotes)Input:
1
5 1
2 1 5 7 6
Output:
1 2 5 6 7
-1
Explanation:
Testcase 1 : Since, 1, 2, 5, 6, 7 are greater or equal to given K. Also, no element less than K is present in the array., I have written this Solution Code: import java.io.*;
import java.util.*;
class Reader{
BufferedReader reader;
Reader(){
this.reader = new BufferedReader(new InputStreamReader(System.in));
}
public String read() throws IOException {
return reader.readLine();
}
public int readInt() throws IOException {
return Integer.parseInt(reader.readLine());
}
public long readLong() throws IOException {
return Long.parseLong(reader.readLine());
}
public String[] readArray() throws IOException {
return reader.readLine().split(" ");
}
public int[] readIntegerArray() throws IOException {
String[] str = reader.readLine().split(" ");
int[] arr = new int[str.length];
for(int i=0;i<str.length;i++) arr[i] = Integer.parseInt(str[i]);
return arr;
}
public long[] readLongArray() throws IOException {
String[] str = reader.readLine().split(" ");
long[] arr = new long[str.length];
for(int i=0;i<str.length;i++) arr[i] = Long.parseLong(str[i]);
return arr;
}
}
public class Main {
public static void main(String[] args) throws IOException {
Reader rdr = new Reader();
int t = rdr.readInt();
while(t-- > 0){
int[] str = rdr.readIntegerArray();
int n = str[0];
int k = str[1];
int[] arr = rdr.readIntegerArray();
Arrays.sort(arr);
int c=0;
for(int i=0;i<n;i++){
if(arr[i]>=k){
System.out.print(arr[i]+" ");
c++;
}
}
if(c==0) System.out.print(-1);
System.out.println();
if(c==n) System.out.print(-1);
else for(int i=0;i<n-c;i++) System.out.print(arr[i]+" ");
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array A of size N and value K. The elements of the array A contains positive integers. You have to print all the elements which are greater than K in the array in sorted order (including K as well if present in the array A), and print all the elements which are smaller than K in sorted order both of them in separate lines. If the elements greater than or equal to K are not present in the array then print "-1". Similarly, in the case of smaller elements print -1 if elements smaller than K doesn’t exist. If a number appears more than once print number more than once.First line of input contains number of testcases T. For each testcase, there are two lines, first of which contains N and K separated by space, next line contains N space separated integers.
Constraints:
1 <= T <= 100
1 <= N <= 100000
1 <= K <= 1000000
1 <= A[i] <= 1000000
Sum of N over all test cases do not exceed 100000For each testcase, print the required elements(if any), else print "-1" (without quotes)Input:
1
5 1
2 1 5 7 6
Output:
1 2 5 6 7
-1
Explanation:
Testcase 1 : Since, 1, 2, 5, 6, 7 are greater or equal to given K. Also, no element less than K is present in the array., I have written this Solution Code: t=int(input())
while t>0:
a=input().split()
b=input().split()
for i in range(len(b)):
b[i]=int(b[i])
lesser=[]
greater=[]
for i in b:
if i>=int(a[1]):
greater.append(i)
else:
lesser.append(i)
if len(greater)==0:
print(-1,end="")
else:
greater.sort()
for x in greater:
print(x,end=" ")
print()
if len(lesser)==0:
print(-1,end="")
else:
lesser.sort()
for y in lesser:
print(y,end=" ")
print()
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array A of size N and value K. The elements of the array A contains positive integers. You have to print all the elements which are greater than K in the array in sorted order (including K as well if present in the array A), and print all the elements which are smaller than K in sorted order both of them in separate lines. If the elements greater than or equal to K are not present in the array then print "-1". Similarly, in the case of smaller elements print -1 if elements smaller than K doesn’t exist. If a number appears more than once print number more than once.First line of input contains number of testcases T. For each testcase, there are two lines, first of which contains N and K separated by space, next line contains N space separated integers.
Constraints:
1 <= T <= 100
1 <= N <= 100000
1 <= K <= 1000000
1 <= A[i] <= 1000000
Sum of N over all test cases do not exceed 100000For each testcase, print the required elements(if any), else print "-1" (without quotes)Input:
1
5 1
2 1 5 7 6
Output:
1 2 5 6 7
-1
Explanation:
Testcase 1 : Since, 1, 2, 5, 6, 7 are greater or equal to given K. Also, no element less than K is present in the array., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
signed main()
{
int t;
cin>>t;
while(t>0)
{
t--;
int n,k;
cin>>n>>k;
vector<int> A,B;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
if(a<k) B.pu(a);
else A.pu(a);
}
sort(all(A));
sort(all(B));
for(auto it:A)
{
cout<<it<<" ";
}if(A.size()==0) cout<<-1;
cout<<endl;
for(auto it:B)
{
cout<<it<<" ";
}if(B.size()==0) cout<<-1;
cout<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd.
Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow.
<b>Constraints:</b>
1 <= N <=10<sup>5</sup>
1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input :
5
1 1 2 2 3
Output:
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));
int noofterm=Integer.parseInt(br.readLine());
int arr[] = new int[noofterm];
String s[] = br.readLine().split(" ");
for(int i=0; i<noofterm;i++){
arr[i]= Integer.parseInt(s[i]);
}
System.out.println(unique(arr));
}
public static int unique(int[] inputArray)
{
int result = 0;
for(int i=0;i<inputArray.length;i++)
{
result ^= inputArray[i];
}
return (result>0 ? result : -1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd.
Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow.
<b>Constraints:</b>
1 <= N <=10<sup>5</sup>
1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input :
5
1 1 2 2 3
Output:
3, I have written this Solution Code: n = int(input())
a = [int (x) for x in input().split()]
mapp={}
for index,val in enumerate(a):
if val in mapp:
del mapp[val]
else:
mapp[val]=1
for key, value in mapp.items():
print(key), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd.
Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow.
<b>Constraints:</b>
1 <= N <=10<sup>5</sup>
1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input :
5
1 1 2 2 3
Output:
3, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
signed main()
{
int n;
cin>>n;
int p=0;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
p^=a;
}
cout<<p<<endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Remove duplicates of an array and return an array of only unique elements.An array containing numbers.Space separated unique elements from the array.Sample Input:-
1 2 3 5 1 5 9 1 2 8
Sample Output:-
1 2 3 5 9 8
<b>Explanation:-</b>
Extra 1, 2, and 5 were removed since they were occurring multiple times.
Note: You only have to remove the extra occurrences i.e. each element in the final array should have a frequency equal to one., I have written this Solution Code: nan, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Remove duplicates of an array and return an array of only unique elements.An array containing numbers.Space separated unique elements from the array.Sample Input:-
1 2 3 5 1 5 9 1 2 8
Sample Output:-
1 2 3 5 9 8
<b>Explanation:-</b>
Extra 1, 2, and 5 were removed since they were occurring multiple times.
Note: You only have to remove the extra occurrences i.e. each element in the final array should have a frequency equal to one., I have written this Solution Code:
inp = eval(input(""))
new_set = []
for i in inp:
if(str(i) not in new_set):
new_set.append(str(i))
print(" ".join(new_set)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments.
Constraints:-
0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:-
4 2 0
Sample Output:-
12
Sample Input:-
1 1 1
Sample Output:-
1, I have written this Solution Code: int Marks(int P, int Q, int R){
return 4*P - 2*Q - R;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments.
Constraints:-
0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:-
4 2 0
Sample Output:-
12
Sample Input:-
1 1 1
Sample Output:-
1, I have written this Solution Code: int Marks(int P, int Q, int R){
return 4*P - 2*Q - R;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments.
Constraints:-
0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:-
4 2 0
Sample Output:-
12
Sample Input:-
1 1 1
Sample Output:-
1, I have written this Solution Code: def Marks(P,Q,R):
return 4*P-2*Q-R
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments.
Constraints:-
0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:-
4 2 0
Sample Output:-
12
Sample Input:-
1 1 1
Sample Output:-
1, I have written this Solution Code: static int Marks(int P, int Q, int R){
return 4*P - 2*Q - R;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a Deque and Q queries. The task is to perform some operation on Deque according to the queries as described in input:
Note:-if deque is empty than pop operation will do nothing, and -1 will be printed as a front and rear element of queue if it is empty.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>push_front_pf()</b>:- that takes the deque and the integer to be added as a parameter.
<b>push_bac_pb()</b>:- that takes the deque and the integer to be added as a parameter.
<b>pop_back_ppb()</b>:- that takes the deque as parameter.
<b>front_dq()</b>:- that takes the deque as parameter.
Constraints:
1 <= N(Number of queries) <= 10<sup>3</sup>
<b>Custom Input: </b>
First line of input should contain the number of queries Q. Next, Q lines should contain any of the given operations:-
For <b>push_front</b> use <b> pf x</b> where x is the element to be added
For <b>push_rear</b> use <b> pb x</b> where x is the element to be added
For <b>pop_back</b> use <b> pp_b</b>
For <b>Display Front</b> use <b>f</b>
Moreover driver code will print
Front element of deque in each push_front opertion
Last element of deque in each push_back operation
Size of deque in each pop_back operation The front_dq() function will return the element at front of your deque in a new line, if the deque is empty you just need to return -1 in the function.Sample Input:
6
push_front 2
push_front 3
push_rear 5
display_front
pop_rear
display_front
Sample Output:
3
3, I have written this Solution Code:
static void push_back_pb(Deque<Integer> dq, int x)
{
dq.add(x);
}
static void push_front_pf(Deque<Integer> dq, int x)
{
dq.addFirst(x);
}
static void pop_back_ppb(Deque<Integer> dq)
{
if(!dq.isEmpty())
dq.pollLast();
else return;
}
static int front_dq(Deque<Integer> dq)
{
if(!dq.isEmpty())
return dq.peek();
else return -1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Yogi and Dharam are playing a game in which one has to solve the problem in order to get out of the room. Dharam goes first and Yogi gave him a problem. Since Dharam is having problem solving it, your task is to solve the problem for him.
Problem:-
Given a range from A to B your task is to count the numbers in which the difference between adjacent digits is not more than one.The first line of input contains a single integer T. The next T lines contain two space- separated integers each containing values of A and B.
Constraints:-
1 <= T <= 100
1 <= A, B <= 1000000000000For each test case print the count of numbers in the range [A, B] such that the difference between adjacent digits is not more than one.Sample Input:-
2
10 30
1 10
Sample Output:-
6
10
Explanation:-
10, 11, 12, 21, 22, 23
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 int count =0;
public static void solve(long a ,long b,long number){
if(number>b){
return;
}
if(number>=a && number <=b){
count++;
}
long last_digit =number % 10;
number *=10;
if(last_digit !=0){
solve(a,b,number+(last_digit-1));
}
if(last_digit !=9){
solve(a,b,number+(last_digit+1));
}
solve(a,b,number+(last_digit));
}
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
long a = sc.nextLong();
long b =sc.nextLong();
count =0;
for(long i=1l ; i<=9l ;i++){
solve(a,b,i);
}
System.out.println(count);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Yogi and Dharam are playing a game in which one has to solve the problem in order to get out of the room. Dharam goes first and Yogi gave him a problem. Since Dharam is having problem solving it, your task is to solve the problem for him.
Problem:-
Given a range from A to B your task is to count the numbers in which the difference between adjacent digits is not more than one.The first line of input contains a single integer T. The next T lines contain two space- separated integers each containing values of A and B.
Constraints:-
1 <= T <= 100
1 <= A, B <= 1000000000000For each test case print the count of numbers in the range [A, B] such that the difference between adjacent digits is not more than one.Sample Input:-
2
10 30
1 10
Sample Output:-
6
10
Explanation:-
10, 11, 12, 21, 22, 23
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int cnt=0;
inline void solve(int a, int b, int p, int c, int i){
if(p>b){return;}
if(p>=a){cnt++;}
int x = p%10;
p*=10;
if(i==c){return;}
solve(a,b,p+x,c,i+1);
if(x!=9){
solve(a,b,p+x+1,c,i+1);
}
if(x!=0){
solve(a,b,p+x-1,c,i+1);
}
}
signed main(){
fast();
int t;
cin>>t;
while(t--){
int a,b;
cnt=0;
cin>>a>>b;
if(b<a){out(-1);continue;}
int ans=b;
int c=0;
while(ans){
c++;
ans/=10;
}
for(int i=1;i<=9;i++){
solve(a,b,i,c,1);
}
out(cnt);
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary square matrix of size N*N and an integer K, your task is to print the maximum side of sub square matrix containing at most K 1's.The first line of input contains two integers N and K, Next N lines contain N space-separated integers depicting the values of the matrix.
<b>Constraints:</b>
1 < = N < = 500
1 < = K < = 100000
0 < = Matrix[][] < = 1Print the maximum side.Sample Input:-
3 2
1 1 1
1 0 1
1 1 0
Sample Output:-
2
Explanation:-
0 1
1 0
is the required sub matrix.
Sample Input:-
2 1
1 0
0 1
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String ar[] = br.readLine().split(" ");
int n = Integer.parseInt(ar[0]);
int k = Integer.parseInt(ar[1]);
int a[][] = new int[n][n];
int sum=0,one_c=0;
for(int i=0;i<n;i++)
{
String arr[] = br.readLine().split(" ");
sum=0;
for(int j=0;j<n;j++)
{
int value=Integer.parseInt(arr[j]);
if(value==1)
one_c++;
sum=sum+value;
a[i][j]=sum;
}
}
for(int j=0;j<n;j++)
{
sum=0;
for(int i=0;i<n;i++)
{
sum=sum+a[i][j];
a[i][j]=sum;
}
}
if(k>=one_c)
{
System.out.println(n);
}
else {
int ans = 1;
for(int len=1;len<=n;len++)
{
boolean flag= false;
for(int i=len;i<n;i++)
{
for(int j=len;j<n;j++)
{
if(j-i==0)
{
if(a[i][j]<=k)
{
ans = Math.max(ans,ans+1);
flag=true;
break;
}
}
else if(j>i)
{
if(i==ans)
{
if(a[i][j]-a[i][j-ans-1]<=k)
{
ans=Math.max(ans,ans+1);
flag = true;
break;
}
}
else {
if(a[i][j]-a[i][j-ans-1]-a[i-ans-1][j]+a[i-ans-1][j-ans-1] <=k)
{
ans = Math.max(ans,ans+1);
flag=true;
break;
}
}
}
if(i>ans) {
if(j==ans)
{
if(a[i][j]-a[i-ans-1][j]<=k)
{
ans=Math.max(ans,ans+1);
flag = true;
break;
}
}
else {
if(a[i][j]-a[i-ans-1][j]-a[i][j-ans-1]+a[i-ans-1][j-ans-1] <=k)
{
ans = Math.max(ans,ans+1);
flag=true;
break;
}
}
}
}
if(flag==true) break;
}
if(flag==false) break;
}
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 binary square matrix of size N*N and an integer K, your task is to print the maximum side of sub square matrix containing at most K 1's.The first line of input contains two integers N and K, Next N lines contain N space-separated integers depicting the values of the matrix.
<b>Constraints:</b>
1 < = N < = 500
1 < = K < = 100000
0 < = Matrix[][] < = 1Print the maximum side.Sample Input:-
3 2
1 1 1
1 0 1
1 1 0
Sample Output:-
2
Explanation:-
0 1
1 0
is the required sub matrix.
Sample Input:-
2 1
1 0
0 1
Sample Output:-
1, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define max1 1001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int a[max1][max1],b[max1][max1];
signed main(){
fast();
int n,k;
cin>>n>>k;
for(int i=0;i<=n;i++){
a[i][0]=0;
a[0][i]=0;
}
FOR(i,n){
FOR(j,n){
cin>>b[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
a[i][j]=a[i][j-1]+b[i-1][j-1];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
a[i][j]=a[i-1][j]+a[i][j];
// out1(a[i][j]);
}
//END;
}
int ans=0;
int cnt=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int l=0;l<=min(n-i,n-j);l++){
cnt=a[i-1][j-1]+a[i+l][j+l]-a[i+l][j-1]-a[i-1][j+l];
if(cnt<=k){
ans=max(ans,l+1);
}
}
}
}
out(ans);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: function easySorting(arr)
{
for(let i = 1; i < 5; i++)
{
let str = arr[i];
let j = i-1;
while(j >= 0 && (arr[j].toString().localeCompare(str)) > 0 )
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = str;
}
return arr;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
map<string,int> m;
string s;
for(int i=0;i<5;i++){
cin>>s;
m[s]++;
}
for(auto it=m.begin();it!=m.end();it++){
while(it->second>0){
cout<<it->first<<" ";
it->second--;}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: inp = input("").split(" ")
print(" ".join(sorted(inp))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static void printArray(String str[])
{
for (String string : str)
System.out.print(string + " ");
}
public static void main (String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
int len = 5;
String[] str = new String[len];
str = br.readLine().split(" ");
Arrays.sort(str, String.CASE_INSENSITIVE_ORDER);
printArray(str);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N strings, find the longest common prefix among all strings present in the array.The fist line of each test contains a single integer N. Next line has space-separated N strings.
Constraints:-
1 <= N <= 10^3
1 <= |S| <= 10^3
Print the longest common prefix as a string in the given array. If no such prefix exists print "-1"(without quotes).Sample Input:
4
geeksforgeeks geeks geek geezer
Sample Output:
gee
Sampel Input:-
3
a b c
Sample Output:-
-1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String[] str = br.readLine().split(" ");
String ref = str[0];
for(String s: str){
if(s.length()<ref.length()){
ref = s;
}
}
for(int i=0; i<n; i++){
if(str[i].contains(ref) == false){
ref = ref.substring(0, ref.length()-1);
}
}
if(ref.length()>0)
System.out.println(ref);
else
System.out.println(-1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N strings, find the longest common prefix among all strings present in the array.The fist line of each test contains a single integer N. Next line has space-separated N strings.
Constraints:-
1 <= N <= 10^3
1 <= |S| <= 10^3
Print the longest common prefix as a string in the given array. If no such prefix exists print "-1"(without quotes).Sample Input:
4
geeksforgeeks geeks geek geezer
Sample Output:
gee
Sampel Input:-
3
a b c
Sample Output:-
-1, I have written this Solution Code: def longestPrefix( strings ):
size = len(strings)
if (size == 0):
return -1
if (size == 1):
return strings[0]
strings.sort()
end = min(len(strings[0]), len(strings[size - 1]))
i = 0
while (i < end and
strings[0][i] == strings[size - 1][i]):
i += 1
pre = strings[0][0: i]
if len(pre) > 1:
return pre
else:
return -1
N=int(input())
strings=input().split()
print( longestPrefix(strings) ), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N strings, find the longest common prefix among all strings present in the array.The fist line of each test contains a single integer N. Next line has space-separated N strings.
Constraints:-
1 <= N <= 10^3
1 <= |S| <= 10^3
Print the longest common prefix as a string in the given array. If no such prefix exists print "-1"(without quotes).Sample Input:
4
geeksforgeeks geeks geek geezer
Sample Output:
gee
Sampel Input:-
3
a b c
Sample Output:-
-1, I have written this Solution Code: function commonPrefixUtil(str1,str2)
{
let result = "";
let n1 = str1.length, n2 = str2.length;
// Compare str1 and str2
for (let i = 0, j = 0; i <= n1 - 1 && j <= n2 - 1; i++, j++) {
if (str1[i] != str2[j]) {
break;
}
result += str1[i];
}
return (result);
}
// n is number of individual space seperated strings inside strings variable,
// strings is the string which contains space seperated words.
function longestCommonPrefix(strings,n){
// write code here
// do not console,log answer
// return the answer as string
if(n===1) return strings;
const arr= strings.split(" ")
let prefix = arr[0];
for (let i = 1; i <= n - 1; i++) {
prefix = commonPrefixUtil(prefix, arr[i]);
}
if(!prefix) return -1;
return (prefix);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N strings, find the longest common prefix among all strings present in the array.The fist line of each test contains a single integer N. Next line has space-separated N strings.
Constraints:-
1 <= N <= 10^3
1 <= |S| <= 10^3
Print the longest common prefix as a string in the given array. If no such prefix exists print "-1"(without quotes).Sample Input:
4
geeksforgeeks geeks geek geezer
Sample Output:
gee
Sampel Input:-
3
a b c
Sample Output:-
-1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string a[n];
int x=INT_MAX;
for(int i=0;i<n;i++){
cin>>a[i];
x=min(x,(int)a[i].length());
}
string ans="";
for(int i=0;i<x;i++){
for(int j=1;j<n;j++){
if(a[j][i]==a[0][i]){continue;}
goto f;
}
ans+=a[0][i];
}
f:;
if(ans==""){cout<<-1;return 0;}
cout<<(ans);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M.
Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K.
Next line contains N integers denoting the elements of arr[]
<b>Constraints:</b>
1 <= N <= 100000
1 <= arr[i] <= 100000
1 <= K <= 100000000Print a single integer the value of smallest number MSample Input:
4 6
2 3 4 9
Sample Output:
4
Explanation:
When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6
When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K.
Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int k = Integer.parseInt(s[1]);
String str[] = br.readLine().split(" ");
int[] arr = new int[n];
for(int i=0;i<n;i++){
arr[i] = Integer.parseInt(str[i]);
}
System.out.print(minDivisor(arr,n,k));
}
static int minDivisor(int arr[],int N, int limit) {
int low = 0, high = 1000000000;
while (low < high)
{
int mid = (low + high) / 2;
int sum = 0;
for(int i = 0; i < N; i++)
{
sum += Math.ceil((double) arr[i] / (double) mid);
}
if(sum <= limit){
high = mid;
}
else{
low = mid + 1;
}
}
return low;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M.
Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K.
Next line contains N integers denoting the elements of arr[]
<b>Constraints:</b>
1 <= N <= 100000
1 <= arr[i] <= 100000
1 <= K <= 100000000Print a single integer the value of smallest number MSample Input:
4 6
2 3 4 9
Sample Output:
4
Explanation:
When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6
When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K.
Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: from math import ceil
def kSum(arr, n, k):
low = 0
high = 10 ** 9
while (low < high):
mid = (low + high) // 2
sum = 0
for i in range(int(n)):
sum += ceil( int(arr[i]) / mid)
if (sum <= int(k)):
high = mid
else:
low = mid + 1
return low
n, k =input().split()
arr = input().split()
print( kSum(arr, n, k) ), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M.
Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K.
Next line contains N integers denoting the elements of arr[]
<b>Constraints:</b>
1 <= N <= 100000
1 <= arr[i] <= 100000
1 <= K <= 100000000Print a single integer the value of smallest number MSample Input:
4 6
2 3 4 9
Sample Output:
4
Explanation:
When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6
When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K.
Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N], n, k;
bool f(int x){
int sum = 0;
for(int i = 1; i <= n; i++)
sum += (a[i]-1)/x + 1;
return (sum <= k);
}
void solve(){
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
int l = 0, h = N;
while(l+1 < h){
int m = (l + h) >> 1;
if(f(m))
h = m;
else
l = m;
}
cout << h;
}
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: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts?
Given an integer N, print "AC" if N is 1. Otherwise, print "WA".
Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N.
<b> Constraints: </b>
0 ≤ N ≤ 1000Print the required answer.Sample Input 1
1
Sample Output 1
AC
Sample Input 2
0
Sample Output 2
WA
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
String num = br.readLine();
int N = Integer.parseInt(num);
String result = "";
if(N < 1000 && N > 0 && N == 1){
result = "AC";
} else {
result = "WA";
}
System.out.println(result);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts?
Given an integer N, print "AC" if N is 1. Otherwise, print "WA".
Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N.
<b> Constraints: </b>
0 ≤ N ≤ 1000Print the required answer.Sample Input 1
1
Sample Output 1
AC
Sample Input 2
0
Sample Output 2
WA
, I have written this Solution Code: N=int(input())
if N==1:
print("AC")
else:
print("WA"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts?
Given an integer N, print "AC" if N is 1. Otherwise, print "WA".
Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N.
<b> Constraints: </b>
0 ≤ N ≤ 1000Print the required answer.Sample Input 1
1
Sample Output 1
AC
Sample Input 2
0
Sample Output 2
WA
, I have written this Solution Code: //Author: Xzirium
//Time and Date: 03:04:29 27 December 2021
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
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_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t clk;
clk = clock();
//-----------------------------------------------------------------------------------------------------------//
READV(N);
if(N==1)
{
cout<<"AC"<<endl;
}
else
{
cout<<"WA"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << 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 arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M.
Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K.
Next line contains N integers denoting the elements of arr[]
<b>Constraints:</b>
1 <= N <= 100000
1 <= arr[i] <= 100000
1 <= K <= 100000000Print a single integer the value of smallest number MSample Input:
4 6
2 3 4 9
Sample Output:
4
Explanation:
When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6
When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K.
Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int k = Integer.parseInt(s[1]);
String str[] = br.readLine().split(" ");
int[] arr = new int[n];
for(int i=0;i<n;i++){
arr[i] = Integer.parseInt(str[i]);
}
System.out.print(minDivisor(arr,n,k));
}
static int minDivisor(int arr[],int N, int limit) {
int low = 0, high = 1000000000;
while (low < high)
{
int mid = (low + high) / 2;
int sum = 0;
for(int i = 0; i < N; i++)
{
sum += Math.ceil((double) arr[i] / (double) mid);
}
if(sum <= limit){
high = mid;
}
else{
low = mid + 1;
}
}
return low;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M.
Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K.
Next line contains N integers denoting the elements of arr[]
<b>Constraints:</b>
1 <= N <= 100000
1 <= arr[i] <= 100000
1 <= K <= 100000000Print a single integer the value of smallest number MSample Input:
4 6
2 3 4 9
Sample Output:
4
Explanation:
When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6
When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K.
Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: from math import ceil
def kSum(arr, n, k):
low = 0
high = 10 ** 9
while (low < high):
mid = (low + high) // 2
sum = 0
for i in range(int(n)):
sum += ceil( int(arr[i]) / mid)
if (sum <= int(k)):
high = mid
else:
low = mid + 1
return low
n, k =input().split()
arr = input().split()
print( kSum(arr, n, k) ), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M.
Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K.
Next line contains N integers denoting the elements of arr[]
<b>Constraints:</b>
1 <= N <= 100000
1 <= arr[i] <= 100000
1 <= K <= 100000000Print a single integer the value of smallest number MSample Input:
4 6
2 3 4 9
Sample Output:
4
Explanation:
When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6
When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K.
Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N], n, k;
bool f(int x){
int sum = 0;
for(int i = 1; i <= n; i++)
sum += (a[i]-1)/x + 1;
return (sum <= k);
}
void solve(){
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
int l = 0, h = N;
while(l+1 < h){
int m = (l + h) >> 1;
if(f(m))
h = m;
else
l = m;
}
cout << h;
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
} , In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three distinct numbers a, b and c which denotes the age of three people 1, 2, 3.
Output the youngest and oldest person among three.Three integers are given as input. a, b, and c denotes the age of person 1, 2, 3 respectively.
<b>Constraints</b>
1 ≤ a ≤ 10<sup>5</sup>
1 ≤ b ≤ 10<sup>5</sup>
1 ≤ c ≤ 10<sup>5</sup>Print the youngest and the oldest person number respectivley.Sample Input:
12 11 7
Sample Output:
3 1
Explanation:
7 is the least among all three so 3 has the least age and similarly, 12 is the maximum among three so 1 is the oldest., I have written this Solution Code: a,b,c = map(int,input().split())
youngest = min(a, b, c)
oldest = max(a, b, c)
# output the youngest and oldest person
if youngest == a:
g = 1
elif youngest == b:
g = 2
else:
g = 3
if oldest == a:
s = 1
elif oldest == b:
s = 2
else:
s = 3
print(g,s), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three distinct numbers a, b and c which denotes the age of three people 1, 2, 3.
Output the youngest and oldest person among three.Three integers are given as input. a, b, and c denotes the age of person 1, 2, 3 respectively.
<b>Constraints</b>
1 ≤ a ≤ 10<sup>5</sup>
1 ≤ b ≤ 10<sup>5</sup>
1 ≤ c ≤ 10<sup>5</sup>Print the youngest and the oldest person number respectivley.Sample Input:
12 11 7
Sample Output:
3 1
Explanation:
7 is the least among all three so 3 has the least age and similarly, 12 is the maximum among three so 1 is the oldest., I have written this Solution Code: import java.util.Scanner;
public class Main
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int s,g; // smallest and greatest
if(a>b && a>c)
g=1;
else if(b>c && b>a)
g=2;
else
g=3;
if(a<b && a<c)
s=1;
else if(b<c && b<a)
s=2;
else
s=3;
System.out.print(s);
System.out.println(" " +g);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two sorted arrays A and B of size N and M respectively.
You have to find the value V, which is the summation of (A[j] - A[i]) for all pairs of i and j such that (j - i) is present in array B.The first line contains two space separated integers N and M – size of arrays A and B respectively.
The second line contains N integers A<sub>1</sub>, A<sub>2</sub>, ... A<sub>N</sub>.
The third line contains M integers B<sub>1</sub>, B<sub>2</sub>, ... B<sub>M</sub>.
<b> Constraints: </b>
1 ≤ N ≤ 2×10<sup>5</sup>
1 ≤ M < N
1 ≤ A<sub>1</sub> ≤ A<sub>2</sub> ≤ ... ≤ A<sub>N</sub> ≤ 10<sup>8</sup>.
1 ≤ B<sub>1</sub> < B<sub>2</sub> < ... < B<sub>M</sub> < N.Print a single integer, the value of V.Sample Input 1:
4 2
1 2 3 4
1 3
Sample Output 1:
6
Sample Explanation 1:
Valid pairs of (i, j) are (1, 2), (2, 3), (3, 4), (1, 4)., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define epsi (double)(0.00000000001)
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<pii>
#define vvi vector<vi>
//#define max(a,b) ((a>b)?a:b)
//#define min(a,b) ((a>b)?b:a)
#define min3(a,b,c) min(min(a,b),c)
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max3(a,b,c) max(max(a,b),c)
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define ff(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define REP(a,b,c) for(int a=b; a<c; a++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define ld long double
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define setbits(x) __builtin_popcountll(x)
#define trav(a,x) for(auto &a:x)
#define make_unique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rev(arr) reverse(all(arr))
#define gcd(a,b) __gcd(a,b);
#define ub upper_bound // '>'
#define lb lower_bound // '>='
#define qi queue<ll>
#define fsh cout.flush()
#define si stack<ll>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define fill(a,b) memset(a, b, sizeof(a))
template<typename T,typename E>bool chmin(T& s,const E& t){bool res=s>t;s=min<T>(s,t);return res;}
const ll INF=1LL<<60;
void solve(){
ll n,m;
cin >> n >> m;
vi v1(n),v2(m);
for(auto &i:v1){
cin >> i;
}
for(auto &i:v2){
cin >> i;
}
ll ans=0;
for(int i=1 ; i<=n ; i++){
auto it=lower_bound(all(v2),i);
ll x=it-v2.begin();
ans+=(x*v1[i-1]);
it=lower_bound(all(v2),n-i+1);
x=it-v2.begin();
ans-=(x*v1[i-1]);
}
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t=1;
// cin >> t;
while(t--){
solve();
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Arun has gone shopping for his new restaurant along with his 8-year-old daughter, Shruthi. They have bought N items. The items are numbered from 1 to N, and item i weighs W<sub>i</sub> grams. Shruthi is eager about helping carry the groceries for her father. She asks her father to give her some items to carry. Arun doesn't want to burden his daughter. But unless he offers her a few things to carry, she won't stop nagging him. Arun decides to give her a few things as a result. Arun obviously wants to give the child fewer things to carry. His daughter, though, is a smart kid.
She advises that the goods be divided into two groups, one of which has exactly K things, in order to prevent being given the absolute least weight to carry. The larger group will then be carried by Arun and the lighter group by his daughter. Help Arun decide which items the daughter should carry. You'll have an easy job to do. Give Arun the maximum possible difference between the weight carried by him and the weight carried by his daughter.The first line of input contains an integer T, denoting the number of test cases. Then T test cases follow. The first line of each test contains two space-separated integers N and K. The next line contains N space- separated integers W<sub>1</sub>, W<sub>2</sub>,...., W<sub>N</sub>.
<b>Constraints</b>
1 ≤ T ≤ 100
1 ≤ K ≤ N ≤ 100
1 ≤ W<sub>i</sub> ≤ 100,000 (10<sup>5</sup>)For each test case, output the maximum possible difference between the weights carried by both in grams.Sample Input :
2
5 2
8 4 5 2 10
8 3
1 1 1 1 1 1 1 1
Sample Output :
17
2
Explanation :
<ul><li>he optimal way is that Arun gives his daughter K = 2 items with weights 2 and 4. Arun carries the rest of the items himself. Thus the difference is (8+5+10)-(4+2) = 23-6 = 17. </li><li>Arun gives his daughter 3 items and he carries 5 items himself.</li></ul>, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main() {
int tt;
cin >> tt;
while (tt--) {
int n, k;
cin >> n >> k;
std::vector<int> v(n);
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
sum += v[i];
}
sort(v.begin(), v.end());
int start = 0, end = 0;
for (int i = 0; i < k; i++) {
start += v[i];
end += v[n - i - 1];
}
if (sum - 2 * start > 2 * end - sum) {
cout << sum - 2 * start << "\n";
} else {
cout << 2 * end - sum << "\n";
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Arun has gone shopping for his new restaurant along with his 8-year-old daughter, Shruthi. They have bought N items. The items are numbered from 1 to N, and item i weighs W<sub>i</sub> grams. Shruthi is eager about helping carry the groceries for her father. She asks her father to give her some items to carry. Arun doesn't want to burden his daughter. But unless he offers her a few things to carry, she won't stop nagging him. Arun decides to give her a few things as a result. Arun obviously wants to give the child fewer things to carry. His daughter, though, is a smart kid.
She advises that the goods be divided into two groups, one of which has exactly K things, in order to prevent being given the absolute least weight to carry. The larger group will then be carried by Arun and the lighter group by his daughter. Help Arun decide which items the daughter should carry. You'll have an easy job to do. Give Arun the maximum possible difference between the weight carried by him and the weight carried by his daughter.The first line of input contains an integer T, denoting the number of test cases. Then T test cases follow. The first line of each test contains two space-separated integers N and K. The next line contains N space- separated integers W<sub>1</sub>, W<sub>2</sub>,...., W<sub>N</sub>.
<b>Constraints</b>
1 ≤ T ≤ 100
1 ≤ K ≤ N ≤ 100
1 ≤ W<sub>i</sub> ≤ 100,000 (10<sup>5</sup>)For each test case, output the maximum possible difference between the weights carried by both in grams.Sample Input :
2
5 2
8 4 5 2 10
8 3
1 1 1 1 1 1 1 1
Sample Output :
17
2
Explanation :
<ul><li>he optimal way is that Arun gives his daughter K = 2 items with weights 2 and 4. Arun carries the rest of the items himself. Thus the difference is (8+5+10)-(4+2) = 23-6 = 17. </li><li>Arun gives his daughter 3 items and he carries 5 items himself.</li></ul>, 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 in=new Scanner(System.in);
int test=in.nextInt();
while(test-->0)
{
int n=in.nextInt();
int k=in.nextInt();
int arr[]=new int[n];
for(int i=0; i<n; i++){
arr[i]=in.nextInt();
}
Arrays.sort(arr);
if(k>n/2)
{
k=n-k;
}
int sum=0;
for(int i=0; i<k; i++){
sum=sum+arr[i];
}
int sum1=0;
for(int i=k; i<n; i++){
sum1=sum1+arr[i];
}
if(sum>sum1){
int total=sum-sum1;
System.out.println(total);
}else{
int total=sum1-sum;
System.out.println(total);
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S.
Constraints
1 <= |S| <= 100000
S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input
ABAAABBBAA
Sample Output
3
Explanation: Substring from character 3-5 is the longest consisting of As only.
Sample Input
AAAA
Sample Output
4, 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 st = br.readLine();
int len = 0;
int c=0;
for(int i=0;i<st.length();i++){
if(st.charAt(i)=='A'){
c++;
len = Math.max(len,c);
}else{
c=0;
}
}
System.out.println(len);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S.
Constraints
1 <= |S| <= 100000
S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input
ABAAABBBAA
Sample Output
3
Explanation: Substring from character 3-5 is the longest consisting of As only.
Sample Input
AAAA
Sample Output
4, I have written this Solution Code: S=input()
max=0
flag=0
for i in range(0,len(S)):
if(S[i]=='A' or S[i]=='B'):
if(S[i]=='A'):
flag+=1
if(flag>max):
max=flag
else:
flag=0
print(max), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S.
Constraints
1 <= |S| <= 100000
S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input
ABAAABBBAA
Sample Output
3
Explanation: Substring from character 3-5 is the longest consisting of As only.
Sample Input
AAAA
Sample Output
4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
string s; cin>>s;
int ct = 0;
int ans = 0;
for(char c: s){
if(c == 'A')
ct++;
else
ct=0;
ans = max(ans, ct);
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd.
Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow.
<b>Constraints:</b>
1 <= N <=10<sup>5</sup>
1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input :
5
1 1 2 2 3
Output:
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));
int noofterm=Integer.parseInt(br.readLine());
int arr[] = new int[noofterm];
String s[] = br.readLine().split(" ");
for(int i=0; i<noofterm;i++){
arr[i]= Integer.parseInt(s[i]);
}
System.out.println(unique(arr));
}
public static int unique(int[] inputArray)
{
int result = 0;
for(int i=0;i<inputArray.length;i++)
{
result ^= inputArray[i];
}
return (result>0 ? result : -1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd.
Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow.
<b>Constraints:</b>
1 <= N <=10<sup>5</sup>
1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input :
5
1 1 2 2 3
Output:
3, I have written this Solution Code: n = int(input())
a = [int (x) for x in input().split()]
mapp={}
for index,val in enumerate(a):
if val in mapp:
del mapp[val]
else:
mapp[val]=1
for key, value in mapp.items():
print(key), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd.
Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow.
<b>Constraints:</b>
1 <= N <=10<sup>5</sup>
1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input :
5
1 1 2 2 3
Output:
3, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
signed main()
{
int n;
cin>>n;
int p=0;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
p^=a;
}
cout<<p<<endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number N.
<b>Note: </b>
The Factorial of a number is the product of an integer and all the integers below it;
e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b>
Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N.
<b>Constraints:</b>
1 <= N <= 15
Return the factorial of the given number.Sample Input:-
5
Sample Output:-
120
Sample Input:-
3
Sample Output:-
6, I have written this Solution Code: def factorial(n):
if(n == 1):
return 1
return n * factorial(n-1)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number N.
<b>Note: </b>
The Factorial of a number is the product of an integer and all the integers below it;
e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b>
Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N.
<b>Constraints:</b>
1 <= N <= 15
Return the factorial of the given number.Sample Input:-
5
Sample Output:-
120
Sample Input:-
3
Sample Output:-
6, I have written this Solution Code: static int Factorial(int N)
{
if(N==0){
return 1;}
return N*Factorial(N-1);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number N.
<b>Note: </b>
The Factorial of a number is the product of an integer and all the integers below it;
e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b>
Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N.
<b>Constraints:</b>
1 <= N <= 15
Return the factorial of the given number.Sample Input:-
5
Sample Output:-
120
Sample Input:-
3
Sample Output:-
6, I have written this Solution Code: // n is the input number
function factorial(n) {
// write code here
// do not console.log
// return the answer as a number
if (n == 1 ) return 1;
return n * factorial(n-1)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary matrix, your task is to calculate the maximum area of a rectangle formed by only 1's in it.First line contains two integers number of rows N and number of columns M.
Next N lines contain M integers with each integer being either 0 or 1
Constraints:-
1 <= N, M <=1000Print the maximum area of rectangle.Sample Input 1:
4 4
0 1 1 0
1 1 1 1
1 1 1 1
1 1 0 0
Sample Output 1:
8
Explanation
The max size rectangle is
1 1 1 1
1 1 1 1
and its area is 4*2 = 8
Sample Input 2:-
1 4
1 1 1 1
Sample Output 2:-
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main { static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) {
FastReader sc = new FastReader();
int n = sc.nextInt();int m = sc.nextInt();
char a[][] = new char[n][m];
for(int i=0;i<n;i++){for(int j=0;j<m;j++){
a[i][j] = sc.next().charAt(0);
}}
System.out.println(findRectangleArea2Ds(a));
}
private static int findRectangleArea2Ds(char[][] matrix) {
if (matrix == null || matrix.length == 0) {
return 0;
}
int maxArea = 0;
int rows = matrix.length;
int cols = matrix[0].length;
int[][] dp = new int[rows][cols];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (matrix[i][j] == '1') {
dp[i][j] = j == 0 ? 1 : dp[i][j - 1] + 1;
int length = dp[i][j];
for (int k = i; k >= 0; k--) {
length = Math.min(length, dp[k][j]);
int width = i - k + 1;
maxArea = Math.max(maxArea, length * width);
}
}
}
}
return maxArea;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary matrix, your task is to calculate the maximum area of a rectangle formed by only 1's in it.First line contains two integers number of rows N and number of columns M.
Next N lines contain M integers with each integer being either 0 or 1
Constraints:-
1 <= N, M <=1000Print the maximum area of rectangle.Sample Input 1:
4 4
0 1 1 0
1 1 1 1
1 1 1 1
1 1 0 0
Sample Output 1:
8
Explanation
The max size rectangle is
1 1 1 1
1 1 1 1
and its area is 4*2 = 8
Sample Input 2:-
1 4
1 1 1 1
Sample Output 2:-
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 = 1e3 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int p[N][N], l[N], r[N];
signed main() {
IOS;
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> p[i][j];
if(p[i][j])
p[i][j] += p[i-1][j];
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
memset(l, 0, sizeof l);
memset(r, 0, sizeof r);
stack<int> s;
p[i][0] = p[i][m+1] = -1;
s.push(0);
for(int j = 1; j <= m; j++){
while(!s.empty() && p[i][s.top()] >= p[i][j])
s.pop();
l[j] = s.top();
s.push(j);
}
while(!s.empty())
s.pop();
s.push(m+1);
for(int j = m; j >= 1; j--){
while(!s.empty() && p[i][s.top()] >= p[i][j])
s.pop();
r[j] = s.top();
s.push(j);
}
for(int j = 1; j <= m; j++)
ans = max(ans, p[i][j]*(r[j]-l[j]-1));
}
cout << ans;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, 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 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int n;
cin>>n;
int a[n][n];
FOR(i,n){
FOR(j,n){
cin>>a[i][j];}}
int sum=0,sum1=0;;
FOR(i,n){
sum+=a[i][i];
sum1+=a[n-i-1][i];
}
out1(sum);out(sum1);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String args[])throws Exception {
InputStreamReader inr= new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(inr);
String str=br.readLine();
int row = Integer.parseInt(str);
int col=row;
int [][] arr=new int [row][col];
for(int i=0;i<row;i++){
String line =br.readLine();
String[] elements = line.split(" ");
for(int j=0;j<col;j++){
arr[i][j]= Integer.parseInt(elements[j]);
}
}
int sumPrimary=0;
int sumSecondary=0;
for(int i=0;i<row;i++){
sumPrimary=sumPrimary + arr[i][i];
sumSecondary= sumSecondary + arr[i][row-1-i];
}
System.out.println(sumPrimary+ " " +sumSecondary);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: // mat is the matrix/ 2d array
// the dimensions of array are n * n
function diagonalSum(mat, n) {
// write code here
// console.log the answer as in example
let principal = 0, secondary = 0;
for (let i = 0; i < n; i++) {
principal += mat[i][i];
secondary += mat[i][n - i - 1];
}
console.log(`${principal} ${secondary}`);
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: n = int(input())
sum1 = 0
sum2 = 0
for i in range(n):
a = [int(j) for j in input().split()]
sum1 = sum1+a[i]
sum2 = sum2+a[n-1-i]
print(sum1,sum2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of positive integers. The task is to find inversion count of array.
Inversion Count : For an array, inversion count indicates how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum.
Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j.
Asked in Adobe, Amazon, Microsoft.The first line of each test case is N, the size of the array. The second line of each test case contains N elements.
Constraints:-
1 ≤ N ≤ 10^5
1 ≤ a[i] ≤ 10^5Print the inversion count of array.Sample Input:
5
2 4 1 3 5
Sample Output:
3
Explanation:
Testcase 1: The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 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));
int n=Integer.parseInt(br.readLine());
String input[]=br.readLine().split("\\s");
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(input[i]);
}
System.out.print(implementMergeSort(a,0,n-1));
}
public static long implementMergeSort(int arr[], int start, int end)
{
long count=0;
if(start<end)
{
int mid=start+(end-start)/2;
count +=implementMergeSort(arr,start,mid);
count +=implementMergeSort(arr,mid+1,end);
count +=merge(arr,start,end,mid);
}
return count;
}
public static long merge(int []a,int start,int end,int mid)
{
int i=start;
int j=mid+1;
int k=0;
int len=end-start+1;
int c[]=new int[len];
long inv_count=0;
while(i<=mid && j<=end)
{
if(a[i]<=a[j])
{
c[k++]=a[i];
i++;
}
else
{
c[k++]=a[j];
j++;
inv_count +=(mid-i)+1;
}
}
while(i<=mid)
{
c[k++]=a[i++];
}
while(j<=end)
{
c[k++]=a[j++];
}
for(int l=0;l<len;l++)
a[start+l]=c[l];
return inv_count;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of positive integers. The task is to find inversion count of array.
Inversion Count : For an array, inversion count indicates how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum.
Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j.
Asked in Adobe, Amazon, Microsoft.The first line of each test case is N, the size of the array. The second line of each test case contains N elements.
Constraints:-
1 ≤ N ≤ 10^5
1 ≤ a[i] ≤ 10^5Print the inversion count of array.Sample Input:
5
2 4 1 3 5
Sample Output:
3
Explanation:
Testcase 1: The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3)., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
long long _mergeSort(int arr[], int temp[], int left, int right);
long long merge(int arr[], int temp[], int left, int mid, int right);
/* This function sorts the input array and returns the
number of inversions in the array */
long long mergeSort(int arr[], int array_size)
{
int temp[array_size];
return _mergeSort(arr, temp, 0, array_size - 1);
}
/* An auxiliary recursive function that sorts the input array and
returns the number of inversions in the array. */
long long _mergeSort(int arr[], int temp[], int left, int right)
{
int mid, inv_count = 0;
if (right > left) {
/* Divide the array into two parts and
call _mergeSortAndCountInv()
for each of the parts */
mid = (right + left) / 2;
/* Inversion count will be sum of
inversions in left-part, right-part
and number of inversions in merging */
inv_count += _mergeSort(arr, temp, left, mid);
inv_count += _mergeSort(arr, temp, mid + 1, right);
/*Merge the two parts*/
inv_count += merge(arr, temp, left, mid + 1, right);
}
return inv_count;
}
/* This funt merges two sorted arrays
and returns inversion count in the arrays.*/
long long merge(int arr[], int temp[], int left,
int mid, int right)
{
int i, j, k;
long long inv_count = 0;
i = left; /* i is index for left subarray*/
j = mid; /* j is index for right subarray*/
k = left; /* k is index for resultant merged subarray*/
while ((i <= mid - 1) && (j <= right)) {
if (arr[i] <= arr[j]) {
temp[k++] = arr[i++];
}
else {
temp[k++] = arr[j++];
/* this is tricky -- see above
explanation/diagram for merge()*/
inv_count = inv_count + (mid - i);
}
}
/* Copy the remaining elements of left subarray
(if there are any) to temp*/
while (i <= mid - 1)
temp[k++] = arr[i++];
/* Copy the remaining elements of right subarray
(if there are any) to temp*/
while (j <= right)
temp[k++] = arr[j++];
/*Copy back the merged elements to original array*/
for (i = left; i <= right; i++)
arr[i] = temp[i];
return inv_count;
}
signed main()
{
int n;
cin>>n;
int a[n];
unordered_map<int,int> m;
for(int i=0;i<n;i++){
cin>>a[i];
if(m.find(a[i])==m.end()){
m[a[i]]=i;
}
}
cout<<mergeSort(a,n);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), 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 t = Integer.parseInt(br.readLine());
for(int i=0;i<t;i++){
int n = Integer.parseInt(br.readLine());
System.out.println(Ways(n,1));
}
}
static int Ways(int x, int num)
{
int val =(x - num);
if (val == 0)
return 1;
if (val < 0)
return 0;
return Ways(val, num + 1) + Ways(x, num + 1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
long cnt=0;
int j;
void sum(int X,int j) {
if(X==0){cnt++;}
if(X<0)
{return;}
else {
for(int i=j;i<=(X);i++){
X=X-i;
sum(X,i+1);
X=X+i;
}
}
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(n<1){cout<<0<<endl;continue;}
sum(n,1);
cout<<cnt<<endl;
cnt=0;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: // ignore number of testcases
// n is the number as provided in input
function numberOfWays(n) {
// write code here
// do not console.log the answer
// return answer as a number
if(n < 1) return 0;
let cnt = 0;
let j;
function sum(X, j) {
if (X == 0) { cnt++; }
if (X < 0) { return; }
else {
for (let i = j; i <= X; i++) {
X = X - i;
sum(X, i + 1);
X = X + i;
}
}
}
sum(n,1);
return cnt
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: for _ in range(int(input())):
x = int(input())
n = 1
dp = [1] + [0] * x
for i in range(1, x + 1):
u = i ** n
for j in range(x, u - 1, -1):
dp[j] += dp[j - u]
if x==0:
print(0)
else:
print(dp[-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array A[] of size N of positive integers. One number 'a' from set {1, 2, …N} is missing and one number 'b' occurs twice in an array. The task is to find the repeating and the smallest positive missing number.The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the size of array.
The second line contains N space-separated integers A(1), A(2), ..., A(N) denoting the elements of the array.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 10^5
1 ≤ A[i] ≤ NFor each test case, in a new line, print b, which is the repeating number, followed by a, which is the smallest positive missing number, in a single line.Input:
2
2
2 2
3
1 3 3
Output:
2 1
3 2
<b>Explanation:</b>
Testcase 1: Repeating number is 2 and the smallest positive missing number is 1.
Testcase 2: Repeating number is 3 and the smallest positive missing number is 2., I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
static int a[] = new int[1000001];
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0)
{
int n = sc.nextInt();
for(int i = 0; i < n; i++)
a[i]= sc.nextInt();
for(int i = 0; i < n; i++)
{
if(a[Math.abs(a[i])-1]>0)
a[Math.abs(a[i])-1] = -a[Math.abs(a[i])-1];
else
System.out.print(Math.abs(a[i]) + " ");
}
for(int i = 0; i < n; i++)
{
if(a[i] >0)
System.out.println(i+1);
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array A[] of size N of positive integers. One number 'a' from set {1, 2, …N} is missing and one number 'b' occurs twice in an array. The task is to find the repeating and the smallest positive missing number.The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the size of array.
The second line contains N space-separated integers A(1), A(2), ..., A(N) denoting the elements of the array.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 10^5
1 ≤ A[i] ≤ NFor each test case, in a new line, print b, which is the repeating number, followed by a, which is the smallest positive missing number, in a single line.Input:
2
2
2 2
3
1 3 3
Output:
2 1
3 2
<b>Explanation:</b>
Testcase 1: Repeating number is 2 and the smallest positive missing number is 1.
Testcase 2: Repeating number is 3 and the smallest positive missing number is 2., I have written this Solution Code: t = int(input())
a = None
b = None
while t>0:
n = int(input())
arr = list (map(int ,input().split()))
arr2 = [0] * (n+1)
for i in arr:
arr2[i] +=1
for i in range(1, n+1):
if arr2[i] == 0:
b = i
if arr2[i] == 2:
a = i
print(a,b)
t -=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array A[] of size N of positive integers. One number 'a' from set {1, 2, …N} is missing and one number 'b' occurs twice in an array. The task is to find the repeating and the smallest positive missing number.The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the size of array.
The second line contains N space-separated integers A(1), A(2), ..., A(N) denoting the elements of the array.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 10^5
1 ≤ A[i] ≤ NFor each test case, in a new line, print b, which is the repeating number, followed by a, which is the smallest positive missing number, in a single line.Input:
2
2
2 2
3
1 3 3
Output:
2 1
3 2
<b>Explanation:</b>
Testcase 1: Repeating number is 2 and the smallest positive missing number is 1.
Testcase 2: Repeating number is 3 and the smallest positive missing number is 2., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n],x;
for(int i=0;i<n;i++){
a[i]=0;
}
for(int i=0;i<n;i++){
cin>>x;
x--;
a[x]++;
}
for(int i=0;i<n;i++){
if(a[i]==2){cout<<i+1<<" ";}
}
for(int i=0;i<n;i++){
if(a[i]==0){cout<<i+1<<endl;}
}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
bool EqualOrNot(int h1, int h2, int v1,int v2){
if (v2>v1&&(h1-h2)%(v2-v1)==0){
return true;
}
return false;
}
int main(){
int n1,n2,v1,v2;
cin>>n1>>n2>>v1>>v2;
if(EqualOrNot(n1,n2,v1,v2)){
cout<<"Yes";}
else{
cout<<"No";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code: def EqualOrNot(h1,h2,v1,v2):
if (v2>v1 and (h1-h2)%(v2-v1)==0):
return True
else:
return False
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code: static boolean EqualOrNot(int h1, int h2, int v1,int v2){
if (v2>v1&&(h1-h2)%(v2-v1)==0){
return true;
}
return false;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an n*m grid which contains lower case English letters. How many times does the phrase "saba" appear horizontally, vertically, and diagonally in the grid?
The phrase "saba" must look one of these shapes:First line: Two integer n and m, where n denotes (1 <= n, m <= 100) the number of rows and m denotes the number of columns in the grid.
Next n lines: Each line must contain a string of length m which contains lower- case English letters only.
<b>Constraints</b>
1 ≤ n, m ≤ 100Print the number of times the word “saba” appears in the grid.
Sample Input 1:
5 5
s a f e r
a m j a d
b a b o l
a a r o n
s o n g s
Sample Output 1:
2, I have written this Solution Code: 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
{
// BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));
Scanner inp = new Scanner(System.in);
int r,c;
r = inp.nextInt();
c = inp.nextInt();
char[][] array = new char[r][c];
for(int i=0 ; i<r ; i++){
for(int j=0 ; j<c ; j++){
array[i][j] = inp.next().charAt(0);
}
}
int count=0;
for(int a=0; a<r; a++){
for(int b=0; b<c; b++){
if(b+3<=c-1){
if(array[a][b]=='s'
&& array[a][b+1]=='a'
&& array[a][b+2]=='b'
&& array[a][b+3]=='a'){
count++;
}
}
if(a+3<=r-1){
if(array[a][b]=='s'
&& array[a+1][b]=='a'
&& array[a+2][b]=='b'
&& array[a+3][b]=='a'){
count++;
}
}
if(a+3<=r-1 && b+3<=c-1){
if(array[a][b]=='s'
&& array[a+1][b+1]=='a'
&& array[a+2][b+2]=='b'
&& array[a+3][b+3]=='a'){
count++;
}
}
if(a-3>=0 && b+3<=c-1){
if(array[a][b]=='s'
&& array[a-1][b+1]=='a'
&& array[a-2][b+2]=='b'
&& array[a-3][b+3]=='a'){
count++;
}
}
}
}
System.out.print(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, super primes are those integers from 1 to N whose multiples (other than themselves) do no exist in the range [1, N].
Your task is to generate all super primes <= N in sorted order.
</b>Note: Super primes are not related to primes in any way.</b><b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SuperPrime()</b> that takes the integer N as a parameter.
Constraints:-
2 < = N <= 1000Printing will be done by the driver code you just need to complete the generator function.Sample Input:-
5
Sample Output:-
3 4 5
Sample Input:-
4
Sample Output:-
3 4, I have written this Solution Code: public static void SuperPrimes(int n){
int x = n/2+1;
for(int i=x ; i<=n ; i++){
out.printf("%d ",i);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, super primes are those integers from 1 to N whose multiples (other than themselves) do no exist in the range [1, N].
Your task is to generate all super primes <= N in sorted order.
</b>Note: Super primes are not related to primes in any way.</b><b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SuperPrime()</b> that takes the integer N as a parameter.
Constraints:-
2 < = N <= 1000Printing will be done by the driver code you just need to complete the generator function.Sample Input:-
5
Sample Output:-
3 4 5
Sample Input:-
4
Sample Output:-
3 4, I have written this Solution Code: def SuperPrimes(N):
for i in range (int(N/2)+1,N+1):
yield i
return
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array and Q queries. Your task is to perform these operations:-
enqueue: this operation will add an element to your current queue.
dequeue: this operation will delete the element from the starting of the queue
displayfront: this operation will print the element presented at the frontUser task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>enqueue()</b>:- that takes the integer to be added and the maximum size of array as parameter.
<b>dequeue()</b>:- that takes the queue as parameter.
<b>displayfront()</b> :- that takes the queue as parameter.
Constraints:
1 <= Q(Number of queries) <= 10<sup>3</sup>
<b> Custom Input:</b>
First line of input should contains two integer number of queries Q and the size of the array N. Next Q lines contains any of the given three operations:-
enqueue x
dequeue
displayfrontDuring a dequeue operation if queue is empty you need to print "Queue is empty", during enqueue operation if the maximum size of array is reached you need to print "Queue is full" and during displayfront operation you need to print the element which is at the front and if the queue is empty you need to print "Queue is empty".
Note:-Each msg or element is to be printed on a new line
Sample Input:-
8 2
displayfront
enqueue 2
displayfront
enqueue 4
displayfront
dequeue
displayfront
enqueue 5
Sample Output:-
Queue is empty
2
2
4
Queue is full
Explanation:-here size of given array is 2 so when last enqueue operation perfomed the array was already full so we display the msg "Queue is full".
Sample input:
5 5
enqueue 4
enqueue 5
displayfront
dequeue
displayfront
Sample output:-
4
5, I have written this Solution Code: public static void enqueue(int x,int k)
{
if (rear >= k) {
System.out.println("Queue is full");
}
else {
a[rear] = x;
rear++;
}
}
public static void dequeue()
{
if (rear <= front) {
System.out.println("Queue is empty");
}
else {
front++;
}
}
public static void displayfront()
{
if (rear<=front) {
System.out.println("Queue is empty");
}
else {
int x = a[front];
System.out.println(x);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N integers. Find the number of subarrays of this array that are powerful.
A subarray [L, R] (1 <= L <= R <= N) is said to be powerful if the product A<sub>L</sub> * A<sub>L+1</sub> * ... * A<sub>R-1</sub> * A<sub>R</sub> is odd.The first line of input contains a single integer N
The second line of input contains N integers representing the elements of the array Arr
<b>Constraints </b>
1 <= N <= 100000
1 <= Arr[i] <= 100000Output the number of powerful subarrays of array Arr.Sample Input 1
5
2 4 4 5 3
Sample output 1
3
Sample Input 2
3
1 5 1
Sample Output 2
6
<b>Explanation:</b>
(3), (5), (3, 5) are the required subarrays.
(1), (2), (1), (1, 5), (5, 1]) (1, 5, 1) are the required subarrays., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
long cnt=0;
long ans=0;
for(int i=0;i<n;i++){
if(a[i]&1){cnt++;}
else{
ans+=(cnt*(cnt+1))/2;
cnt=0;
}
}
ans+=(cnt*(cnt+1))/2;
cout<<ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N integers. Find the number of subarrays of this array that are powerful.
A subarray [L, R] (1 <= L <= R <= N) is said to be powerful if the product A<sub>L</sub> * A<sub>L+1</sub> * ... * A<sub>R-1</sub> * A<sub>R</sub> is odd.The first line of input contains a single integer N
The second line of input contains N integers representing the elements of the array Arr
<b>Constraints </b>
1 <= N <= 100000
1 <= Arr[i] <= 100000Output the number of powerful subarrays of array Arr.Sample Input 1
5
2 4 4 5 3
Sample output 1
3
Sample Input 2
3
1 5 1
Sample Output 2
6
<b>Explanation:</b>
(3), (5), (3, 5) are the required subarrays.
(1), (2), (1), (1, 5), (5, 1]) (1, 5, 1) are the required subarrays., I have written this Solution Code: n = int(input())
arr = list(map(int,input().split()))
c=0
result=0
for i in arr:
if i % 2 != 0:
c += 1
else:
result += (c*(c+1)) / 2
c=0
result += (c*(c+1)) / 2
print(int(result)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N integers. Find the number of subarrays of this array that are powerful.
A subarray [L, R] (1 <= L <= R <= N) is said to be powerful if the product A<sub>L</sub> * A<sub>L+1</sub> * ... * A<sub>R-1</sub> * A<sub>R</sub> is odd.The first line of input contains a single integer N
The second line of input contains N integers representing the elements of the array Arr
<b>Constraints </b>
1 <= N <= 100000
1 <= Arr[i] <= 100000Output the number of powerful subarrays of array Arr.Sample Input 1
5
2 4 4 5 3
Sample output 1
3
Sample Input 2
3
1 5 1
Sample Output 2
6
<b>Explanation:</b>
(3), (5), (3, 5) are the required subarrays.
(1), (2), (1), (1, 5), (5, 1]) (1, 5, 1) are the required subarrays., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
InputStreamReader inputStreamReader=new InputStreamReader(System.in);
BufferedReader reader=new BufferedReader(inputStreamReader);
int n =Integer.parseInt(reader.readLine());
String str=reader.readLine();
String[] strarr=str.split(" ");
int[] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(strarr[i]);
}
long noOfsubArrays=0;
int start=0;
boolean sFlag=false;
for(int i=0;i<n;i++){
if(arr[i]%2!=0){
if(!sFlag){
start=i;
noOfsubArrays++;
sFlag=true;
continue;
}
noOfsubArrays+=2;
int temp=start;
temp++;
while(temp<i){
temp++;
noOfsubArrays++;
}
}else if(arr[i]%2==0 && sFlag){
sFlag=false;
}
}
System.out.println(noOfsubArrays);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Peter Parker is taking part in a competition where Mr Tony Stark has come to see Peter lift the cup. But Tony can't tell what position Peter is on since the school authorities didn't display a leaderboard. Help Tony Identify which rank is Peter on by seeing his victory status in different rounds. Points are awarded on solving every question based on the difficulty level of the question which are divided into subcategories. The player with the highest score is ranked number 1 on the leaderboard. Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number.The first line contains an integer n, the number of participants on the leaderboard. The next line contains n space- separated integers containing the leaderboard points in decreasing order in the competition. The next line contains an integer m, denoting the number of times Peter is attempting the question. The last line contains m space- separated integers containing Peter's score in each attempt in the competition.
<b>Constraints:-</b>
1 <= n <= 10<sup>5</sup>
1 <= m <= 10<sup>3</sup>
1 <= points, score <= 10<sup>7</sup>
Note:-
In the existing leaderboard, points are in descending order. Peter's points are in ascending order.Print m integers indicating Peter's rank in each competition.Sample Input:-
7
100 100 50 40 40 20 10
4
5 25 50 120
Sample Output:-
6
4
2
1, 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 line1 = br.readLine();
String[] num1 = line1.trim().split("\\s+");
int[] arr1 = new int[n];
for(int i = 0; i < n; i++)
{
arr1[i] = Integer.parseInt(num1[i]);
}
int m = Integer.parseInt(br.readLine());
int[] arr2 = new int[m];
String line2 = br.readLine();
String[] num2 = line2.trim().split("\\s+");
for(int i = 0; i < m; i++)
{
arr2[i] = Integer.parseInt(num2[i]);
}
Stack<Integer> st = new Stack<>();
for(int i = 0; i < n; i++)
{
while(!st.isEmpty() && st.peek() == arr1[i])
st.pop();
st.push(arr1[i]);
}
for(int i = 0; i < m; i++)
{
while(!st.isEmpty() && st.peek() <= arr2[i])
st.pop();
System.out.println(st.size() + 1);
st.push(arr2[i]);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Peter Parker is taking part in a competition where Mr Tony Stark has come to see Peter lift the cup. But Tony can't tell what position Peter is on since the school authorities didn't display a leaderboard. Help Tony Identify which rank is Peter on by seeing his victory status in different rounds. Points are awarded on solving every question based on the difficulty level of the question which are divided into subcategories. The player with the highest score is ranked number 1 on the leaderboard. Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number.The first line contains an integer n, the number of participants on the leaderboard. The next line contains n space- separated integers containing the leaderboard points in decreasing order in the competition. The next line contains an integer m, denoting the number of times Peter is attempting the question. The last line contains m space- separated integers containing Peter's score in each attempt in the competition.
<b>Constraints:-</b>
1 <= n <= 10<sup>5</sup>
1 <= m <= 10<sup>3</sup>
1 <= points, score <= 10<sup>7</sup>
Note:-
In the existing leaderboard, points are in descending order. Peter's points are in ascending order.Print m integers indicating Peter's rank in each competition.Sample Input:-
7
100 100 50 40 40 20 10
4
5 25 50 120
Sample Output:-
6
4
2
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
// freopen("ou.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
unsigned long n, m, i, tmp;
cin>> n;
stack<unsigned long> scores;
for (i = 0; i< n; ++i) {
cin>>tmp;
if (scores.empty() || scores.top() != tmp) scores.push(tmp);
}
cin>> m;
for (i = 0; i< m; ++i) {
cin>>tmp;
while (!scores.empty() &&tmp>= scores.top()) scores.pop();
cout<< (scores.size() + 1) <<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 X of size N containing positive integers, Newton is required to compute and output the product of all the numbers in the array modulo 10<sup>9</sup>+7.The first line contains a single integer N denoting the size of the array.
The next line contains N space- separated integers denoting the elements of the array
<b>Constraints</b>
1 ≤ N ≤ 10<sup>3</sup>
1 ≤ A<sub>[i]</sub> ≤ 10<sup>3</sup>Print a single integer denoting the product of all the elements of the array Modulo 10<sup>9</sup>+7.Sample Input:
5
1 2 3 4 5
Sample output:
120
<b>Explanation</b>
There are 5 integers to multiply. Let's store the final answer in the output variable. Since 1 is the identity value for multiplication, initialize the output as 1.
output = 1
output = (output*1)%(10<sup>9</sup>+7)
output = (output*2)%(10<sup>9</sup>+7)
output = (output*3)%(10<sup>9</sup>+7)
output = (output*4)%(10<sup>9</sup>+7)
output = (output*5)%(10<sup>9</sup>+7), I have written this Solution Code: #include <iostream>
using namespace std;
int main() {
int n,i;
long long int p=1;
cin >> n;
int a[n];
for(i=0;i<=n-1;i++)
{
cin>>a[i];
p=(p*a[i])%(1000000007);
}
cout<<p;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array X of size N containing positive integers, Newton is required to compute and output the product of all the numbers in the array modulo 10<sup>9</sup>+7.The first line contains a single integer N denoting the size of the array.
The next line contains N space- separated integers denoting the elements of the array
<b>Constraints</b>
1 ≤ N ≤ 10<sup>3</sup>
1 ≤ A<sub>[i]</sub> ≤ 10<sup>3</sup>Print a single integer denoting the product of all the elements of the array Modulo 10<sup>9</sup>+7.Sample Input:
5
1 2 3 4 5
Sample output:
120
<b>Explanation</b>
There are 5 integers to multiply. Let's store the final answer in the output variable. Since 1 is the identity value for multiplication, initialize the output as 1.
output = 1
output = (output*1)%(10<sup>9</sup>+7)
output = (output*2)%(10<sup>9</sup>+7)
output = (output*3)%(10<sup>9</sup>+7)
output = (output*4)%(10<sup>9</sup>+7)
output = (output*5)%(10<sup>9</sup>+7), I have written this Solution Code: n = int(input())
arr = [int(x) for x in input().split()]
output = 1
mod = 1000000007
for i in range(n):
output = (output*arr[i]) % mod
print(output), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SumOfDivisors()</b> that takes the integer N as parameter.
Constraints:-
1<=N<=10^9Return the sum of all of the divisors.Sample Input:-
4
Sample Output:-
7
Sample Input:-
13
Sample Output:-
14, I have written this Solution Code: public static long SumOfDivisors(long N){
long sum=0;
long c=(long)Math.sqrt(N);
for(long i=1;i<=c;i++){
if(N%i==0){
sum+=i;
if(i*i!=N){sum+=N/i;}
}
}
return sum;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.