Java Programs
Java Programs
Java Programs
Problem Description:
Sajid was booking a train ticket from Chennai to Delhi for his family.
Two of the relatives was interested in joining that journey from different places with their family
members
So, Sajid booked tickets for those persons also along with his family members.
this travel. Can you help him in finding the total number of
passengers?
Constraint:
1 < num1 ≤ 15
1 ≤ num2 ≤ 15
1 ≤ num3 ≤ 15
Input Format:
Only Line of input has three integers num 1, num2 and num3 separated by a space representing the
numbers of ticket booked by Sajid at three different interval of time.
Output Format:
Code:
import java.io.*;
import java.util.Scanner;
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
int d = a+b+c;
System.out.println(+d);
}
2. Problem Description:
The shop keeper specified the the bill amount. Nancy also given some amount to the shop keeper
for paying the bill.
But she likes to know the quotient and remainder after dividing the amount given by her by the bill
amount specified by shop keeper.
Constraint:
5 samtgivens 2500
Input Format:
First Line: Integer value of amtgiven representing the amount given by nancy.
Output Format:
Code:
import java.io.*;
import java.util.Scanner;
int q = amtgiven/billamt;
int r = amtgiven%billamt;
System.out.println("Quotient:"+q);
System.out.println("Remainder:"+r);
}
3. Problem Description:
Rathik organized technical round interview in Macrosoft for the set of computer science candidates.
The problem is to perform addition, subtraction, multiplication, and division of given two numbers.
Rathik have given the deadline of only 5 minutes to complete the problem.
Can you Help the candidates to complete the problem within the specified time limit?
Constraint:
1 ≤ testnum2 < 50
Input Format:
The only line of input has two numbers a and b of type integers separated by a comma.
Output Format:
Print Addition, Subtraction, Multiplication, Division, and Modulus of given two numbers in a
separate line respectively.
Note: Rathik instructed his candidates to print the result of the division with 3 values after decimal
point.
Code:
import java.io.*;
import java.util.Scanner;
System.out.println("Subtraction : "+(testnum1-testnum2));
System.out.println("Multiplication : "+(testnum1*testnum2));
float div;
System.out.println("Division : "+String.format("%.3f",div));
System.out.println("Modulus : "+(testnum1%testnum2));
}
4. Problem Description:
Rebecca bought a new volleyball in the sports shop. It looks like a medium size.
She somehow found the radius of the sphere. But she would like to know the volume of
that ball. Can you help him in finding the Volume of the ball?
Functional Description:
π = 3.14
Constraint:
1.00 ≤r ≤ 5.00
Input Format:
The only line of input has a single value of type float representing the radius of the ball.
Output Format:
Code:
import java.util.Scanner;
double v = (4.0/3.0)*3.14 ;
System.out.println(String.format("%.6f",v*(Math.pow(radiusofball, 3))));
}
5. Problem Description:
Selvan was playing with the a object of random size for stress relief.
Selvan knows that the Length, Width, and Height of the object.
But he would like to know the surface area of the object he is playing with.
Functional Description:
Surface area of the Object = 2 x [width x length + length x height + height x width]
Constraints:
1 ≤ width ≤ 10
1 ≤ height ≤ 10
Input Format:
Output Format:
Print a single integer value representing the surface area of the object selvam is playing with.
Code:
import java.io.*;
import java.util.Scanner;
System.out.println(area);
}
6. Problem Description:
The Electricity Officer has mentioned the total counts of unit and amount.
The officer inform the customer the bill amount in a unique format.
But customers are finding the difficult to find the exact amount that needs to be paid.
Functional Description:
Constraints:
1 ≤ unitconsumed ≤ 500
2 ≤ costperunit ≤ 10
Input Format:
Output Format:
Code:
import java.io.*;
import java.lang.Math;
import java.util.Scanner;
System.out.println(Math.pow(unitconsumed, costperunit));
}
7. Problem Description:
Phoenix mall in the capital city of Washington and it is rectangular in shape when it is seen on the
map with the size n x m meters.
On the occasion of the jubilee anniversary, a decision was taken to pave the Square with square
marbles stones. Each stone is of the size nxn.
Can you what is the least number of stones needed to pave the Square?
It's allowed to cover the surface larger than the Mall Square, but the Square has to be covered.
It's not allowed to break the stones. The sides of stones should be side by side(parallel) to the sides
of the Square.
Constraints:
1 ≤ n ≤ 10^9
1 sm≤ 10^9
1 sas 10^9
Input Format:
The only line of input contains three positive integer numbers n, m and a separated by a space.
Output Format:
Code:
import java.io.*;
import java.util.Scanner;
int n = input.nextInt();
int m = input.nextInt();
int a = input.nextInt();
System.out.println(((m+a-1)/a)*((n+a-1)/a));
}
8. Problem Description:
During the IPL Match between CSK and MI, as a part of IPL contest the question was asked to the
fans.
Who are all giving the correct answer to that question will get the free VIP box ticket for the Final for
which CSK have already qualified.
The question is convert given integer number to octal and hexadecimal number respectively.
Abilash is an die heart CSK fan. Can you help him answer the question so that he can watch CSK play
the final from VIP box?
Constraints:
1 siplno≤ 10000
Input Format:
Only line of input has single integer number that need to be converted.
Output Format:
In the First line of output print the octal number equivalent to the input value.
In the Second line of output print the hexadecimal number equivalent to the input value.
Code:
import java.io.*;
import java.util.Scanner;
System.out.println(Integer.toOctalString(iplno));
System.out.println(Integer.toHexString(iplno));
}
9. Problem Description:
On one beautiful Sunday Selvan went to Aaron's house for exam preparation.
They have decided to study Mathematics subject because they have exams by coming Monday,
Aaron is a master in Mathematics but Selvan is not so good in Mathematics so James trained with
Selvan for getting a high score in the exam.
After teaching some problems to Selvan. Aaron have given some tasks to Selvan to solve.
Constraints:
Input Format:
The first and second line of the input represents two different input value of type float. Output
Format:
The first and second line of the output represents outputs of first and second line of input of type
double.
Code:
import java.io.*;
import java.util.Scanner;
System.out.print(num1);
System.out.println("0000");
System.out.print(num2);
System.out.println("0000");
}
10. Problem Description:
The employees of one million dollar profit company TeamZilla organised the strike because they
want to have additional salary increment, the strike is continuing for more than a month now.
Rathik the CEO of TeamZilla has found the solution to break the strike, so he organised a small
technical competition for his employees.
Most of the employees who were part of the strike have participated in the technical event
announced and in that there was a task of printing the ASCII Value of the character inputted.
Can you help them to complete the task and win the competition?
Constraint:
a ≤ Asc ≤ z
A ≤ Asc ≤ Z
Input format:
Output format:
Code:
import java.io.*;
import java.util.Scanner;
System.out.println(+Asc);
}
11. Question description:
Kenneth is playing in a T20 cricket match. In a match, Team A plays for 20 overs. In a
single over, the team gets to play 6 times, and in each of these 6 tries, they can score a
maximum of 6 runs. After Team A's 20 overs are finished, Team B similarly plays for 20
overs and tries to get a higher total score than the first team. The team with the higher
Kenneth is in Team B. Team A has already played their 20 overs, and have gotten a score of R.
Kenneth's Team B has started playing, and have already scored C runs in the first O overs. In the
remaining 20-0 overs, find whether it is possible for Kenneth's Team B to get a score high enough to
win the game. That is, can their final score be strictly larger than R?
Constraints:
• O≤C≤R≤720
• O≤C≤36*O
Input Format:
Output Format:
Output in a single line, the answer, which should be "YES" if it's possible for Kenneth's Team B to win
the match and "NO" if not.
Code:
import java.util.Scanner;
int r,o,c;
r = sc.nextInt();
o = sc.nextInt();
c = sc.nextInt();
int a = 20-o;
int b = (a*6*6)+c;
System.out.println(d);
}
}
12. Question description
An important part of preparing for a competition is sharing programming knowledge from the
experienced members to those who are just beginning to deal with the contests. Therefore, during
the next team training Zach decided to make teams so that newbies are solving problems together
with experienced participants.
Zach believes that the optimal team of three people should consist of one experienced participant
and two newbies. Thus, each experienced participant can share the experience with a large number
of people.
However, Miller believes that the optimal team should have two experienced members plus one
newbie. Thus, each newbie can gain more knowledge and experience.
As a result, Zach and Miller have decided that all the teams during the training session should belong
to one of the two types described above. Furthermore, they agree that the total number of teams
should be as much as possible.
There are n experienced members and m newbies on the training session. Can calculate what
maximum number of teams can be formed? you
Constraints:
0≤ n, m≤5.105
Input Format:
The first line contains two integers n and m - the number of experienced participants and newbies
that are present at the training session.
Output Format:
Code:
import java.util.Scanner;
int n,m;
n = input.nextInt();
m = input.nextInt();
int c = (n+m)/3;
System.out.println(Math.min(Math.min(n,m),Math.min(m,c)));
}
}
13. Question description
Once upon a time, there lived a mad programmer. He loved to solve creative problems other than
anything. His wife loved him quite a lot but disliked his curiosity for the problems. One day he came
from office, his wife gave him a glass of cold lime juice. She was in a romantic mood and waiting for
some romantic stuff. But the programmer asked her curiously, "If I give u radius of the top and
bottom part of the glass and the height, can you come up with the volume of the glass?" His wife
became a bit disappointed but as she is smart she replied with a smile, "You already have drunk
some juice, and the glass is not full. If I give you the height of the juice, can you find the volume of
the remaining juice in the glass?" Then the programmer kissed his wife and said, "You are the best
problem setter in the world!"
Now he set the same problem for you. The radius of the upper part г¡ and lower part г2 is given. If
height of the glass is h and height of the juice is p what is the volume of the juice in the glass?
problem-1217-juice-1603773420519.png (153x172)
Constraints:
1 ≤ 2 < ≤ 100
1 ≤psh≤ 100
Input Format:
Each case starts with a line containing four integers r,r2,h and p
Output Format:
For each case, print the case number and the volume of the juice in the glass, and the decimal value
should be rounded off to 4 decimal places
Code:
import java.util.Scanner;
double r1,r2,h,p,r,k,juice;
r1=sc.nextDouble();
r2=sc.nextDouble();
h=sc.nextDouble();
p=sc.nextDouble();
r = p/(h*1.0)*(r1-r2)+r2;
k = (Math.PI/3.0);
juice = k*p*(r*r+r2*r2+(r*r2));
System.out.printf("%.4f%n",juice);
}
14. Question description
Bryan Mills needs a fence around his farm, but he is too lazy to build it himself. So he purchased a
fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can
only make fence corners at a single angle a.
Will the robot be able to build the fence Bryan Mills wants? In other words, is there a regular
polygon which angles are equal to a?
Constraints:
Input Format:
Single line input contains a single integer a- the angle the robot can make corners at measured in
degrees.
Output Format:
Output on a single line "YES" (without quotes), if the robot can build a fence Bryan Mills wants, and
"NO" (without quotes), if it is impossible.
Code:
import java.io.*;
import java.util.Scanner;
int y,x;
x = input.nextInt();
y = (360%(180-x));
System.out.println(y==0 ?"YES":"NO");
} }
15. Question description
Charles has three socks in his drawer. Each sock has one of 10 possible colors, which are represented
by integers between 1 and 10. Specifically, the colors of the socks are A,B and C
Charles has to wear two socks which have the same color. Help Charles find out if that is possible or
not. Charles has three socks in his drawer. Each sock has one of 10 possible colors, which are
represented by integers between 1 and 10. Specifically, the colors of the socks are A,B and C
Charles has to wear two socks which have the same color. Help Charles find out if that is possible or
not.
Explanation:
Since there are no two socks with the same color, Charles cannot wear a pair of socks with the same
color.
Constraints
1<A,B,C<10
Input Format:
The first and only line of the input contains three space-separated integers A,B and C
Output Format:
Print a single line containing the string "YES" if it is possible for Charles to wear two socks with the
same color or "NO" if it is impossible.
Code:
import java.io.*;
import java.util.Scanner;
int a,b,c;
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
System.out.println("YES");
else
{
System.out.println("NO");
}
16. Question description
Mathew is really young and is just starting to learn english, John wants to explain him about
consonants and vowels
Help john to write a program that takes a letter as input and displays whether the entered character
is a consonant or vowel
Constraints
1≤N≤10^5
|S|=N
Input Format:
Output Format:
Code:
import java.io.*;
import java.util.Scanner;
char ch = input.next().charAt(0);
System.out.println("Vowel"); }
else{3
System.out.println("Consonant");
} } }
17. Question description
Jones has got a task from his boss and he needs to finish it by evening
He gave him a set of phone numbers and he has to reverse the digits of those phone numbers and
generate new phone numbers which are going to be used by the company
Help Jones to complete the task quick since he wants to watch the football match this evening
Constraints
1≤n≤100
1sk≤10
Input Format:
Output Format:
Code:
import java.util.Scanner;
{ int n,remainder,reverse;
int reverse = 0;
while(n>0){
n /=10;
return reverse;
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
System.out.println(reverse(n));
}
18. Question description
Tim went camping with his friends and they thought to casually roam around in the nature
They come across a lake and they though to play around for a while so they play a small game
There are three piles of stones. The first pile contains a stones, the second pile contains
b stones and the third pile contains c stones. Tim must choose one of the piles and split
the stones from it to the other two piles, specifically, if the chosen pile initially contained
s stones, he should choose an integer k (0 ≤k≤ s), move k stones from the chosen pile
onto one of the remaining two piles and s – k stones onto the other remaining pile.
Determine if it is possible for the two remaining piles (in any order) to contain x stones
Constraints:
1≤T≤100
Isa,b,c,x,y≤10^6
Input Format:
The first line of the input contains a single integer T denoting the number of test cases. The
description of T test cases follows.
The first and only line of each test case contains five space-separated integers a, b, c, x and y
Output Format:
For each test case, print a single line containing the string "YES" if it is possible to obtain piles of the
given sizes or "NO" if it is impossible.
Code:
import java.util.Scanner;
int t = input.nextInt();
for(int i=0;i<t;i++)
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
int x = input.nextInt();
int y = input.nextInt();
if(a+b+c!=(x+y) || Math.min(x,y)<Math.min(a,Math.min(b,c)))
System.out.println("NO");
else
System.out.println("YES");
}
19. Question description:
Stephen has three shoes of the same size lying around. Each shoe is either a left shoe (represented
using O) or a right shoe (represented using 1). Given A, B, C, representing the information for each
shoe, find out whether he can go out now, wearing one left shoe and one right shoe.
Constraints:
1≤T≤8
O≤A,B,C≤1
Input Format:
The first line contains an integer T, the number of test cases. Then the test cases follow
Output Format:
For each test case, output in a single line the answer: 1 if it's possible to go out with a pair of shoes
and 0 if not.
Code:
import java.io.*;
import java.util.Scanner;
int t = input.nextInt();
while(t-->0)
int a,b,c;
a = input.nextInt();
b = input.nextInt();
c = input.nextInt();
int n = a+b+c;
if(n>=1&&n<3)
System.out.println("1");
else
System.out.println("0");
}
}
20. Question description
You are given the height H (in metres) and mass M (in kilograms) of Tony. The
Report the category into which Tony falls, based on his BMI:
Category 2: Normal weight if BMI is {19, 20,..., 24} • Category 3: Overweight if BMI is {25, 26,..., 29}
Constraints:
1<T<2*10^4
1<M≤10^4
1<H<10^2
Input Format:
• The first line of input will contain an integer, T, which denotes the number of testcases. Then the
testcases follow.
• Each testcase contains a single line of input, with two space separated integers, M, H, which
denote the mass and height of Tony respectively.
Output Format:
For each testcase, output in a single line, 1, 2, 3 or 4, based on the category in which Tony falls.
Code:
import java.io.*;
import java.util.Scanner;
int t = input.nextInt();
while(t-->0)
float bmi,m,h;
m = input.nextFloat();
h = input.nextFloat();
bmi = m/(h*h);
if(bmi<=18)
{System.out.println("1");}
{System.out.println("2");}
{System.out.println("3");}
else
{System.out.println("4");}
}
21. Question description
Bruce has just entered a lottery contest where he gets a chance to win 1000$
He has to count the number of multiples of 7 between 1 and the given number n
Can you help him to win this lottery so that he can have a nice summer vacation?
Constraints
1≤n≤10^5
Input Format:
Output Format:
Code:
import java.util.Scanner;
long n,res = 0;
n = input.nextLong();
if (i % 7 == 0)
res++;
System.out.println(res);
}
22. Question description
Bill was solving some problems in his math textbook and after he was done his friend
He gave him the sizes of angles of a simple quadrilateral (in degrees) A,B,C and D in some order
along its perimeter. Bill has to determine whether the quadrilateral is cyclic.
Note: A quadrilateral is cyclic if and only if the sum of opposite angles is 180 degrees
Constraints:
1≤T≤10^4
1<A,B,C,D≤357
A+B+C+D=360
Input Format:
The first line of the input contains a single integer T denoting the number of test cases.
The first and only line of each test case contains four space-separated integers A, B, C and D.
Output Format:
Print a single line containing the string "YES" if the given quadrilateral is cyclic or "NO" if it is not
(without quotes).
Code:
import java.io.*;
import java.util.Scanner;
int A,B,C,D;
int t = input.nextInt();
while(t-->0)
A = input.nextInt();
B = input.nextInt();
C = input.nextInt();
D = input.nextInt();
System.out.println("YES");
else
System.out.println("NO");
}
23. Question description:
Timothy is a computer science student and his teacher gave him a simple question to solve within
time but he is little busy in his life, so he asked you to solve this problem.
Problem statement: You have been given an array of positive integers A1,A2,...,An with length N and
you have to print an array of same length (N) where the values in the new array are the sum of every
number in the array, except the number at that index.
Constraints:
1 ≤ N ≤105
0≤A[i]≤109
Input Format:
Output Format:
Code:
import java.util.Scanner;
long sum = 0;
int n = input.nextInt();
a[i] = input.nextInt();
sum += a[i];
for(int i=0;i<n;i++)
sb.append(sum-a[i]+" ");
System.out.println(sb);
} }
24. Question description
Price of each item is represented using an array P where Pi represents the price of item i.
A customer always buys 3 items of the lowest price from his store.
Find out the profit Frederick can make from that customer. It is guaranteed that his store has at least
3 items.
Constraints:
3≤N≤10^5
1≤A[i]≤10^3
Input Format:
First line contains N which represents the number of items in Jon's store.
Second line contains N space separated integers P1, P2, P3,...., PN which represents
Output Format:
Output in a single line answer the profit Frederick makes from those 3 items.
Code:
import java.util.Scanner;
import java.util.Arrays;
int n,i,sum=0;
n = S.nextInt();
for(i=0;i<n;i++)
s[i]= S.nextInt();
for(i=0;i<3;i++)
{
Arrays.sort(s);
sum+=s[i];
System.out.println(sum);
}
25. Question description
Lucas and his friend were scratching the lottery cards and checking whether the numbers on the
screen would match
Eventually Lucas and his friend got bored so his friend gave Lucas a challenge. They considered the
random numbers of lottery cards as an array of n positive integers and an integer X and task is to
find the frequency of X in the array
Constraints:
1≤N≤1000
1<A[i]≤10^5
1≤x≤1000
Input Format:
Output Format:
The frequency or the number of times the number X has occurred in the array A1,A2,A2....An.
Code:
import java.util.Scanner;
int n,count=0;
int i;
n = sc.nextInt();
for(i=0;i<n;i++)
arr[i]=sc.nextInt();
int v = sc.nextInt();
for(i=0;i<n;i++){
if(arr[i]==v){
count++;
System.out.println(count);
}
26. Question description
He has given him an array A of n integers as input. Also, you are given two integers, / and r and you
have to print the subarray [1,...,r] (sub array of A from position /to position ǹ).
If he solves this challenge his brother will give him a brand new Play Station 5? Can you help Carl and
get his PS5?
Constraints:
1≤n≤10^6
-10^9≤A[i]≤10^9
Input Format:
Output Format:
Code:
import java.util.Scanner;
int n,i;
int l,r;
n = sc.nextInt();
for(i=0;i<n;i++)
X[i]=sc.nextInt();
l = sc.nextInt();
r = sc.nextInt();
for(i=l-1;i<r;i++)
{
System.out.print(X[i]+" ");
}
27. Question description
Hank is participating in a hackathon and he has been given an array al,a2,...,an consisting of n
positive integers and a positive integer m.
He has to check whether $1>S2. If the first sum of array is greater than second sum print "YES" ,else
print "NO".
Constraints:
1≤n≤10^5
1≤m≤10^5
(1 sai≤109)
Input Format:
The first line of each test case contains two integers n, m (1≤n≤105,1<m<105) (1≤n≤105,1<m≤105).
Output Format:
Code:
import java.util.Scanner;
int n,m,j,s1=0,s2=0;
n = sc.nextInt();
m = sc.nextInt();
for(j=0;j<n;j++){
arr[j]=sc.nextInt();
for(int i=0;i<n;i++){
s1+=arr[i];
}
for(int i=0;i<m;i++){
s2+=arr[i];
if(s1>s2){
System.out.println("YES");
else{
System.out.println("NO");
–––
28. Question description:
Lucas was a nice teacher, and he wanted to give a problem to the students present in class, to make
them practice for the test next week.
Given an array of N integers, print the product of the numbers present in the array.
Constraints:
1 <= N <= 10
Input Format:
Each test cases consists of two lines, the first line containing N, the number of elements, and the
second line containing N integers.
Output Format:
Code:
import java.util.Scanner;
import java.util.Arrays;
long ans = 1;
int n = sc.nextInt();
for(int i=0;i<n;i++)
arr[i] = sc.nextInt();
ans = ans*arr[i];
System.out.println(ans);
}
29. Question description
Jacob has been bunking classes lately and has been caught by the guard flunking the class. His class
teacher gave him an extra homework as punishment. Jacob has to finish the work quickly so
Given an array of size N consisting of only O's and I's. The array is sorted in such a manner that all
the 1's are placed first and then they are followed by all the O's. Find the count of all the O's.
Constraints:
1<N≤105
O≤Arr[i]≤1
Input Format:
First line contains a single integer input which specifies the number of elements in an array
Output Format:
Code:
import
java.util.Scanner;
import java.util.Arrays;
int count=0,n,i;
n = sc.nextInt();
for(i=0;i<n;i++)
arr[i]=sc.nextInt();
if(arr[i]==0)
count++;
System.out.println(count);
} }
30. Question description
Davis loves travelling. Today, he will take the train from Manchester to Bristol
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is Xo'clock, and the train will start in exactly Y hours. When will the Train Start?
Answer in 24-hour time
Constraints:
O≤X,Y≤23
Input Format:
Output Format:
Print the hour of the starting time of the contest in 24-hour time.
Code:
import java.util.*;
int t;
CurrentTime.t= sc.nextInt();
RemTime.t= sc.nextInt();
else
System.out.println(CurrentTime.t + RemTime.t);
}
31. Question description
There are two rectangles. The lengths of the vertical sides of the first rectangle are U, and the
lengths of the horizontal sides of the first rectangle are V. The lengths of the vertical sides of the
second rectangle are X, and the lengths of the horizontal sides of the second rectangle are Y.
Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that
area.
Constraints:
1≤U≤104
1sV≤104
1sY≤104
Input Format:
Single line input contains 4 integers U,V,X,Y separated by space representing the lengths and
breadths of first and second rectangle correspondingly
Output Format:
Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that
area.
Code:
import java.util.*;
class Rectangle1{
int U,V;
class Rectangle2{
int X,Y;
R1.U= sc.nextInt();
R1.V= sc.nextInt();
R2.X= sc.nextInt();
R2.Y= sc.nextInt();
System.out.println(Math.max(R1.U*R1.V,R2.X*R2.Y));
}
32. Question description
Jax the analyst has adopted n little bunnies. As we all know, bunnies love carrots. Thus, Jax has
bought a carrot to be shared between his bunnies. Jax wants to treat all the bunnies equally, and
thus he wants to cut the carrot into n pieces of equal area.
Formally, the carrot can be viewed as an isosceles triangle with base length equal to 1 and height
equal to h. Jax wants to make n-1 cuts parallel to the base to cut the carrot into n pieces. He wants
to make sure that all n pieces have the same area. Can you help Jax determine where to cut the
carrot so that each piece have equal area?
Constraints:
2 ≤ n ≤ 1000
1sh≤ 105
Input Format:
The first and only line of input contains two space separated integers, n and h
Output Format:
The output should contain n-1 real numbers x1, x2, ..., Xn-1. The number x, denotes that the ith cut
must be made x¡ units away from the apex of the carrot.
Code:
import java.util.*;
class Carrot{
int numofpieces,height;
divisions.numofpieces= S.nextInt();
divisions.height= S.nextInt();
for(int i=1;i<divisions.numofpieces;i++)
System.out.print(String.format("%.4f",divisions.height*Math.sqrt(i*1.0/divisions.numofpiec
es))+" ");
}
33. Question description
Kendrick has been studying about geometrical shapes recently and he thought to write a rap verse
based on a geometrical shape and thought the name Pyramid sounds cool. So he wants to write a
couple of lines based on the volume of Trapezoid in his song but doesn't know how to find the
volume of a rectangular pyramid. Given the lengths of its length, width, and height are x, y, and z,
respectively. Can you help Kendrick find the volume of Trapezoid?
Constraints:
1sy≤100
Input Format:
Single line input consists of a decimal floating point value representing the lengths of its length,
width, and height respectively separated by a space
Output Format:
Print the volume of the given rectangular pyramid rounded off to 4 decimal points.
Code:
import java.util.Scanner;
class RectPyramidArea
area.x= sc.nextFloat();
area.y= sc.nextFloat();
area.z= sc.nextFloat();
float a = (area.x*area.y*area.z)/3;
}
34. Question description
Zane would most likely take the cab today for work since he gave his car for servicing. At last he
would know the total distance covered by cab.
Can you help him to calculate the total fare for the whole ride?
Constraints:
O≤R,P,Q,D≤105
Input Format:
Single line input contains four integers representing the first R kilometers followed by P which is the
corresponding fare for first R kilometers followed by Q which is the fare for the remaining distance
covered and D which is the total distance travelled and all of them are separated by a space.
Output Format:
Code:
import java.util.*;
int R,P;
int Q,D;
IF.R= sc.nextInt();
IF.P= sc.nextInt();
SF.Q= sc.nextInt();
SF.D= sc.nextInt();
System.out.println(IF.R*IF.P+(SF.D-IF.R)*SF.Q);
}
35. Question description
Brody went across the neighbourhood to get some lemonade and he came across a lemonade stand
hosting a small contest and if the person who takes the challenge clears it up they get a glass of
lemonade for free. The statement of the contest was, given non negative integers u and v (u≤v), and
a positive integer w. Among the integers between u and v, inclusive, how many are divisible
by w?
Can you help Brody get a nice cool glass of lemonade for free?
Constraints: Is u, vs1018
Is ws1018
Input Format:
Output Format:
Print the number of the integers between u and v, inclusive, that are divisible by w.
Code:
import java.util.Scanner;
obj.a= sc.nextInt();
obj.b= sc.nextInt();
obj.c= sc.nextInt();
int count=0;
for(int i=obj.a;i<=obj.b;i++){
if(i%obj.c==0){
count++;
}
System.out.println(count);
}
36. Question description
You are asked to break exactly one of them into two pieces in such a way that:
Constraints:
Input Format:
The only line of each testcase contains three integers 11,12,13 the lengths of the sticks.
Output Format:
Print "POSSIBLE" if it's possible to break one of the sticks into two pieces with positive integer length
in such a way that it's possible to construct a rectangle from the resulting four sticks. Otherwise,
print "NOT POSSIBLE".
Code:
import java.util.Scanner;
class StickRectangles
int s1,s2,s3;
stick.s1= S.nextInt();
stick.s2= S.nextInt();
stick.s3= S.nextInt();
System.out.println("POSSIBLE");
}
else
System.out.println("NOT POSSIBLE");
}
37. Question description
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Mary is trying to distribute the packs between the two students so that each student gets
the same number of candies. Determine whether it is possible.
Note that Mary cannot take candies out of the packs, and the whole contents of each pack must be
given to one of the students.
Constraints:
Isa,b,c≤ 1000
Input Format:
Output Format:
If it is possible to distribute the packs so that each student gets the same number of candies, print
Yes. Otherwise, print No.
Code:
import java.util.Scanner;
class ClassAdmin {
int a,b,c;
obj.a= sc.nextInt();
obj.b= sc.nextInt();
obj.c= sc.nextInt();
System.out.println("YES");
else
System.out.println("NO");
}
38. Question description
Brady is given a list of N triangles. Each triangle is identified by the coordinates of its three corners in
the 2-D cartesian plane. His job is to figure out how many of the given triangles are right triangles. A
right triangle is a triangle in which one angle is a 90 degree angle. The vertices of the triangles have
integer coordinates and all the triangles given are valid(three points aren't colinear).
Constraints:
Input Format:
Single line input contains six space separated integers X1,Y1,X2,Y2,X3, Y3 where (X1,Y1) (X2,Y2) (
X3,Y3) are the vertices of a triangle.
Output Format:
Print "It is a Right Angled Triangle" if the given coordinates form a right angle triangle otherwise
print "Not a Right Angled Triangle".
Code:
import java.util.Scanner;
class Coordinates
int X1,Y1; }
int X2,Y2; }
int X3,Y3; }
point1.X1= Sc.nextInt();
point1.Y1= Sc.nextInt();
point2.X2= Sc.nextInt();
point2.Y2= Sc.nextInt();
point3.X3= Sc.nextInt();
point3.Y3= Sc.nextInt();
if ((A == (B + C) || B == (A + C) || C == (A + B)))
else
}
39. Question description
Neil has planned a trip using trains and buses. The train fare will be M euros if you buy ordinary
tickets along the way, and Neuros if you buy an unlimited ticket. Similarly, the bus fare will be O
euros if you buy ordinary tickets along the way, and Peuros if you buy an unlimited ticket.
Find the minimum total fare when the optimal choices are made for trains and buses.
Constraints:
1<M<1000
1<N≤1000
1≤0≤1000
1<P≤1000
Input Format:
Output Format:
Print the minimum total fare which can help Neil save some money.
Code:
import java.util.Scanner;
class TrainFare
int M,N;
class BusFare
int O,P;
train.M= sc.nextInt();
train.N= sc.nextInt();
bus.O= sc.nextInt();
bus.P= sc.nextInt();
}
40. Question description
The main street of Candyland is a straight line with n houses built along it (n is an even number). The
houses are located at both sides of the street. The houses with odd numbers are at one side of the
street and are numbered from 1 to n-1 in the order from the beginning of the street to the end (in
the picture: from left to right). The houses with even numbers are at the other side of the street and
are numbered from 2 to n in the order from the end of the street to its beginning (in the picture:
from right to left). The corresponding houses with even and odd numbers are strictly opposite each
other, that is, house 1 is opposite house n, house 3 is opposite house n-2, house 5 is opposite house
n-4 and so on.
Brad needs to get to house number a as quickly as possible. He starts driving from the beginning of
the street and drives his car to house a. To get from the beginning of the street to houses number 1
and n, he spends exactly 1 second. He also spends exactly one second to drive the distance between
two neighbouring houses. Brad can park at any side of the road, so the distance between the
beginning of the street at the houses that stand opposite one another should be considered the
same.
Your task is: find the minimum time Brad needs to reach house a.
Constraints:
Input Format:
The first line of the input contains two integers, n and a- the number of houses on the street and the
number of the house that Brad needs to reach, correspondingly. It is guaranteed that number n is
even.
Output Format:
Print a single integer — the minimum time Brad needs to get from the beginning of the street to
house a.
Code:
import java.util.*;
if(y%2==0) {
System.out.print((x-y)/2+1);
else {
System.out.print(y/2+1);
int n,a;
n= sc.nextInt();
a= sc.nextInt();
housenumbers(n,a);
}
41. Question description
Donald seemingly down-to-earth guy. Donald has a Brother Ronald. Ronald leads a life of a computer
hacker by day and a thief by night. One day, Ronald tries to break the door digital lock of Donald's
room.
But it only accepts a perfect number as input. Can you help him to make a program for checking the
given number is the perfect number or not...
Explanation:
Constraints:
1≤num≤10000
Input Format:
Output Format:
Print whether the given number is a perfect number or not a perfect number.
Code:
import java.util.Scanner;
for(i=1;i<=num/2;i++)
rem = num % i;
if (rem == 0){
sum = sum + i;
if (sum == num)
System.out.println("Perfect Number");
else
System.out.println("Not a Perfect Number");
return sum;
int a= sc.nextInt();
perfect(a);
}
42. Question description
Alfred likes everything infinite. Now he is studying the properties of a sequence s, such that its first
element is equal to a (s₁ = a), and the difference between any two neighbouring elements is equal to
c (s;- §;- 1 = c). In particular, Alfred wonders if his favourite integer b appears in this sequence, that
is, there exists a positive integer i, such that s;= b. Of course, you are the person he asks for a help.
Constraints:
- 109 ≤ a, b, c≤ 109
Input Format:
The first line of the input contain three integers a, b and c - the first element of the sequence,
Alfred's favorite number and the difference between any two neighbouring elements of the
sequence, respectively.
Output Format:
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
Code:
import java.util.Scanner;
if(z==0) {
if(x==y){
System.out.println("YES");
else {
System.out.println("NO");
return;}
System.out.println("YES");
else {
System.out.println("NO");
}}
a= sc.nextInt();
b= sc.nextInt();
c= sc.nextInt();
infsequence(a,b,c);
}}
43. Question description
Travis Scott shared pictures of his batman suit on Instagram but it ended up becoming a meme .
Felix is hosting meme review this Friday and Therefore, he decided to take a string S and change
each of its substrings that spells "Travis" to "Batman". Find the resulting string.
Constraints:
1<|S|≤105
Input Format:
The first and only line of each test case contains a single string S
Output Format:
Print a single line containing the string after it is modified by Felix by replacing "Travis" with
"Batman"
Code:
import java.util.Scanner;
import java.lang.String;
String s;
s=sc.nextLine();
System.out.println(s); } }
44. Question description
Nicholas take the metro everyday from Brooklyn to Manhattan and likes to read the newspaper
during the journey. He eventually got bored of reading the routine news everyday so he started
playing a small game to keep himself entertained. He started to count the number of alphabets,
digits and special characters in a whole sentence of the newspaper.
Can you also join Nicholas and hang out with him?
Constraints:
Input Format:
Output Format:
Print the number of alphabets, digits and special characters in the sentence.
Code:
import java.util.Scanner;
int ascii;
int alphabets=0,digits=0,splchar=0;
char[]str=st.toCharArray();
for(int i=0;i<str.length;i++)
ascii = str[i];
digits++;
else if(ascii >= 65 && ascii <= 90 || ascii >= 97 && ascii <= 122) {
alphabets++;
else {
splchar++;
}
}
45. Question description
Mike is getting really bored during the lecture so he started to add all the digits of the current page
number the teacher is reading from the textbook and called the sum S(n)
Let S(n) denote the sum of the digits in the decimal notation of the page number. For example,
S(101)=1+0+1=2.
Constraints
Input Format:
Single line input which has a string S which consists of a number representing the page number
Output Format:
Code:
import java.util.Scanner;
String str;
int sum=0;
str = sc.next();
int j = Character.digit(number.charAt(i),10);
sum+=j;
if(num%sum==0){
System.out.println("Yes");
else{
System.out.println("No");
} }
46. Question description
To train their logical thinking and solve problems better, Hamilton and Jake decided to play chess.
During the game Hamilton wondered whose position is now stronger.
The player's weight equals to the sum of weights of all his pieces on the board.
As Hamilton doesn't like counting, he asked you to help him determine which player has the larger
position weight.
Constraints:
Input Format:
The input contains eight lines, eight characters each - the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with
lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook
- as 'R', the bishop - as 'B', the knight - as 'N', the pawn - as 'P', the king - as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there
can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so
on.
Output Format:
Print "White" (without quotes) if the weight of the position of the white pieces is more than the
weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than
the weight of the white pieces and print "Draw" if the weights of the white and black pieces are
equal.
Code:
import java.util.Scanner;
interface Chess{
int s_white=0,s_black=0;
s[i] =input.nextLine();
if(s[i].charAt(j)==white[k]) {
s_white+=verif[k];
if(s[i].charAt(j)==black[k]) {
s_black+=verif[k];}}}
if(s_white>s_black)
System.out.print("White");
if(s_white<s_black)
System.out.print("Black");
if(s_white==s_black)
System.out.print("Draw");
input.close();
}
47. Question description
Collin, Cindy, Hannah, and Hunter are four friends sharing a one-room workspace. The workspace
has a single thermostat which they can set to any integer temperature between 35 degrees to 95
degrees Fahrenheit, inclusive.
The four friends can't agree on the room's temperature! Collin and Cindy don't want it to be too
cold, while Hannah and Hunter don't want it to be too hot. Specifically:
Given c1, c2,h1 and h₂ and is there a satisfactory temperature that all four friends will be happy
with? If it's possible, print YES; otherwise, print NO.
Constraints:
Input Format:
Four space-separated integers describing the respective values of c1, c2,h1 and h2
Output Format:
Print YES if it's possible to satisfy all four friends' conditions; otherwise, print NO instead.
Code:
import java.util.*;
class Temperature{
int c1,c2,h1,h2;
if(Math.max(c1,c2)<=Math.min(h1,h2)){
return "YES";
else {
return "NO";
}
}
temp.c1=sc.nextInt();
temp.c2=sc.nextInt();
temp.h1=sc.nextInt();
temp.h2=sc.nextInt();
System.out.println(result);
}
48. Problem Description:
The company calculates salary for the employees on the basis of employee working
Since the number of people working in the company is huge salary calculation become a tedious
process at the end of the each day.
Constraints:
Input Format:
The First line of the input has a single value representing the total working hours of type
integer.
The Second line of the input has single value representing the salary per day of type double.
Output Format:
Print the total salary in single line with two values after decimal point.
Code:
import java.io.*;
import java.util.Scanner;
System.out.println(String.format("%.2f",tot));
}
49. Problem Description:
Swathy and Nancy were selected for Spacey programme which was about to take place the next
year, in their interview they were struck with the question.
The question is that if the floating number is given they have to create a code to display the
rightmost integer from the integer part of the number.
If they have the logic for the code they will be the part of the digital meter designing for the Spacey
Mars launch which was their dream.
Can you help them with a logic of the code for the criteria given to them?
Constraints:
Input Format:
Only Line of Input has single value of type float. Output Format:
Explanation:
If the input is given 124.34, then the output to be displayed is 4 (i.e) Before decimal the integral part
is 124, in that last digit is 4.
Code:
import java.io.*;
import java.util.Scanner;
num=(int)spacenum;
digit = num%10;
System.out.println(digit); } }
50. Problem Description:
Arul and Kani own the farm in the beautiful location of the city were lot of cows was roaming
around.
On that day cows have eaten the grasses in the farm which is circular in structure. Whem Arul and
Kani reached the location they were shocked to see the grass being
eaten by crows.
Now they wold like to know for how much area and circumference of the farm the cows have eaten
the grass.
Functional Description:
Circumference = 2*π*г
Area =π *r*r
π = 3.14
Constraints:
Input Format:
The only line of the input represents the radius of the circle of type float.
Output Format:
Print the area in the first line and circumference in the second line with only 2 values after decimal
point
Code:
import java.util.Scanner;
System.out.println(String.format("%.2f", area));
System.out.println(String.format("%.2f", circumference));
}
51. Problem Description:
Flipkart announced the year end stock clearance sale and as apart of they have also conducting the
contest and the users answering the questions asked in the contest can win Moto One Power free of
cost.
The task is to display the first three powers (N^1, N^2, N^3) of the given.
If you help nishanth in solving the task he will get his favorite mobile.Can you help him?
Constraints:
Input Format:
Output Format:
Code:
import java.lang.Math;
import java.util.Scanner;
int N = input.nextInt();
double NP = (double)N;
System.out.print(N);
System.out.println(""); } }
52. Problem Description:
One day his teacher was taking a class about shapes and asked the students to find the Area of the
triangle using Heron's formula.
Sajid misheard this as Hero's formula and was curious to discover the Hero's formula
Help Sajid to solve his math problem by using the correct logic in your code.
Functional Description:
s = (a+b+c)/2
and
Constraints:
Isas 15
1<b≤15
Isc≤ 15
Input Format:
Only Line of input has 3 integers representing 3 side of the triangle separated by a space.
Output Format:
Print the area of the triangle with only two values after the decimal point
Code:
import java.io.*;
import java.util.Scanner;
int a=input.nextInt();
int b=input.nextInt();
int c=input.nextInt();
double s = (a+b+c)/2;
System.out.println(String.format("%.2f",(Math.sqrt(area))));
}
53. Problem Description:
Roopa and Atifa are sisters they love to compete by playing math games which gradually helped
them in their academics one day.
Atifa just had add the two floating point numbers but the twist is Atifa should only add the integer
part of the decimal number.
But Atifa thought she can code a program for the puzzle but she is finding it difficult.
Explanation:
Roopa gave her sister two floating point numbers: 23.44 and 33.22 Her sister need to identify the
left side integral part of given numbers are 23 and 33. Finally the added output value is 56.
Constraint:
Input Format:
First Line: Has Single Input of type float representing first number
Second Line: Has Single Input of type float representing second number
Output Format:
Code:
import java.io.*;
import java.util.Scanner;
float num1=input.nextFloat();
float num2=input.nextFloat();
System.out.println(Math.round(sum1));
} }
54. Problem Description:
Arif planned to make a room cleaning robot for his college mini project competition.
First he has to code program to simulate the robot movements inside the room.
Once the values are available, his program should compute and display the area of the room.
Can you help Arif with a suitable logic for the code?
Constraint:
Input format:
First Line:has single floating point number representing length of the room Second Line:has single
floating point number representing width of the room
Output format:
Code:
import java.io.*;
import java.util.Scanner;
System.out.println(String.format("%.2f",(length*width))+" sq.ft");
} }
55. Problem Description:
Issac loved to do agriculture he worked for a 9-5 job in the week days and dedicated to do
agriculture on the week end.
He dreamed to combine technology and agriculture together in the future. He started with a small
automated automobile that can water the plants when he is not available in the field.
He measured his field in square feet but for generalising his project he wished to convert it to acres.
Can you help him with a code that reads the area of the farmer's field in square feet and display the
area in acres?
Functional Description:
Constraints:
20000.00≤tractLand≤70000.00
Input format:
Single Line of Input has a tractland's area in square feet of type float.
Output format:
Print the input area of the tractLand in square feet and its equivalent area in acres in a single line.
Code:
import java.io.*;
import java.util.Scanner;
float tractLand,tractLandAcred;
tractLand = input.nextFloat();
tractLandAcred = tractLand/43560;
}
56. Problem Description:
Aaron took his girl friend Binita to a restauraunt as he got a job of his dreams. Since he had small
welcome interview he was little bit tennsed.
Binita figured this out and to get back Aaron's confidence she gave him a little task,
When they received the bill for the food they ordered, she asked aaron to find out the tax amount of
the bill and tip for the meal through a computer code.
Aaron can use your local tax rate when computing the amount of tax owing.
Note:
Tip amount=5%
Constraint:
50sbillwt≤ 1300
Where billwt is the variable you should use for getting the bill amount without tax and tip.
Input format:
Single Line of input has single value of type integer representing the Bill Amount Without Tax and Tip
Output format:
In First Line Print the calculated Tax with only 2 values after decimal point.
In the Second Line Print the calculated Tip with only 2 values after decimal point.
In the Third Line Print the Total Bill Amount with tax and tip with only 2 values after decimal point.
Code:
import java.io.*;
import java.util.Scanner;
int billwt;
billwt = input.nextInt();
double b = (double)billwt;
}
57. Problem Description:
So he started working in a grocery store. In the grocery store he need to get the product ID, price of
the product(Price per Unit) and the quantity of the product purchased by the customer.
At point of time he found he was doing the same job again and again so he thought of automating
the task.
Constraint:
Input Format:
Output Format:
Code:
import java.io.*;
import java.util.Scanner;
int prodid,billid,quantity;
float price,totprice;
billid = input.nextInt();
prodid = input.nextInt();
price = input.nextFloat();
quantity = input.nextInt();
totprice = price * quantity;
System.out.println(String.format("%.2f",totprice));
}
58. Question description
Pete and his friends are walking along the fence of height h and they do not want the guard to notice
them. In order to achieve this the height of each of the friends should not exceed h. If the height of
some person is greater than h he can bend down and then he surely won't be noticed by the guard.
The height of the ith person is equal to
Consider the width of the person walking as usual to be equal to 1, while the width of the bent
person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a
single row. What is the minimum width of the road, such that friends can walk in a row and remain
unattended by the guard?
Constraints:
1≤n≤ 1000
1≤h≤ 1000
Input Format:
The first line of the input contains two integers n and h — the number of friends and the height of
the fence, respectively.
The second line contains n integers a;, the ith of them is equal to the height of the i-th person.
Output Format:
Print a single integer - the minimum possible valid width of the road.
Code:
import java.util.*;
int n,m;
n=sc.nextInt();
m=sc.nextInt();
int w=0;
for(int i=0;i<n;i++){
if(m>=sc.nextInt())w++;
else w+=2;
System.out.println(w);
} }
59. Question description
Let's consider a table consisting of n rows and n columns. The cell located at the intersection of ith
row and ith column contains number ixj. The rows and columns are numbered starting from 1.
You are given a positive integer x. Your task is to count the number of cells in a table that contain
number x.
Constraints:
1≤n≤ 105
1≤x≤ 109
Input Format:
The single line contains numbers n and x we are looking for in the table. -the size of the table and
the number that
Output Format:
Code:
import java.util.*;
int n,x;
n=sc.nextInt();
x=sc.nextInt();
int c=0;
System.out.println(c); } }
60. Question description
Joyner is in love with lovely numbers! A positive integer x is called lovely if and only if there is no
such positive integer a> 1 such that a² is a divisor of x.
Malek has a number store! In his store, he has only divisors of positive integer n (and he has all of
them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this
number to be as big as possible.
Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely
number in his store.
Constraints:
1≤ns 1012
Input Format:
Output Format:
Code:
import java.util.*;
long n=sc.nextLong();
for(long i=2;i*i<=n;i++){
while(n%(i*i)==0){
n=n/i;
} }
System.out.println(n);
} }
61. Question description
Constraints:
1≤ns 1014
Input Format:
The only line contains integer n - the position of the number to find.
Output Format:
Print the element in the n-th position of the sequence (the elements are numerated from one).
Code:
import java.util.*;
long n = sc.nextLong();
long x = (long)Math.sqrt(2*n);
res=res%x==0?x:res%x;
System.out.println(res);
} }
62. Question description
After finishing eating her bun, Amanda came up with two integers n and m. She decided to write
down two columns of integers — the first column containing integers from 1 to n and the second
containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can
choose, one from the first column and the other from the second column, such that their sum is
divisible by 5.
Formally, Amanda wants to count the number of pairs of integers (x, y) such that 1≤x≤ n, lsysm and
(x + y) mod 5 equals 0.
Constraints:
1 ≤ n, m≤ 1 000 000
Input Format:
Output Format:
Print the only integer - the number of pairs of integers (x, y) such that 1≤x≤ n, l≤y≤ m and (x + y) is
divisible by 5.
Code:
import java.util.*;
int n,m;
n = sc.nextInt(); m = sc.nextInt();
long ans=0;
for(int i=1;i<=n;i++){
ans+=m/5;
if(m%5>=5-(i%5))ans++; }
System.out.println(ans); } }
63. Question description
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working
on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that
everything happens on a straight line, the presses are initially at coordinates O and L, and they move
towards each other with speed v₁ and v2, respectively. Luke has width d and is able to choose any
position between the presses. Luke dies as soon as the distance between the presses is less than his
width. Your task is to determine for how long Luke can stay alive.
Constraints:
d<L
Input Format:
The first line of the input contains four integers d, L, v₁, ½ — Luke's width, the initial position of the
second press and the speed of the first and second presses, respectively.
Output Format:
Print a single real value - the maximum period of time Luke can stay alive for.
Code:
import java.util.Scanner;
long d,L,v1,v2;
d=sc.nextLong();
L=sc.nextLong();
v1=sc.nextLong();
v2=sc.nextLong();
System.out.println(String.format("%.4f",(double)(L-d)/(v1+v2))); } }
64. Question description
A soldier wants to buy w apples in the shop. He has to pay k dollars for the first apple, 2k dollars for
the second one and so on (in other words, he has to pay i-k dollars for the ith apple).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w apples?
Constraints:
1 ≤ k, w ≤ 1000
0≤n≤ 10⁹
Input Format:
The first line contains three positive integers k, n, w , the cost of the first apple, initial number of
dollars the soldier has and number of apples he wants.
Output Format:
Output one integer - the amount of dollars that the soldier must borrow from his friend. If he
doesn't have to borrow money, output 0.
Code:
import java.util.Scanner;
int k,w,n,a,x=0;
k=sc.nextInt();
n=sc.nextInt();
w=sc.nextInt();
w=w*(w+1)/2;
a=k*w-n;
if(a<=0)
a=0; System.out.println(a); } }
65. Question description
Vincent owns a grocery store and suddenly the billing machine malfunctioned.
He has to do the billing manually now and urgently needs a basic calculator
Can you help him by writing a code for a simple calculator which performs arithmetic operations like
subtraction, addition, multiplication, division.
Constraints
1sx,y≤1000
Input Format:
Single line input consists of two numbers which are either integer or decimal value, a character input
of arithmetic operation as +,-,*,/ in between both of them (45+24=69)
Output Format:
Code:
import java.util.Scanner;
float x,y;
float result;
char operator;
x = sc.nextFloat();
operator = sc.next().charAt(0);
y = sc.nextFloat();
switch (operator) {
case '+':
result = x+y;
System.out.println(String.format("%.2f",result));
break;
case '-':
result = x-y;
System.out.println(String.format("%.2f",result));
break;
case '*':
result = x*y;
System.out.println(String.format("%.2f",result));
break;
case '/':
result = x/y;
System.out.println(String.format("%.2f",result));
break;
default:
System.out.println("Invalid operator!");
break;
}
66. Question Description:
Brian has a riddle for you and if you manage to solve it, he will give you a cheese burger for free.
You are given an integer n. You need to find two integers I and r such that l+ (l+1)+...+(r-1)+r=n.
Constraints
1st≤104
1≤n≤1018
-1018<l<r<1018
Input Format:
The first line contains a single integer t the number of test cases.
The first and only line of each test case contains a single integer n
Output Format:
For each test case, print the two integers I and r such that l+(l+1)+...+ (r-1)+r=n.
Code:
import java.util.Scanner;
long a,n;
n = s.nextInt();
for(int i=0;i<n;i++) {
a = s.nextLong();
System.out.println(-(a-1)+" "+a);
} } }
67. Question description:
Attendance is very important for any student to take a semester exam. Bruce is the class monitor
and he has been assigned the task to make a program that can display the status. Given the number
of classes attended (NA) and a total number of classes conducted (NC). Let P be the percentage of
attendance. Its status needs to be printed as below.
75≤P≤79 = Average
P≤75 = Danger
Constraints:
1≤T≤100
1≤NA≤1000
1≤NC≤1000
Input Format:
space.
Output Format:
Code:
import java.util.Scanner;
float a,c,ans=0;
int t = input.nextInt();
while(t-->0)
a = input.nextFloat();
c = input.nextFloat();
ans = (a/c)*100;
if(ans>=90 && ans<=100){
System.out.println("Very Good");
}
else if(ans<=75){
System.out.println("Danger");
}
68. Question description
Marc has been given n numbers, he can perform the following operation any number of times:
• Choose any subset of the numbers (possibly empty), none of which are 0.
• Decrement the numbers in the subset by 1, and increment the numbers not in the subset by K.
Constraints:
2≤n≤100
1≤K≤10
0≤Ai≤1000
Input Format:
Output Format:
Code:
import java.util.*;
int n,a,k=1000,j,ans=0,x;
n = input.nextInt();
a = input.nextInt();
for(j=0;j<k+1;j++)res[j]=0;
for(j=0;j<n;j++){
b[j]=input.nextInt();
x=(b[j]%(a+1));
res[x]++;
if(res[x]>n-2)
ans=1;
}
if(ans>0)
System.out.println("YES");
else
System.out.println("NO");
}
69. Question description
A King is planning to attack one of its neighbouring Kingdom. The Kingdom that he is going to attack
is undefeated till date. So he went to his priest and asked for his help. The priest told him that the
only chance he can win the battle is by creating an army that only contain the soldiers having id
numbers which are multiple of 7 as 7 is the lucky number for King and his army. As this priest is
widely known for his wisdom King chooses to act upon his advice. He calls his army to the ground
and ask Cyril to calculate the total number soldiers that can be selected for the battle. Cyril wants
you to help him with this.
Constraints:
1≤N≤1000
1<A[i]≤10^5
Input Format:
First line contains an integer n, representing the number of soldiers present on the ground. Second
line contains n integers A1,A2,A3............n that are space separated representing the id number of
each soldier.
Output Format:
Output will be an integer giving the total number of soldiers that can go for battle.
Code:
import java.util.Scanner;
int a,count=0;
a = sc.nextInt();
for(int j=0;j<a;j++){
arr[j]= sc.nextInt();
if(arr[j]%7==0){
count++;
System.out.println(count);
}
70. Question description
One of my friend Aidan loves coins and he is playing with them but unable to do one problem. The
problem is that you have N coins, not all of different denominations and you have to put the coins of
same denomination on top of each other to form pile of different lengths. You have to print the
denomination and number of coins in the pile which have maximum number of coins. If 2 or more
such denominations are possible then print the denomination having the smallest denomination
Constraints:
1≤N≤100000
Input Format:
The first line of the input contains an integer N denoting the number of coins.
Output Format:
Print the two numbers as asked in the problem. Print First number on first line and second on
second line.
Code:
import java.util.Scanner;
int max=0,element_having_max_freq = 0;
int n = sc.nextInt();
int t = n;
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
int count = 0;
for(int j=0;j<t;j++) {
if (a[i] == a[j]) {
count++;
}
if(count>max) {
max = count;
element_having_max_freq = a[i];
} }
System.out.println(element_having_max_freq);
System.out.println(max);
}
71. Question description
classmate as challenge
There is a platform with n columns. 1x1 squares are appearing one after another in some columns
on this platform. If there are no squares in the column, a square will occupy the bottom row.
Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You
will receive 1 point for this, and all the squares left will fall down one row.
His task is to calculate the amount of points you will receive. Can you help him out?
Constraints:
1≤n,m≤1000
Input Format:
The first line of input contain 2 integer numbers n and m - the length of the platform and the
number of the squares.
The next line contain m integer numbers c1, c2,...,cm -column in which i-th square will appear.
Output Format:
Code:
import java.util.*;
int numofcolumns,numofsquares;
numofcolumns = sc.nextInt();
numofsquares = sc.nextInt();
for(int i=0;i<numofsquares;i++) {
columns[sc.nextInt()-1]++;
Arrays.sort(columns);
System.out.println(columns[0]);
}
72. Question description
Derek and Gavin are busy during the summer, working together to build some ML Models. However,
they got stuck in a very complicated problem and are trying to figure out the method. Derek has got
two arrays (Lets suppose, we denote them as A and B) of length N, containing single digit numbers
only.
Derek needs to combine the i-th element of array -A and B and find the greatest among the two
combinations (two digit number formed by joining the digits).
Help Derek!
Constraints:
1≤N≤10^5
Input Format:
The next two lines contains N space-separated integers (Let's denote it X) - the digits in (
0-9) range
Output Format:
print the newly formed N two digit numbers in a space - separated format
Code:
import java.util.*;
int n = sc.nextInt();
for(int k=0;k<n;k++) {
arr1[k]=sc.nextInt();
for(int k=0;k<n;k++) {
arr2[k]=sc.nextInt();
for(int k=0;k<n;k++){
if(arr1[k]>arr2[k]){
System.out.print(arr1[k]);
System.out.print(arr2[k]+" ");
else if(arr1[k]==arr2[k]){
System.out.print(arr1[k]);
System.out.print(arr2[k]+" ");
else if(arr1[k]<arr2[k]){
System.out.print(arr2[k]);
System.out.print(arr1[k]+" ");
}
73. Question description
Robert and Winston decided to compete in text typing on the site "Keyboard Racing". During the
competition, they have to type a text consisting of s characters. The first participant types one
character in v milliseconds and has ping & milliseconds. The second participant types one character
in v2 milliseconds and has ping 2 milliseconds.
If connection ping (delay) is † milliseconds, the competition passes for a participant as follows:
1. Exactly after + milliseconds after the start of the competition the participant receives the text to
be entered.
3. Exactly + milliseconds after he ends typing all the text, the site receives
The winner is the participant whose information on the success comes earlier. If the information
comes from both participants at the same time, it is considered that there is
a draw.
Given the length of the text and the information about participants, determine the result
of the game.
Constraints:
Input Format:
The first line contains five integers s, V1, V2, †, 2. the number of characters in the text, the time of
typing one character for the first participant, the time of typing one character for the the second
participant, the ping of the first participant and the ping of the second participant.
Output Format:
If the Robert wins, print "Robert". If the Winston participant wins, print "Winston". In case of a draw
print "Friendship".
Code:
import java.util.*;
class KeyboardRace{
int numofchar,time1,time2,ping1,ping2;
participant.time1= sc.nextInt();
participant.time2= sc.nextInt();
participant.ping1= sc.nextInt();
participant.ping2= sc.nextInt();
if((participant.time1*participant.numofchar)+participant.ping1+participant.ping1<(participant.time2
*participant.numofchar)+participant.ping2+participant.ping2)
System.out.print("Robert");
System.out.print("Winston");
else
System.out.print("Friendship");
}
74. Question description
On vacations n pupils decided to go on excursion and gather all together. They need to overcome
the path with the length /meters. Each of the pupils will go with the speed equal to vi. To get to the
excursion quickly, it was decided to rent a bus, which has seats for k people (it means that it can't fit
more than k people at the same time) and the speed equal to v½. In order to avoid seasick, each of
the pupils want to get into the bus no more than
once.
Determine the minimum time required for all n pupils to reach the place of excursion. Consider that
the embarkation and disembarkation of passengers, as well as the reversal of the bus, take place
immediately and this time can
be neglected.
Constraints:
1 ≤ n ≤ 10000
15/109
Input Format:
The first line of the input contains five positive integers n, I, vi, v₂ and k- the number of pupils, the
distance from meeting to the place of excursion, the speed of each pupil, the speed of bus and the
number of seats in the bus.
Output Format:
Print the real number - the minimum time in which all pupils can reach the place of excursion.
Code:
import java.util.*;
class Excursion{
long n,k;
class Speed{
double l,v1,v2;
obj.n= sc.nextLong();
obj1.l= sc.nextDouble();;
obj1.v1= sc.nextDouble();
obj1.v2= sc.nextDouble();
obj.k= sc.nextLong();
double m=(obj.n-1)/obj.k+1;
double v=obj1.v1+obj1.v2;
double x=obj1.l*v*obj1.v2/(m*v*obj1.v2-(m-1)*(obj1.v2-obj1.v1)*obj1.v2);
System.out.println(String.format("%.4f",(float)x/obj1.v2+(obj1.l-x)/obj1.v1));
}
75. Question description
Henry once received a gift: it was a book about aliens, which he started read immediately. This book
had c pages.
At first day Henry read vo pages, but after that he started to speed up. Every day, starting from the
second, he read a pages more than on the previous day (at first day he read vo pages, at second —
vo+ a pages, at third — vo+2a pages, and so on). But Henry is just a human, so he physically wasn't
able to read more than vi pages per day.
Also, to refresh his memory, every day, starting from the second, Henry had to reread last /pages he
read on the previous day. Henry finished the book when he read the last page for the first time.
Help Henry to calculate how many days he needed to finish the book.
Constraints:
1≤c≤ 1000
0≤/<v≤ 1000
O≤ a≤ 1000
Input Format:
First and only line contains five space-separated integers: c, vo, VI, a and /- the length of the book in
pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and
the number of pages for rereading.
Output Format:
Print one integer - the number of days Henry needed to finish the book.
Code:
import java.util.*;
class ReadingBooks{
int length,speed,maxspeed,acc,reread;
int ans=1,cur=book.speed,k=1,vel=book.speed;
while(cur<book.length){
ans++;
vel=Math.min(book.maxspeed,vel+book.acc);
cur+=(vel-book.reread);
k++;
}
System.out.println(ans);
}
76. Question description
To make a paper boat, one has to use a rectangular piece of paper. From a sheet of standard size
you can make s boats.
A group of k people decided to make n boats each. They are going to buy several packs of paper,
each of them containing p sheets, and then distribute the sheets between the people. Each person
should have enough sheets to make n boats. How many packs should they buy?
Constraints:
1≤k,n,s,p≤109
Input Format:
The only line contains four integers k, n, s, p- the number of people, the number of boats each
should make, the number of boats that can be made using one sheet and the number of sheets in
one pack, respectively.
Output Format:
Print a single integer - the minimum number of packs they should buy.
Code:
import java.util.Scanner;
class PaperBoat{
int k,n,s,p; }
System.out.println((int)Math.ceil((fun.k*perPerson)/(double)fun.p)); } }
77. Question description
During the winter holidays, the demand for Christmas balls is exceptionally high. The advances in
alchemy allow easy and efficient ball creation by utilizing magic crystals.
Hailey needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball
one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue
crystals are enough.
Right now there are A yellow and B blue crystals in Hailey's disposal. Find out how many additional
crystals he should acquire in order to produce the required number of balls.
Constraints:
O≤ A, B≤ 109
O≤ x, y, z≤ 109
Input Format:
The first line features two integers A and B, denoting the number of yellow and blue crystals
respectively at Hailey's disposal.
The next line contains three integers x, y and z- the respective amounts of yellow, green and blue
balls to be obtained.
Output Format:
Print a single integer - the minimum number of crystals that Hailey should acquire in addition.
Code:
import java.util.Scanner;
class ChristmasBalls{
long A,B,x,y,z;
happy.A= sc.nextLong();
happy.B= sc.nextLong();
happy.x= sc.nextLong();
happy.y= sc.nextLong();
happy.z= sc.nextLong();
long ans=0;
if(2*happy.x+happy.y>happy.A) {
ans+=((2*happy.x)+happy.y)-happy.A;
if(3*happy.z+happy.y>happy.B) {
ans+=((3*happy.z+happy.y)-happy.B);
System.out.println(ans);
}
78. Problem Description:
He has a m x n units of floor area and want to cover it up with 2x1 size tiles.
Could you help him to find out the minimum number tiles he needs to cover the floor?
Constraints:
1 ≤ m,n ≤ 500
Input Format:
Output Format:
Print the minimum number of tiles need to pave the floor as output.
Code:
import java.util.Scanner;
int m = input.nextInt();
int n = input.nextInt();
float m1 = (float)m;
float n1 = (float)n;
System.out.println(String.format("%.0f",(m1*n1/2)));}}
79. Problem Description:
Tina successfully completed her first Month as Navy Officer and her much awaited first month salary
got credited into her account and also go her salary report in her mail.
On seeing the salary report there is no information available about the Employee provident fund. So
Tina would like to know about the Employee and Employer Contribution for EPF. Can you help her?
Constraints:
Input Format:
The only line of input has a single floating point value representing the basic salary of
Tina.
Output Format:
In the First Line of output print the Employee Share of EPF with only two values after decimal point.
In the Second Line of output print the Employer Share of EPF with only two values after decimal
point.
Code:
import java.util.Scanner;
double employeeFund,employerFund;
Aarav and Nathan who live in the fictional town of Pune, think and do innovatively on weekends.
Every day the boys embark on some grand new project, which annoys their controlling sister
Thendral, who tries to bust them.
One Sunday they were both sitting under a tree in their back yard. They decide to invent the
machine which would allow us to enter 2 numbers it would say whether one of the entered numbers
is an appropriate value of the other number entered.
They decide to insert a program code into the machine. A number is said to be an approximate value
of the other if they differ by utmost 0.5.
Can you help Aarav and Nathan with the programming logic to find whether the given number is an
approximate number of other?
Constraints:
0≤A≤1000
0<B≤1000
Input Format:
The only line of input has two numbers of type float separated by a space representing A and B
respectively.
Output Format:
In the only line of output print as "Approximate number" or "Not an Approximate number" based on
the condition.
Code:
import java.util.Scanner;
Zaheer and Vinod went to California for attending the Apple products launch event.
In the event location there are lot of mini contests going on with exciting rewards.
In one such stall there was a contest were they have given a floating point number and asked the
visitors to display the rightmost digit integral part of the number using a programming logic.
Can you help Zaheer and Vinod to display the rightmost integral part of the number so that they get
the exciting apple products as reward?
Constraints:
Input Format:
Only line of input has a single floating point value with three values after decimal point.
Output Format:
Print the output in a single line rightmost integral part of the number.
Code:
import java.util.Scanner;
System.out.println((int)appleno%10); }
}
82. Problem Description:
better.
Sathya usually gives interesting problems to the youngsters to make them love the math.
One such day Sathya provided the youngsters the base number and exponent and asked the power
of that given number.
Constraints:
Input Format:
Output Format:
Code:
import java.util.Scanner;
System.out.println(String.format("%.2f",Math.pow(base, exp))); } }
83. Problem Description:
Arav was a popular maths trainer, he gave a 4 digit number to his students as an assignment.
But students are confused with the logic for doing so.
Constraint:
Input Format:
Output Format:
Explanation:
Let us say Aarav given a number "7821" then the number at one place is "1"
Code:
import java.util.Scanner;
System.out.println(num%10); } }
84. Problem Description:
Nancy is a data scientist. She regularly faces about Terra bytes of data in her work.
One day she was working on an application that collects users address and stores it
Nancy now has the burden of arranging the users data into their respective field can you
help her?
Constraint:
Input Format:
Output Format:
Code:
import java.util.Scanner;
System.out.println("EmployeeID : "+employeeID);
}
85. Problem Description:
Binita always dreamed of flying in the sky from her childhood. Her goal was to become a pilot. When
she applied for the pilot training program she cleared the entrance exam but failed the physical test
due to overweight. She forget to take care of her health during the preparation.But she had the
spirit of not giving up.Binita joined a gym to pass the physical test next time. Her gym trainer asked
her to calculate BMI for giving her a proper diet plan, But she had other works to do can you help
this motivated girl?
Functional Description:
Constraints:
Input Format:
Output Format:
Print the BMI with only two values after decimal points.
Code:
import java.util.Scanner;
System.out.println(String.format("%.2f",weight/(height*height))); } }
86. Problem Description:
Shiva is part of budget estimation team so he would like to calculate the Area of that apartment.
Constraints:
Input Format:
Only Line of input has three floating point values representing basel base 2 and height separated by
a space
Output Format:
Print the area of the apartment in a single line with two values after decimal point.
Code:
import java.util.Scanner;
System.out.println(String.format("%.2f",(base1+base2)*height/2)); } }
87. Problem Description
Nedumaran Rajangam is an visionary in Aviation industry. His wife Bommi runs a bakery where she
sells loaves of bread for 185 rupees each.
Bommi noted the number of loaves of day old bread being purchased from the customer.
Bommi likes to know the following details regarding the sales in her bakery:
The amount that will be discounted for customers if discount of 60% is applied to the regular income
Constraints:
BreadPrice = 185
Input format:
Only line of input has a single integer representing the number of the loaves of the bread
Output format:
Second Line: Print the Amount Discounted if 60% discount is applied with 2 values after decimal
point.
Third Line: Print the amount to be paid after discount with 2 values after decimal point.
Code:
import java.util.Scanner;
System.out.println("Regular Price="+regular);
}
}
88. Question description
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to
an original toy, he additionally gets one more original toy and one copy, and if he applies the
machine to a copied toy, he gets two additional copies.
Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get
exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine
to a copy if he doesn't currently have any copies.
Constraints:
Osx, y≤ 109
Input Format:
The only line contains two integers x and y — the number of copies and the number of original toys
Imp wants to get (including the initial one).
Output Format:
Code:
import java.util.*;
int b,h;
b=sc.nextInt();
h=sc.nextInt();
System.out.println("No");
else
System.out.println("Yes");
sc.close();
}
89. Question description
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day
he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are
simple. Sasha draws n sticks in a row. After that the players take turns crossing out exactly k sticks
from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are
less than k sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly
more moves than Lena. Sasha wants to know the result of the game before playing, you are to help
him.
Constraints:
1≤n, k≤ 1018
k≤n
Input Format:
The first line contains two integers n and k - the number of sticks drawn by Sasha and the number k -
the number of sticks to be crossed out on each turn.
Output Format:
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
Code:
import java.util.*;
long n,k;
n=sc.nextLong(); k=sc.nextLong();
String c = n/k%2==1?"YES":"NO";
System.out.println(c); } }
90. Question description
Recently Shankar learned about a special kind of numbers that she calls beautiful numbers. The
number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k
consecutive zeroes.
12 (110);
1102 (610);
• 11110002 (12010);
• 1111100002 (49610).
More formally, the number is beautiful iff there exists some positive integer k such that the number
is equal to (2-1)* (2k-1).
Shankar has got an integer number n, and she wants to find its greatest beautiful divisor. Help her
to find it!
Constraints:
1≤ns 105
Input Format:
The only line of input contains one number n - number Shankar has got.
the
Output Format:
Output one number - the greatest beautiful divisor of Shankar's number. It is obvious that the
answer always exists.
Code:
import java.util.Scanner;
int n,r=0;
n = input.nextInt();
for(int k=1;k<10;k++){
if(n%x==0){
r=x;
}
System.out.println(r);
}
91. Question description
It seems that Dana is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of
the doctors needs the information about all previous visits, so Dana has to visit them in the
prescribed order (i.e. Dana should first visit doctor 1, then doctor 2, then doctor 3 and so on). Dana
will get the information about his health from the last doctor.
Doctors have a strange working schedule. The doctor i goes to work on the syth day and works every
d; day. So, he works on days si, si+ dj, s;+2d;, ....
The doctor's appointment takes quite a long time, so Dana can not see more than one doctor per
day. What is the minimum time he needs to visit all doctors?
Constraints:
1≤n≤ 1000
Input Format:
Output Format:
Output a single integer — the minimum day at which - Dana can visit the last doctor.
Code:
import java.util.Scanner;
int nDoctors;
int nDay=0;
nDoctors = sc.nextInt();
nDay = startWork;
System.out.println(nDay);
}
}
92. Question description
After a probationary period in the game development company of IT City Tony was included in a
group of the programmers that develops a new turn-based strategy game resembling the well
known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of
enemies on infinite fields where every cell is in form of a hexagon.
Some of magic effects are able to affect several field cells at once, cells that are situated not farther
than n cells away from the cell in which the effect was applied. The distance between cells is the
minimum number of cell border crosses on a path from one cell to another.
It is easy to see that the number of cells affected by a magic effect grows rapidly when n increases,
so it can adversely affect the game performance. That's why Tony decided to write a program that
can, given n, determine the number of cells that should be repainted after effect application, so that
game designers can balance scale of the effects and the game performance. Help him to do it. Find
the number of hexagons situated not farther than n cells away from a given cell.
Constraints:
0≤n≤ 109
Input Format:
The only line of the input contains one integer n.
Output Format:
Output one integer - the number of hexagons situated not farther than n cells away from a given
cell.
Code:
import java.util.*;
long n=sc.nextLong();
System.out.println(1+(3*n*n)+(3*n));
}
93. Question description
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take
his place at a desk! In the classroom there are n lanes of m desks each, and there are two working
places at each of the desks. The lanes are numbered from 1 to n from the left to the right, the desks
in a lane are numbered from 1 to m starting from the blackboard. Note that the lanes go
perpendicularly to the blackboard, not along it (see picture).
The organizers numbered all the working places from 1 to 2nm. The places are numbered by lanes (i.
e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane
the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the
lane), at each desk, the place on the left is numbered before the place on the right.
Santa Clause knows that his place has number k. Help him to determine at which lane at which desk
he should sit, and whether his place is on the left or on the right!
Constraints:
1 ≤ n, m≤ 10000
1≤k≤2nm
Input Format:
The only line contains three integers n, m and k- the number of lanes, the number of desks in each
lane and the number of Santa Claus' place.
Output Format:
Print two integers: the number of laner, the number of desk d, and a characters, which stands for
the side of the desk Santa Claus. The character s should be "L", if Santa Clause should sit on the left,
and "R" if his place is on the right.
Code:
import java.util.Scanner;
int p,l,d;
n = sc.nextInt();
m = sc.nextInt();
k = sc.nextInt();
p = (int)Math.floor((k-1)/2);
l = (int)Math.floor(p/m)+1;
d = (p%m)+1;
sc.close();
}
94. Question description
Aaron and Eric have played several table tennis sets. Each set consists of several serves, each serve is
won by one of the players, he receives one point and the loser receives nothing. Once one of the
players scores exactly k points, the score is reset and a new set begins.
Across all the sets Aaron scored a points in total, and Eric scored b points. Given this information,
determine the maximum number of sets they could have played, or that the situation is impossible.
Constraints:
1 ≤k≤ 109
O<a, b<10⁹
a+b>0
Input Format:
Output Format:
If the situation is impossible, print a single number "Impossible". Otherwise, print the maximum
possible number of sets.
Code:
import java.util.*;
int k,a,b;
k = sc.nextInt();
a = sc.nextInt();
b = sc.nextInt();
if(a%k!=0&&k>=b||b<k) System.out.println("Impossible");
else{
System.out.println(ans);
}
}
95. Question description
You are asked to watch your nephew who likes to play with toy blocks in a strange way. He has n
boxes and the ith box has ai blocks. His game consists of two steps:
2. he tries to move all blocks from the i-th box to other boxes.
If he can make the same number of blocks in each of n-1 other boxes then he will be happy,
otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the
other boxes; he cannot move blocks from the other boxes.
You don't want to make your nephew sad, so you decided to put several extra blocks into some
boxes in such a way that no matter which box i he chooses he won't be sad. What is the minimum
number of extra blocks you need to put?
Constraint:
1st≤1000
2≤n≤105
Osai≤109
Input Format:
The first line of each test case contains the integer n- the number of boxes.
The second line of each test case contains n integers al,a2,...,an - the number of blocks in each box.
It's guaranteed that the sum of n over test cases doesn't exceed 105.
Output Format:
For each test case, print a single integer - the minimum number of blocks you need to put. It can be
proved that the answer always exists, i. e. the number of blocks is finite.
Code:
import java.util.*;
long s,m,now;
int n = sc.nextInt();
s = 0;
m = 0;
s+=arr[i];
m = Math.max(arr[i],m);
System.out.println(now-s);
}
96. Question description
Your favorite grocery store sells n Zinder Surprise chocolate eggs. You know that exactly s stickers
and exactly t toys are placed in n eggs in total.
⚫ it can contain a single sticker and no toy; ⚫ it can contain a single toy and no sticker;
But you don't know which type a particular Zinder Surprise has. All eggs look identical and
indistinguishable from each other.
What is the minimum number of Zinder Surprise Eggs you have to buy to be sure that, whichever
types they are, you'll obtain at least one sticker and at least one toy?
Note that you do not open the eggs in the purchasing process, that is, you just buy some number of
eggs.
Constraints:
1≤n≤10^9
1ss,tsn
s+t2n
Input Format:
Single line contain three integers n, s and teach - the number of eggs, stickers and toys.
Output Format:
Print the minimum number of Zinder Surprise Eggs you have to buy to be sure that, whichever types
they are, you'll obtain at least one sticker and one toy
Code:
import java.util.Scanner;
int x,y,z;
int c;
x = sc.nextInt();
y = sc.nextInt();
z = sc.nextInt();
if (y <= z)
c = (x - y) + 1;
else
c = (x - z) + 1;
System.out.println(c);
}
97. Question description
B Rabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from
the point (x1,y1) to the point (x2,y2).
He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit
away from the box in the direction of one of two coordinate axes. He will pull the box to where he is
standing before moving out of the way in the same direction by 1 unit.
For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the
box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).
Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is
not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he
must return to a point next to the box. Also, Wabbit can't move to the point where the box is
located.
Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of
whether he pulls the box while moving.
Determine the minimum amount of time he needs to move the box from (x1,y1) to (x2,y2). Note
that the point where Wabbit ends up at does not matter.
Constraints:
1sts1000
1sx1,y1,x2,y2≤10^9
Input Format:
Single line contains four space-separated integers x1,y1,x2,y2, describing the next test case.
Output Format:
Print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x1,y1) to
(x2,y2).
Code:
import java.util.*;
int x,y,x2,y2;
x=sc.nextInt();
y=sc.nextInt();
x2=sc.nextInt();
y2=sc.nextInt();
if(x==x2 || y==y2)
System.out.println(Math.abs(x-x2)+Math.abs(y-y2));
else
System.out.println(Math.abs(x-x2)+Math.abs(y-y2)+2);
}
98. Question description
Given three integers li, ri and di, find minimum positive integer xi such that it is divisible by di and it
does not belong to the segment [li,ri].
Can you answer all the queries and help her out?
Constraints:
1≤q≤500
1slisris 109
1<di≤109
Input Format:
Then q lines follow, each containing a query given in the format li ri di which are integers.
Output Format:
For each query print one integer: the answer to this query.
Code:
import java.util.*;
int l,r,d;
int t = s.nextInt();
while(t>0) {
l = s.nextInt();
r = s.nextInt();
d = s.nextInt();
if(d<l)
System.out.println(d);
else
System.out.println((r/d)*d+d);
t--;
}
}
99. Question description
Alexis and Fred play the classic game of odds and evens. In this game, each of the two players
choose a number between 1 and 5 without revealing to their opponent. Both of the players then
simultaneously reveal their number by holding up that many fingers of their hand. Then the winner
is decided based upon whether the sum of numbers played by both the players is odd or even. In
this game we assume that if the sum is odd then Alexis wins, otherwise Fred wins.
If Alexis held up a fingers and Fred held up b fingers, determine who won the game?
Constraints:
1≤T≤1000
1sa,b≤5
Input Format:
• First line will contain T, number of testcases. Then the T testcases follow.
• Each testcase contains of a single line of input, two integers a,b which denote the number played
by Alexis and Fred respectively.
Output Format:
Code:
import java.util.*;
int a,b,d;
int t= sc.nextInt();
while(t-->0)
a= sc.nextInt();
b= sc.nextInt();
d=(a+b)%2;
if(d==0)
System.out.println("Fred");
else
{
System.out.println("Alexis");
}
100. Question description
Finally, University has started calling students back to campus. There are so many students and thus
due to some safety measures the University can't call back all the students on the same day. It
currently has the capacity of screening K students on a single day. There is a total of N students.
What's the minimum number of days required for all the students to be back on the campus?
Constraints:
1≤N,K≤100
Input Format:
The first and only line of each test case contains two space-separated integers N,K.
Output Format:
Print a single line containing one integer - the minimum number of days required for all the students
to be back on the campus.
Code:
import java.util.Scanner;
int N = input.nextInt();
int K = input.nextInt();
if(N%K==0)
System.out.println("1");
else if(N%K!=0){
System.out.println(Math.round(N/K)+1); } } }