You are on page 1of 30

Mock1

The Two Numbers


Ram and Mohan are two brothers. They are not good in Maths. So their father decided to give some
assignment as a game so that they can enjoy as well as they can learn the concept of number
systems. So he gave two numbers to them. One is the sum of two number, x and y, and another is
the product of same two numbers. Help them to write a code to find x and y.
Note:
The two numbers should be printed in ascending order.
Input format
The input contains two integers in the same line separated by space that denotes the sum of x and y
and the product of s and y respectively.
Output format
The output consists of two numbers separated by space which corresponds to x and y in ascending
order.
Sample input 1:
56
Sample output 1:
23

Sample input 2:
15 50
Sample output 2:
5 10
Skill testing
Amar’s team is assigned with a project that deals with the digital signals. He is aware that the digital
signals will be represented as arrays. He wants to test his team with respect to their strength in
arrays. As part of the skill testing the task is as follows:
You are given an array of integers of size N.
Consider all its contiguous subarrays of length k and find the maximum sum.
Do this for all k from 1 to the length of the input array.
Write a program to evaluate the task done by the kids.
Input format:
The first line contains a single integer denotes the size of the array N.
The second line contains N-space separated integer that corresponds to the values of the array.
Output format:
The output consists of N-space separated integer that corresponds to the values of the array.
Sample input 1:
5
-1 2 1 3 -2
Sample output 1:
34653

Explanation:
For inputArray=[-1,2,1,3,-2], the output should be [3,2,1,0,0].
The contiguous subarray
Of k=1,each subarray will have 1 element, the sub-array with maximum sum is [3]. So result[0]=3.
Of k=2,each subarray will have 2 elements, the sub-array with maximum sum is [1,3]. So result[1]=4.
Of k=3,each subarray will have 3 elements, the sub-array with maximum sum is [2,1,3]. So
result[2]=6.
Of k=4,each subarray will have 4 elements, the sub-array with maximum sum is [-1,2,1,3]. So
result[4]=5.
Of k=5,each subarray will have 5 elements, the sub-array with maximum sum is [-1,2,1,3,-2]. So
result[5]=3.

Sample input 2:
5
2 3 2 -2 3
Sample output 2:
35768
Anuska’s instruction
Anuska has created a robot that will take instructions and work accordingly. Due to budget problem,
she has set the memory low. To overcome that, she has to encode the instruction. Given the
instruction s, count the consecutive characters and each character will be followed by its frequency.
For example, if the instruction is “aaaabb”, the encoded instruction is “a4b2”.
Note:
If the frequency is one, the count need not be printed.
Input format:
The first input is a string that denotes the instruction, s.
Output format:
Output is a string that denotes the encoded string.
Sample input 1:
aaaabb
Sample output 1:
a4b2

sample input 2:
sggvvvgss
sample output 2:
sg2v3gs2
Team Assessment
The Team Leader of Testing team of XYZ company decided to assess the team members by
organising a programming event. So he gave the team a task.
The task is given an array of size , find the number of distinct elements in the array and print them in
ascending order. Those members who answer, will get some reward.
Write a program to help the Team Leader to evaluate the solution of the team members.
Input format:
The first line contains s single integer that denotes the size of the array, N.
The second line contains N space separated integer values of the array.
Output format:
The first line is an integer that denotes the number of the distinct elements in the array.
The second line is a series of integers separated by space that denotes the distinct elements
Sample input 1:
5
12121
Sample output 1:
2
12
Sample input 2:
5
145 25 21 25 36
Sample output 2:
4
21 25 36 145
Summer Vacation Game
In summer vacation time, the students of ABC school went for a team outing. A game was conducted
by the Incharge for the student so that they can enjoy. So he told them to take one integer N and
arrange the digits of the integer in incremental order from right to left. Help students by writing a
code.
Input format:
The first line contains s single integer that denotes the given number, N.
Output format:
The output is an integer in which the digits of N are arranged in incremental order from right to left.
Sample input 1:
231
Sample output 1:
321
Picnic Event
As part of the picnic events, the families from ABC apartment plan to organize same games for their
kids so that they can learn something during leisure time also. The task is as follows:
Given a string S, find the string which has only the distinct character in S. the characters should be
presented in the descending order of its occurrence. If the occurrence count of two characters is
same, then the order for those two characters should be the same as its is in the input string.
Input Format:
The input is a string that denotes the S.
Note:
The String is case-sensitive.
Output format:
The output is a string that denotes the modified string.
Sample input 1:
HelloWorld
Sample output 1:
loHeWrd

sample input 2:
Entertainment
Sample Output 2:
nteEraim
Mock 2
Practical Exam Preparation
Vel is a first year computer science student. The next day he is having his practical’s lab exam. His
sister (Priya) is working in atop IT firm. To test vel, she gives him a problem to solve. The problem is
to find the N-th special number, given he value of N. she also defines a number to be special, if it’s
units place digit only consist of 0,1,2,3,4 or 5.
Write a program to help vel.
Input format:
First input is an integer that denotes the N value.
Output format:
Output is an integer that denotes the N-th special number.
Sample input 1:
5
Sample output 1
4
Explanation:
Here N=5
The first 5 special numbers are 0,1,2,3 and 4. So the output is 4.

Sample input 2:
60
Sample output 2:
95
Explanation:
Here N=60.
The first 60 special numbers are as follows:
0,1,2,3,4,5,10,11,12,13,14,15,20,21,22,23,24,25,30,31,32,33,34,35,40,41,42,43,44,45,50,51,52,53,54
,55,60,61,62,63,64,65,70,71,72,73,74,75,80,81,82,83,84,85,90,91,92,93,94 and 95
So the output is 95.
Sai’s Programming Skills
Sai is doing his 5th grade in VIBGYOR International School. He has already started to do programming.
Priya, being a programming geeks, tests her son’s knowledge by asking him to code for her
requirement. The requirement is as follows:
Given two arrays A and B each containing N numbers, choose exactly one number from A and
exactly one number from B such that the index of the two chosen numbers is not same and the sum
of the 2 chosen values is minimum. Formally, if you choose ith element from A whose value is x and
jth element from B whose value is y, you need to minimize the value of (x+y) such that i is not equal
to j.
Help Sai in writing the program.
Input format:
First line of the input is an integer that denotes the N value, size of the array.
Second line of the input is a series of n integers separated by a space that denotes the array values
of A.
Third line of the input is a series of n integers separated by a space that denotes the array values of
B.
Assume:
All the elements in each array are distinct.
Output format:
Output is an integer that denotes the minimum value as per the requirement.
Sample input 1:
5
12345
54321
Sample output 1:
2
Explanation:
Here x is 1 (the first element of A) and y is also 1 the last element of B). their sum is 2.
Sample input 2:
6
2548696
4 5 6 9 8 10
Sample output 2:
7
Explanation
Here x is 2(the first element of A) at index 0 and y is 4 at index 0. Since the index of j is also the same,
we choose the next smallest element which is 5 at index 1.
Bangles gift
Vel bought 2 bangles for his elder sister Priya, as a birthday gift. Before presenting the gift, vel
challenges his sister to answer his question blindfolded. He places both the bangles on the table and
asks priya to answer two questions:
1. Are the two bangles intersecting or touching or not touching?
2. What is the distance between the centers of the bangles?
To answer these questions, Vel gives the centers c1(x1,y1) and c2(x2,y2) and radius r1 and r2 of the
bangles.
Now write a program to help priya to answer her brother’s questions.
Input format:
First line of the input consists of two integers separated by a space which corresponds to x1 and y1
values, respectively.
Second line of the input consists of two integers separated by a space which corresponds to x2 and
y2 values, respectively.
Third line of the input consists of two integers separated by a space which corresponds to r1 and r2
values, respectively.
Output format:
First line of the output is a string, “intersects” or “Touches” or “Do not Touch”.
Second line of the output is a float value which corresponds to the distance between the two centers
of the bangles, rounded off to 2 decimal points.
Sample input 1:
34
14 18
58
Sample output 1:
Do not Touch
17.80
Sample input 2:
34
46
45
Sample output 2:
Intersects
2.24
Choclolate box
Priya returned to India from the onsite trip to Singapore. She bought lots of chocolates for his son sai
and younger brother vel. The chocolate box is square shaped and contains identical compartments.
Each compartment contains several number of chocolates. Now comes the fight between sai and vel
for the chocolates. To stop the fight, priya gives a condition to both of them that, the compartments
in the upper triangular part of the box are for sai and that of the lower triangular part is for vel, and
the compartments in the main diagonal will be shared by priya and her husband.
Now help sai and vel to find how many chocolates did each get, by writing a program.
Note:
In this problem, upper triangle consists of elements above the main diagonal, and the lower triangle
consists of elements below the main diagonal.
Input format:
First input is an integer that denotes the N value, size of the box. The range of n is [1 – 15], both
inclusive.
Next N lines of the input consists of N integers separated by space in each line, that denotes the
number of chocolates in each compartment.
Output format:
Output is two integers separated by a space that denotes the number of chocolates for sai and
number of chocolates for vel respectively.
Note:
If N=1, there is no upper triangle and lower triangle. The single element present corresponds to the
main diagonal.
Sample input 1:
4
1234
8596
1 2 3 15
5716
Sample output 1:
39 24
Reorder the students
Sai is doing his 5th grade in VIBGYOR international school. He is the most intelligent student in his
class, and his class teacher has made him the representative for his class. Now its play time. There
are n students in his class and each student is given a card that has a number written in it. Sai, being
the representative, has to reorder those kids as per the order given to him.
Help sai in reordering the kids, by writing a program.
Input format:
First input is an integer that denotes the n value, the number of students.
Second input is a series of n integers separated by a space that denotes the numbers given to each
student.
Third input is a series of n integers separated by a space that denotes the array which contains the
order in which the students have to be reordered.
Assume:
The elements of the 2nd array are unique and always greater than or equal to 0 and less than n.
Output format:
Output is a series of n integers separated by a space that denotes the reordered array.
Sample input 1:
3
14 15 16
120
Sample output 1:
16 14 15
Explanation:
The first array: 16 14 15
The order array: 1 2 0
Here the first element 16 should be moved to index 1.
The second element 14 should be moved to index 2.
The third element 15 should be moved to index 0.
So, after moving, the final order is 16 14 15
Sample input 2:
5
12345
12034
Sample output 2:
31245
Sliding number
nd
Priya’s son sai is doing his 2 grade. He started learning about number. To test his intelligence, priya
asks him to solve a problem. The problem is to find the number of sliding numbers within a given
range. A number is called sliding number if all adjacent digits have an absolute difference of 1.
For e.g. ‘432’ is a sliding number while 542 is not.
Write a program to help sai to find the number of sliding number in range [m,n](both inclusive)
Input format:
First input is an integer that denotes the m value.
Second input is an integer that denotes the n value.
Assume:
n>M>=10
output format:
output is an integer that denotes the number of sliding numbers.
Sample input 1:
10
25
Sample output 1:
4
Explanation:
Sliding numbers are 10 12 21 23
Sample input 2:
10
16
Sample output 2:
2
Mock 3
Boat travel
You’re travelling in boat, the water currents sometimes they slow you down. You need to calculate
the time to reach. Knowing the boat speed and wate current speed.
A boat moves at a constant speed of x dmph without water flow. the water flow also affects the
speed of the boat.
Given the ideal boat speed and the water flow speed, write a program to find the time required to
reach a given distance.
Input format: :
First LIne of the input contains a single integer value that denotes the ideal boat speed in kmph.
Second Line of the input contains a single integer value that denotes the water flow speed in
kmph(+ve when it favors the boat and -ve when it disfavours.
Third Line of the input contains a single integer value that denotes the distance to be convered in
km.
Output format::
A single integer value that denotes the time taken to reach the given distance.
Assume::
The time taken will always be an integer.
sample input 1::
20
5
100
sample output 1::
4
sample input 2::
25
-5
100

Bigger Number
Suriya loves playing with numbers. He comes up with a new game idea of creating a greater number
than the given number by changing exactly one digit. Now he has to find the number of ways in
which this is possible. Help Suriya to develop a program to find the number of ways to obtain a
bigger number.
input format::
Input contains a single integer that denotes the given number.
output format::
the output contains a single integer that denotes the number of ways.
sample input 1::
10
sample output1 ::
17

sample input 2::


32310
sample output 2::
36
Explanation:
First digit 3 can be changed into 4,5,6,7,8,9 so 6 posiibilities
second dight 2 can be changed into 3,4,5,6,7,8,9 sp 7 possibilities
Third digit 3 can be changed into 4,5,6,7,8,9 so 6 posiibilities
Fourth digit 1 can be changed into 2,3,4,5,6,7,8,9 so 8 posiibilities
Fifth digit 0 can be changed into 1,2,3,4,5,6,7,8,9 so 9 posiibilities
Hence Result=6+7+6+8+9=36
--------------------------------------------------------------------------------------------------------------------------------------
Greatest common prime divisor
Sapna has learnt about prime numbers and Greatest common divisor. Now shw experiments by
finding the greatest prime divisor.
Help her develop a program by combining her knowledge in both the concepts to find the greatest
common prime divisor.
Given two numbers, write a program to find the greatest common prime divisor.
Note:
If there is not such numbers, print -1.
input format:
First Line of the input contains a single integer that denotes the second number.
Second Line of the input contains a single integer that denotes the second number.
Ouptut format:
The output contains a single integer that denotes the gcpd of the two inputs.
sample input 1:
12
18
sample output 1:
3
--------------------------------------------------------------------------------------------------------------------------------------
Exchange positions in array
Nikitha is very interested in programming with arrays, she tries to exchange the positions of the
elements by swapping the elements and the number at the place which it occupies.
For Example,
Consider the array elements.
1342
The element 1 in the given array, is at position 1, so 1 is places at position 1 in output array.
The element 3 in the given array, is at position 2, so 2 is places at position 3 in output array.
The element 4 in the given array, is at position 3, so 3 is places at position 4 in output array.
The element 2 in the given array, is at position 4, so 4 is places at position 2 in output array.
The output array becomes 1,4,2,3

Develop a program to help Nikitha.

Input format::
First Line of the input contains a single integer that denotes the size of the array n.
Second line consists of n space seperated integer array values. The input array values will always be
a permutation of numbers from 1 to n.

output format::
the output consists of n space separated integers that denote the output array values.
sample input 1:
4
1234
Sample output 1:
1423
--------------------------------------------------------------------------------------------------------------------------------------
Diagonal Difference:
Roshan just found out that matrix can be implemented using 2d arrays. He is good in programming.
So he tries to develop a program to do his math homework. Help Roshan to write a program to do
his math homework.
In his math homework, a square matrix of size N is given. He needs to calculate the absolute
difference between the sums of the diagonals.
Help Roshan by writing a program.
Input Format:
The first line contains a single integer denotes the size of the matrix, N.
The next N lines denote the matrix’s rows, with each line containing N space-separated integers
describing the columns.
Output format:
Print the absolute difference between the two sums of the matrix’s diagonals as a a single integer.
sample input 1:
3
11 2 4
456
10 8 -12
Sample Output 1:
15
Explanations:
The primary diagonal elements are:
11 5 -2
Sum across the primary diagonal: 11+5-12=4
--------------------------------------------------------------------------------------------------------------------------------------
Power Pairs:
Your friend challenges you to play a game, in which you have to find the number of Power pairs in
the series of numbers. A Power pair is formed when a number b is divisible by another number a
that occurs before the number b in the given sequence. you can easily win the challenge by
developing a program to find it.
Input format:
first line of the input contains a single integer that denotes the size of the array n.
second line consists of n space separated integers that denote the array values.
output format:
The output consists a single integer that denotes the number of power pairs in the given sequence.
sample input 1:
3
132
sample output 1:
2
Explanation:
for sequence=[1 3 2]
the sorted pairs are:(1,3),(1,2).
so output should be 2.
--------------------------------------------------------------------------------------------------------------------------------------
Main1:
COST FOR SPIRAL BINDING
Your final year project papers has to be spiraled (spiral binding). The cost for spiraling depends on
the thickness of the spiral. If thickness is <= 1 cnm
the cost is Rs.50, if thickness>1cm and <=2cm, the cost is Rs.100. If thickness>2cm and <=3cm, the
cost is Rs.150. For each 1cm increase in spiral thickness, it costs Rs.50 additionally. A total of 2-
sheets will give a thickness of 1mm. Given the number of sheets, write a program to find the cost of
spiral.
Input format:
first line consists of a single integer that denotes the number of sheets to be spiraled.
output format:
output is an integer that denotes the cost for spiralling.
sample input 1:
225
sample output 1:
100
sample input 2:
488
sample output 2:
150
explanation:
for sample input 1→ 225 sheets has to be spiraled. 225 sheets will make around 1.125cm, since it is
less than 2 cm and greater than 1 cm, it costs Rs. 100.
for sample input 2 → 488 sheets has to be spiraled, 488 sheets will make around 2.44cm, since it is
less than 3cm and greater than 2cm, it costs Rs.150.
--------------------------------------------------------------------------------------------------------------------------------------
Free Fall
A boy drops a ball from the top of the building of height h. Write a program to find the velocity at
which it hits the ground.
Formula:
Equations of motion, v2=u2+2gh.
Note:
Assume Air in the atmosphere is not affecting the speed. Take g=9.8m/s2.
input format:
first input is an integer that denotes the height of the building in meteres.
output format:
Output is a double vlaue that denotes the velocity of the ball at which it hits the ground.(Rounded
off to two decimal places)
sample input 1:
45
sample output 1:
29.70
sample input 2:
15
sample output 2:
17.15
Explanation:
For sample input 1 → Height of the building - 45m. From equations of motion formula we can find
the velocity at which the ball will hit the ground. At the instant when the ball is dropped, its initial
velocity is u=0,, so v2=0+2*9.8*45=√882=29.70
--------------------------------------------------------------------------------------------------------------------------------------
Parallel Resistors:
In electronic circuits, resistors are used to reduce current flow and adjust signal levels. Resistors can
be connected either in series or in parallel. Given N resistors which are connected in parallel and
their respective resistance values, write a program to find the total resistance.
Formula:
1/R=1/R1+1/R2+1/R3+...+1/Rn
Input format:
first input is an integer that denotes the number of resistors N.
second line consists of series of n integers separated by a space that denotes the resistance values.
output format:
output is a double value that denotes the total resistance.(Rounded off to two decimal places)
sample input 1:
2
12 12
sample output 1:
6.00
sample input 2:
5
12345
sample output 2:
0.44
explanations:
for sample input 1-->2 resistors are connected parallely and their resistance value is 12 and 12. The
formula to find total resistance for the parallel connection is 1/R=1/R1+1/R2+1/R3+...+1/Rn.
the net resistance is, 1/R=1/12+1/12=2/12=⅙. therefore to find R, take reciprocal.
the total resistance is R=6.00
--------------------------------------------------------------------------------------------------------------------------------------
AWESOME CHARACTERS
Raghu has twin sons and they are studying in 8th grade. To test their knowledge, he gave them a fun
task to play with. The task is to find the awesome characters. Two characters x and y are said to be
awesome characters if absolute difference between their ascii values produce a character that is an
uppercase alphabet. Given x and y values as inputs, write a program tofind whether the characters
are awesome characters or not and also print the difference in the next line.
Input format:
first line consists of a two space separated characters that denotes x and y.
output format:
output is of two lines.
1) print “Awesome Characters’ if absolute difference between their ascii values produce a
character that is a uppercase alphabet, else print “Normal Characters”.
2) also print the absolute difference between their ascii values.
sample input 1:
AZ
sample output 1:
Normal Characters
25
sample input 1:
v!
sample output 2:
Awesome Characters
85
Explanation:
For sample input 1-->the ascii value for A is 65 and Z is 90. Their absolute difference is 25
and their difference in ascii values did not produce an uppercase alphabet. So A and Z are
normal characters.
For sample input 1-->the ascii value for v is 118 and ! is 33. Their absolute difference is
85and their difference in ascii values produces an uppercase alphabet. So v and ! are
Awesomel characters.
---------------------------------------------------------------------------------------------------------------------------
COST OF TABLE
A rectangular table has 4 semi-circle on all the 4 edges and the semicircle portion is cut from
the table. Given the length and width of the rectangular table in cm, radius of the semicircle,
find the area of the table and if the area is greater than 20000 sqcm, the table will be
painted, else the table will be given a wooden finish.
Given the cost for painting and wooden finish per sq.cm, write a program to find the total
cost of the table.
Note:
Area of semi-circle=(3.14*r*r)/2
input format:
first line consists of s single integer that denotes the length of the table.
second line consists of a single integer that denotes the width of the table.
third line consists of a single integer that denotes the radius of the semi-circle.
next line consists of a single double value that denotes the cost for painting per sq cm.
last line consists of single double value that denotes the cost for wooden finish per sq cm.
output format:
output is a double vlaue that denotes the total cost of the table. (Rounded off to two
decimal places)
sample input 1::
15
17
3
102.3
142.2
sample output 1:
28223.86
sample input 2:
100
70
20
12
11
sample output 2:
53856.00
---------------------------------------------------------------------------------------------------------------------------
7 SEGMENT LED DISPLAY
A seven segment display (SSD_, or seven segment indicator, is a form of electrnic device for
displaying decimal in digital format. kTow single digi numbers a and b are given as inputs,
initially, the number a is displayed in the 7 segment LED display. write a pprogram to
determine how many segments has to be alered (either urn on or turn off) to change from a
to b.
Input ormat:
first input is an integer that denotes the first number a
second input is an integer that denotes the second number b
output format:
output is an integer that denotes the number of segments to be changed.
sample input 1:
6
1
sample output 1:
6
sample input 2:
4
5
sample output 2:
3
explanation:
For sample input 1→ first number 6 is displayed in 7 segment display., it takes 6 segments
(a,f,e,d,c,g) to display. Number 1 takes 2 segments (b,c) to display. So no change from 6 to 1
(a,f,g,e,d) has to be turned off and (b) has to be turned on. Hence a total of 6 segments
needs to be changed.
For sample input 2→ first number 4 is displayed in 7 segment display, it takes 4 segments
(f,g,b,e) to display Number 5 takes 5 segments (a,f,g,c,d) to display. so to change from 4 to
(b) has to be turned of and (a,d) has to he turned on,(f,g and c) are already turned on, so
they need not be considered. Hence a total of 3 segments (b-->off and a,d-->on) needs to be
changed.
---------------------------------------------------------------------------------------------------------------------------
LUCKY CHAIR
Rohan and his friends were playing a game. there are n number of chairs arranged both row
wise and column wise. Each chair is moved with number at the back. Each person has to find
the lucky chair. The chair which is present in the row with maximum sum and column with
the minimum sum is the lucky chair. Given a matrix a, write a program to find the a[x][y],
where x is the row with max sum and y is the column with min sum.
Note:
consider 0 based index for rows and columns. if two rows or columns have same maximum
sum or minimum sum take the first occurring row or column.
input format:
first line consists of single integer that denotes the row size of the matrix.
second line consists of a single integer that denotes the column size of the matrix.
next line consists of series of integers separated by a space that denotes the array values.
output format:
output is an integer that denotes the a[x][y] value.
sample input 1:
3
3
123
456
789
sample output 1:
7
sample input 2:
4
2
10 20
41 25
15 136
145 2
sample output 2:
136
--------------------------------------------------------------------------------------------------------------------------
TOTAL RUNS
Given the total runs, number of boudaries and sixes made by players of the cricket team,
write a program to calculate the total percentage of runs made by the players by running
between the wickets.
input format:
first line contains a single integer that denotes the total runs.
second line contains a single integer that denotes the number of boundaries
third line contains a single integer that denotes the number of sixes.
output format:
output contains a single integer denoting the the total percentage of runs made by running
between the wickets.
sample input 1:
100
8
5
sample output 1:
38
sample input 2:
125
5
8
sample output 2:
45
explanation:
for sample input 1→ total runs is 100, he scored 8 boundaries and 5 sizes. so the total runs
made by running between wickets is 100-(8*4+5*6)=38
total percentage of runs he made by running between the wickets is = (38/100)*100=38
---------------------------------------------------------------------------------------------------------------------

DIFFERENCE OF ELEMENTS AT INTERSECTION


Given a matrix of size a[r][c], write a program to print the difference between the elements at
maximum row maximum column intersection and minimum row and minimum column intersection.
input format:
first line contains a single integer denoting the row size
second line contains a single integer denoting the column size
next lines contains the matrix values
output format:
output contains a single integer denoting the difference at intersection elements.
sample input 1:
4
4
1234
5678
9 10 11 12
13 14 15 16
sample output 1:
15
sample input 2:
5
3
125
456
456
253
10 11 15
sample output 2:
14
explanation:
for sample input 1→ the element that is present at the intersection of maximum row and column is
16 and the element that is present at the intersection of minimum row and column is 1.
maximum row sum is=13+14+15+16, at index is 3
maximum column sum is=4+8+12+16, at index 3
so a[3][3]=16
minimum row sum is=1+2+3+4,at index 0.
minimum column sum is=1+5+9+13,at index 0
so a[0][0]=1.
Difference between them is 16-1=15.
-------------------------------------------------------------------------------------------------------------------------------------
HIGHEST MULTIPLICATION NUMBER
Given a array of size n, write a program to find the maximum product where multiplication of two
numbers such that the result also exists in the array and find the highest multiplication number
present in the array.
Input format:
First input is an integer that denotes the size of the array, n.
Second line consists of series of integers separated by a space that denotes the array values.
Output format:
Output is an integer that denotes the highest multiplication number in the array.
Sample input 1:
8
2 4 5 35 6 7 12 30
Sample output 1:
35
Sample intput 2:
7
2 4 8 10 25 89 63
Sample output 2:
8
Explanation:
For sample input 1à there are totally 3 numbers where multiplication of two numbers whose result
is found in the array are: 2*6=12, 5*6=30, 5*7=35). Out of these, 35 is the highest multiplication
number present.
--------------------------------------------------------------------------------------------------------------------------------------
ARRANGE ARRAY ELEMENTS
Given an array of size n with both positive and negative numbers. Write a program to print all the
negative values first followed by positive values without changing the order if user selects option 1,
else print all the positive values first followed by negative values without changing the order.
Input format:
First input is an integer that denotes the size of the array, n.
Second line consists of series of integers searated by a space that denotes the array values.
Thirs line consists of an integer that denotes the Boolean value x 1 or 0 for the option.
Output format:
Output consists of series of integers separated by a space that represents the arranged array values.
Sample input 1:
10
9 4 5 -8 -5 -4 -9 5 4 8
1
Sample output 1:
-8 -5 -4 -9 9 4 5 5 4 8
Sample input 2:
10
9 4 5 -8 -5 -4 -9 5 4 8
0
Sample output 1:
9 4 5 5 4 8 -8 -5 -4 -9
Explanation:
For smapleinput 1àsince the value of x is 1, negative elements are arranged first followed by the
positive elements without changing the order.
-------------------------------------------------------------------------------------------------------------------------------
DISTANCE TRAVELED
Write a program to calculate the speed at which distance the aeroplane must travel to reach the
destination, given the total speed of the aeroplane and the hours taken to reach the destination
currently and the hours taken to reach destination at a required rate.
Input format:
First line consists of a single integer that denotes the speed of all aeroplane
Second line consists of a single integer that denotes the hours at which the aeroplane currently
travels.
Third line consists of single integer that denotes the hour at which the aeroplane is expected to
travel to reach the destination.
Output format:
Output is a float value that denotes the speed at which the aeroplane must travel to reach the
destination.
Sample input 1:
240
5
6
Sample output 1:
200.00
Sample input 2:
320
2
6
Sample output 2:
106.67
Explanation:
For sample input 1à the distance covered by the aeroplane when travelling at a speed of 240km/h
for 5 hours =240*5=1200km. Hence in 6 hours the speed required by the plane is =1200/6=200.00
Note:
The result should be rounded to two decimal places.
-------------------------------------------------------------------------------------------------------------------------------------
MIRROR IMAGE
Write a program to find the mirror image of the given number.
Input format:
First line consists of a single integer that denotes the n value.
Output format:
Output is an integer that denotes the mirror number of n.
Sample input 1:
97
Sample output 1:
67
Sample input 2:
125
Sample output 2:
95
Explanation:
For sample input 1àbinary value of 97 is 1100001.Mirror Image is the reverse of the binary value
which is 1000011 whose decimal value is 67
---------------------------------------------------------------------------------------------------------------------------------
Allwin’s matrix
Allwin got an array for Christmas, now he plans to construct a matrix with it.
He decides to construct a square matrix.
The resultant square matrix is constructed considering the following points.
1. Side length equal to the size of the array.
2. Each element at index [i][j] is equal to the sum of elements present at indexes between I and
j(inclusive of index I and j)
For a given array, write a program to construct and print the formed matrix.
Note:
If i<j, element at [i][j]=a[i]+a[i+1]+….+a[j].
If i>j, element at [i][j]=a[j]+a[j+1]+….+a[1].
If i=j,element at [i][j]=a[i][j]
Input format:
The first line consists of a single integer that denotes the size of the array
The second line consists of n-space separated integers that denote the elements of the array
Output format:
The output consists of n lines each containing n space separated integers that denote the output
matrix.
Sample input 1:
3
123
Sample output 1:
136
325
653
Sample input 2:
245
Sample output 2:
49
95
--------------------------------------------------------------------------------------------------------------------------------------
Bike race
Ramesh challenges suresh for a bike race where the one who reaches maximum distance in a given
time t wins the race. Their bikes have an acceleration of a1 and a2 respectively.
You being a practical person convince both of them saying bike racing is a dangerous sport and write
a program to predict the outcome of the race.
Input format:
The first line consists of s single integer that denotes the acceleration a1 of ramesh’s bike.
The second line consists of s single integer that denotes the acceleration a2 of suresh’s bike.
The third line consists of a single integer that denotes the given time 1.
Note:
Acceleration unit is m/s2
Initial velocity is zero since the bikes will start from rest.
Laws of motion:
S=ut+1/2at2
Where,
s-distance
t-time
u-initial velocity
a-acceleration
output format:
the first line consists of a single string that denotes the winner of the race(Ramesh/suresh).
The second line consists of a single integer that denotes the absolute difference between distance
covered by the racers in meter.
(or)
A single sring output ‘tie’ if the race ends in a tie.
Sample input 1:
8
10
50
Sample output 1:
Suresh
2500
Sample input 2:
21
12
4
Sample output 1:
tie
------------------------------------------------------------------------------------------------------------------------------------
Heavyweight championship
In your company, you plan for a heavyweight championship match between juniors and seniors.
Everyone with experience greater than the given limit ‘t’ are considered as senior.
Given the experience and weights of everyone in your company, write a program to print the
winners.
Note:
The game will never end in a tie.
Input format:
The first line consists of a single integer that denotes the number of employees – n.
The second line consists of n space separated integers that denote the experience of the employees.
The third line consists of n space separated integers that denote the weights of the employees.
The fourth line consists of a single integer that denotes the experience limit ‘t’. any employee with
more that ‘t’ years experience is considered a senior.
Output format:
The first line consists of a single string that denotes the winners of the game(juniors/seniors)
The second line consists of s single integer that denotes the absolute difference between the
weights of the teams.
Sample input 1:
5
42387
62 44 84 48 68
3
Sample output 1:
Seniors
50
Sample input 2:
8
21423214
62 44 84 48 68 62 44 84
Sample output 2:
Juniors
24
-------------------------------------------------------------------------------------------------------------------------------------
Required run rate
There is a lag in displaying the required run rate of the ongoing cricket match. You plan to solve the
problem by calculating the required run rate using a program. Given the target runs required,
current runs, the total number of overs, and the number of completed overs. Write a program to
print the required run rate to win the match.
Input format:
The first line consists of a single integer that denotes the target runs required.
The second line consists of a single integer that denotes the current runs.
The third line consists of a single integer that consists of the total number of overs.
The fourth line consists of a single integer that consists of the number of completed overs.
Output format:
A single double value (rounded to 3 decimal places) that denotes the required run rate.
Sample input 1:
100
40
12
3
Sample output 1:
5.67
Sample input 2:
60
40
10
2
Sample output 2:
5.00
--------------------------------------------------------------------------------------------------------------------------------------
Fun with house numbers
A boy is walking a long way from school to his home. To make the walk more fun he decides to add
up all the numbers of the houses that he passes by during his walk. He is regularly taking turns to
change streets, so the numbers don’t appear to him in any particular order.
Whenever he comes across a house with a house number divisible by 3, he multiplies the house
number with 3 and adds the product to the total.
At some point during the walk, the boy encounters a house with a negative number written on it,
which surprises him so much that he stops adding numbers to his total after seeing that house.
For the given sequence of houses write a program to print the sum that the boy will get.
Input format:
The first line consists of a single integer that denotes the number of houses n.
The second line consists of n space separated integers that denote the house numbers.
Output format:
A single integer that denotes the sum that the boy will get.
Sample input 1:
6
123456
Sample output 1:
39
------------------------------------------------------------------------------------------------------------------------------------
open doors
there are n doors in a row, all doors are initially closed. A person walks through all doors n times and
toggle (if open then close, if close then opens) them in the following way:
in the first walk, the person toggles every door
in the seond walk, the person toggles eery second door, ie. 2 nd,4th,6th,8th.
In the third walk, the person toggles every third door, ie. 3 rd,tth,9th.
In nth walk, the person toggles nth door.
Write a program to print all the open doors in ascending order.
Note:
The door numbers start from 1 to n.
Input format:
The first line consists of a single integer n that denotes the number of doors and number of walks
taken.
Output format:
The output consists of multiple lines each containing a single integer that denotes the door numbers
in ascending order.
Sample input 1:
50
Sample output 1:
1
4
9
16
25
36
49
Sample input 2:
30
Sample output 2:
1
4
9
9
16
25
-------------------------------------------------------------------------------------------------------------------------------------
Cost for spiral binding
Your final year project papers has to be spiralled (spiral binding). The cost for spiralling depends on
the thickness of the spiral. If thickness is <=1cm, the cost is rs.50. if thickness>1cm and <=2cm, the
cost id rs.100. if thickness>2cm and <=3cm, the cost id rs.150. for each 1cm increase in spiral
thickness, it costs rs.50 additionally. A total of 20 sheets will give a thickness of 1mm. given the
number of sheets, write a program to find the cost of spiral.
Input format:
First line consists of a single integer that denotes the number of sheets to be spiralled.
Output format:
Output is an integer that denotes the cost for spiralling.
Sample input 1:
225
Sample output 1:
100
Sample input 2:
488
Sample output 2:
150
Explanation:
For sample input 1à 225 sheets has to be spiralled. 225 sheets will make around 1.123 cm, since it is
less than 2cm and greater than 1cm, it costs rs.100
For sample input 2à488 sheets has to be spiralled. 488 sheets will make around 2.44cm. since it is
less than 3cm and greater than 2cm,it costs rs.150.
-------------------------------------------------------------------------------------------------------------------------------------
Volume of watermelon skin
Watermelon is in the shape of sphere. It has a thick skin. Given the radius of the entire fruit and the
radius of the fruit without the skin, write a program to find the volume of the skin alone.
Note:
Volume of spere=4/3*3.14*r3
Input format:
First line consists of a single double value that denotes the radius of the netire fruit.
Second line consists of a single double value that denotes the radius of the fruit without the skin.
Output format:
Output is a double value that denotes the volume of the skin alone.(Rounded off to two decimal
places)
Sample input 1:
15.2
12.6
Sample output 1:
63277.66
Sample input 2:
10.7
7.6
Sample output 2:
3291.00
-------------------------------------------------------------------------------------------------------------------------------------
Number of chocolates
There are n students standing in a circle. Starting from the first student, a ball is passed m times in
circular manner. The lucky student who has the ball after m passes will get m+index number+is
rollnumber amount of chocolates.
Given the total number of students n, their corresponding roll numbers and m, write aprogram to
find the number of chocolates the lucky student will get.
Input format:
First line consists of a single integer that denotes the number of students n.
Second line consists of series of inegers separated by a space that denotes the roll numbers.
Third line consists of a single integer that denotes the m value.
Output format:
Output is an integer that denotes the number of chocolates that the lucky student will get.
Sample input 1:
5
100 101 102 103 104
3
Sample output 1:
109
Sample input 2:
7
11 12 14 15 18 36 21
15
Sample output 2:
28
Explanation:
For sample input 1à5 students are standing in a circle, the ball is passed 3 times. Now the ball is with
3rd person(0 based index) with register number 103. Since he is the lucky student, he would get 109
chocolates(103 register number)+3(m value)+3(index).
For sample input 2: 7 students are standing in a circle, the ball is passed 15 times. Now the ball is
with 1st person(0based index) with register number 12. Since he is the lucky student, he would get 28
chocolates(12 register number+15 m value+1 index).
-------------------------------------------------------------------------------------------------------------------------------------
Special Matrix
Ram needs our help to solve a 2d array problem for him. Given a 2d square matrix, write a program
to find whether the given matrix is special or not.
Matrix is special if sum of upper triangular elements=sum of lower triangular elements=sum of
diagonal elements. Also if it is a special matrix print the sum else print the sum of upper triangle
elements, lower triangle elements and diagonal elements in the same line separated by a space.
Note:
Upper triangular elements are the elements that are present above the diagonal elements.
Lower triangular elements are the elements that are present below the diagonal elements.
Consider only left top to right bottom diagonal elements.
Input format:
First line consists of s single integer that denotes the size of the matrix n
The next n lines consist of a series of integers separated by a space that denotes the matrix values.
Output format:
Output is of two lines,
1) Print special matrix if sum of upper triangle elements, sum of lower triangle elements and sum
of diagonal elements are all equal, else print normal matrix
2) If special matrix print the sum else print the sum of upper triangle elements, lower triangle
elements and diagonal elements in the same line separated by a space.
Sample input 1:
4
1434
5678
9 10 15 12
13 1 0 16
sample output 1:
special matrix
3
sample input 2:
3
13 0 1
6 10 4
887
sample output 2:
normal matrix 5 22 30
------------------------------------------------------------------------------------------------------------------------------------
Paper correction
Teachers get paid for correcting the students board exam papers.
1) If a teacher corrects<=100papers, he gets rs.2 per paper.
2) If he corrects>100 and <=200 papers, the total amount he gets for correcting all the papers is
derived by formula -(rs.2 for each paper that he corrects after 100 copies+rs.x)
3) If he corrects>200 and <=300 papers, the total amount he gets for correcting all the papers is
derived by formula -(rs.3 for each paper that he corrects after 200 copies+rs.2 * x)
4) If he corrects>300 and <=400 papers, the total amount he gets for correcting all the papers is
derived by formula -(rs.5 for each paper that he corrects after 300 copies+rs.3 * x)
5) If he corrects>400 and <=500 papers, the total amount he gets for correcting all the papers is
derived by formula -(rs.6 for each paper that he corrects after 400 copies+rs.4 * x)
6) If he corrects>500 papers, the total amount he gets for correcting all the papers is derived by
formula -(rs.10 for each paper that he corrects after 500 copies+rs.5 * x)
Given the number of papers that the teacher had corrected and the value for x, write a program to
calculate the amount he gets.
Input format:
First line consists of a single integer that denotes the number of papers that the teacher has
corrected.
Second line consists of a single integer that denotes the x value.
Output format:
Output is an integer that denotes total amount that the teacher would get.
Sample input 1:
100
20
Sample output 1:
200
Sample input 2:
248
150
Sample output 2:
444
Explanation:
For sample input 1: the teacher corrects 100 papers, he gets rs.2 for each paper he corrects so he
would get rs.200 for correcting all papers.
For sample input 2: the teacher corrects 248 papers, he gets rs.3 for each paper he corrects after 200
copies plus rs.2x, so he would get rs.444(48*3+2*150) for correcting all papers.
-------------------------------------------------------------------------------------------------------------------------------------
Special odd array
Given an array of n integers, write a program to find whether the given array is special odd array or
not. Also print the number of special odd values.
Input format:
First line consists of a single integer that denotes the array size.
Second line consists of series of integers separated by a space hat denotes the array values.
Output format:
Output is of two line.
1) Print special odd array if there are odd number of odd digits in each of the elements in the array,
else print normal array.
2) Number of special odd values.
Sample input 1:
3
1 23 351
Sample output 1:
Special odd array
3
Sample input 2:
7
1 25 48 46 35 125 191
Sample output 2:
Normal array
3
Explanation:
For sample input 1: there are 3 elements in the array 1 23 351
First element : 1- has 1 odd digit 1
Second element: 23- has 1 odd digit 3
Third element: 351 has 3 odd digit 3, 5, 1
So its is a special odd array and there are 3 values that satisfies the condition.

For sample input 2: there are 7 elements in the array 1 25 48 46 35 125 191
First element: 1- has 1 odd digig 1
Second elemet: 25- has 1 odd digit 5
Last element : 191- has 3 odd digit 1 9 1
All other elements has even number of odd digits 35 125 or no odd digts at all 48 46, so its is
considered as normal array. Also there are only 3 values that satisfies the condition.
--------------------------------------------------------------------------------------------------------------------------------------
Magic number
Sherlock holmes is trying to solve a puzzle that leads him to his next destination. He has a note that
contains two integers that specify the lower bound and the upper bound and says to find the
smallest number divisible by all the numbers in that interval. Help shelock by developing a program
for him.
Note 1: both the upper bound and the lower bound are inclusive.
Note 2: always upper bound>=lower bound.
Input format:
The first line of the input contains single integer that denotes the lower bound
The second line of the input contains a single integer that denotes the upper bound.
Output format:
Output is an integer that denotes the smallest number divisible by all the numbers in the interval
between upper bound and the lower bound.
Sample input 1:
2
6
Sample output 1:
60
Explanation:
60 is the smallest number that is divisible by all 2 3 4 5 6
Sample input 2:
4
10
Sample output 2:
2520
Explanation:
2520 is the smallest number that is divisible by all 4 5 6 7 8 9 10
------------------------------------------------------------------------------------------------------------------------------------
The sticks
On summer vacation, jennier and her sister used to have ice-candy everyday. Jennifer’s sister used
to collect those ice sticks.
Now she has n ice sticks of different lengths. Jennifer’s sister wanted to play a game with those
sticks. So Jennifer suggested a game, that is, game of triangle.
In this game, there are n sticks of different lengths and one has to find the number of triangles that
can be constructed using any three of these sticks.
Constraints:
· The sum of the lengths of any two sides of a triangle must be greater that the third side.
· Equal triangles that are constructed from different sticks are considered different.
Input format:
First line contains a single integer that denotes the size of the array n.
Second line contains of n space separated integer values of the array that denote the stick lengths.
Output format:
A single integer output that denotes the number of triangles that can be formed.
Sample input 1:
4
3579
Sample output 1:
3
Explanation:
The triangles can be formed sing
3 5 7 – because 3+5>7 and 5+7>3 and 3.7>5
5 7 9 – because 5+7>9 and 7+9>5 and 9+5>7
3 7 9 – because 3+7>9 and 7+9>3 and 9+3>7
And 3 5 9 cannot be used to construct triangle because 3+5<9
-------------------------------------------------------------------------------------------------------------------------------------
Matrix assignment
Ravi is a 6h grade student in ABC school. He had a lecture session on matrix subtraction and an
assignment to be solved.
Given two matrices, find the difference between each elements in the matrices and print the matrix.
If the dimensions of the two matrices are not matching, then print invalid.
Input format:
The first line contains a single integer denotes the row size of the first matrix, m.
The next line contains a single integer denotes the column size of the first matrix, n.
The next m lines denote the matrix’s rows, with each line containing n space-separated integers of
the second matrix.
Output format:
If the dimensions are matching, print m lines that denote the result matrix’s rows, with each line
containing n space separated integers of the difference matrix.
Else print invalid
Sample input 1:
3
2
100
400
033
3
3
123
986
342
Sample output 1:
0 -2 -3
-5 -8 -6
-3 -1 3
--------------------------------------------------------------------------------------------------------------------------------------
Middle element
The middle of the array arr is defined as follows:
If arr contains odd number of element, its middle is the element whose index number is the same
when counting from the beginning of the array and from its end;
If arr contains an even number of elements, its middle is the average of the two elements whose
index numbers when counting from the beginning and from the end of the array differ by one.
When array arr, write a program to find its middle and if it consists of two elements, replace those
elements with the value of middle. Print the resulting array as the answer.
Note:
If the middle produces a floating point result, take its floor value.
Input format:
The first line contains a single integer that denotes the size of the array, n.
The second line consists of n space separated integer values of the array.
Output format:
Output consists of space separated integer values of the result array.
Sample input 1:
5
152 23 7 887 243
Sample output 1:
152 23 887 243
Explanation:
Here the number of elements is odd. So the middle is 7 and the result array is same as the input
array
Sample input 2:
5
11 23 543 342 97
Sample output 2:
11 23 543 342 97
Sample input 3:
6
7 2 2 5 10 7
Sample output 3:
7 2 3 10 7
--------------------------------------------------------------------------------------------------------------------------------------
Find the century
John is an archaeologist, and he wants to categorize the artefacts that he found by their centuries.
He knows their year of origin, now he needs to find their century.
Given a year, write a program to print the century of its origin.
The first century spans from the year 1 up to and including the year 100, the second – from the year
101 up to and including the year 200, and so on.
Input format:
First line of the input contains a single integer that denotes the year of origin.
Output format:
Output is a single integer that denotes the century of origin.
Sample input 1:
1992
Sample output 1:
20
Sample input 2:
1300
Sample output 2:
13
--------------------------------------------------------------------------------------------------------------------------------------
Adult or juvenile
Ram is planning to go on a world tour. Before visiting the countries he wants to verify whether he’s
an adult as per that countries rules. Help him develop a program to check whether he is an adult or
juvenile using his age and the adulthood age in a particular country.
Note that people whose age is the same as the adulthood age are considered adult.
Input format:
The first line contains a single integer that corresponds to the age of ram.
The second line contains a single integer that corresponds to the adulthood age of a particular
country.
Output format:
The first line of the output is a string. Print adult, if ram satisfies the adulthood age, else print
juvenile.
The second line of the output is an integer that denotes the absolute difference between ram’s age
and adulthood age.
Sample input 1:
32
18
Sample output 1:
Adult
14
Sample input 2:
12
16
Sample output 2:
Juvenile
4
--------------------------------------------------------------------------------------------------------------------------------------

You might also like