coding
coding
Question 2: Elections
Problem Description
Elections are going on, and there are two candidates A and B, contesting with each other.
There is a queue of voters and in this queue some of them are supporters of A and some of
them are supporters of B. Many of them are neutral. The fate of the election will be decided on
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
which side the neutral voters vote. Supporters of A and supporters of B make attempt to win
the votes of neutral voters.
The way this can be done is explained below:
1. The voter queue is denoted by three characters, viz {-, A, B}. The – denotes neutral
candidate, A denotes supporter of candidate A and B denotes supporter of candidate B.
2. Supporters of A can only move towards the left side of the queue.
3. Supporters of B can only move towards the right side of the queue.
4. Since time is critical, supporters of both A and B will move simultaneously.
5. They both will try and influence the neutral voters by moving in their direction in the queue.
If supporter of A reaches the neutral voter before supporter of B reaches him, then that neutral
voter will become a supporter of candidate A.
6. Similarly, if supporter of B reaches the neutral voter before supporter of A reaches him, then
that neutral voter will become a supporter of candidate B.
7. Finally, if both reach at the same time, the voter will remain neutral. A neutral vote cannot
decide the outcome of the election.
8. If finally, the queue has more votes for candidate A, then A wins the election. If B has more
votes, then B wins that election. If both have equal votes, then it will be a coalition
government.
Refer Examples section for understanding the dynamics of how the supporters influence the
neutral voters.
Your task is to find the outcome of the election.
Note: There are no test cases where all votes are neutral.
Input
First line contains an integer which is length of queue of voters.
Second line contains characters {-, A, B}, in which denotes
· A = voter who is supporter of candidate A
· B = voter who is supporter of candidate B
· – = neutral voter
Output
Print candidate with maximum number of votes. If they have equal number of votes, print
“Coalition government“.
Examples
Input :14
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
–AB–AB—A–
Output : A
Input : 4
A—
Output : A
Question 3: Moving Average
Problem Description
A stock price is dynamic. Its value can change multiple times in a fraction of a second or
remain unchanged for several minutes. Analyzing the dynamics of stock price change can
provide an indication for forth coming uptrend or downtrend in that stock. One such indicator
is simple moving averages. Now, Harry wants to analyze the price trend of the stock on the
basis of moving averages (MA).
Let’s consider a moving average of 2-day and 4-day respectively. A 2-day moving average is
calculated by taking average of closing price of 2 consecutive days. A 4-day moving average is
calculated by taking average of closing price of 4 consecutive days. Now, according to experts
whenever a faster moving average curve (2-day MA) cuts the slower moving average (4-day
MA) from below, then it is an indication of uptrend in the stock. Similarly, whenever a faster
moving averages curve (2-day MA) cuts the slower moving average curve (4-day MA) from
above, then it is an indication of downtrend in the stock.
Help Harry in computing the number of uptrends and downtrends in the given time for which
the data is provided.
In this graph, there are three lines indicating stock closing price, moving average of two days
and four days .Now we can see that between 13th and 15th there is an intersection. It is known
as downtrend when moving average of fewer days is cutting downwards the more days moving
average and vice versa.
Note1 – There will be no day1 moving average for 2-day MA. Similarly there will be no day1,
day2, day3 moving average for 4-day MA. In general there will be no X-1, X-2, Y-1, Y-2, etc
day point for X-day and Y-day moving average curve.
Note2 – All the computation has to be accurate up to 6 digits after the decimal point.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input
First line contains two space separated integers which are the moving average days X and Y.
Second-line contains an integer N denoting number of stock prices.
Third line contains N space separated decimal values denoting the closing price of the stock for
N days.
Output
Print the total number of times the stock will give uptrend or downtrend.
Examples
Input : 3 5
11
4.55 5.4 5.65 5.4 5.2 4.85 4.95 5.05 4.9 4.9 4.95
Output : 3
Input : 2 4
14
69.849998 72.900002 74.449997 77.300003 75.050003 74.349998 75.449997 76.300003 74
69.349998 65.349998 67.349998 67.599998 68.449997
Output : 4
Question 4: Jogging Ground
Problem Description
There are 4 circular grounds of equal sizes. Their circumferences do not intersect. The radius
and the distance of the center of each circle from the leftmost circle’s center are given.
There are 4 joggers who can start at the same time from any of the points designated as { a, b,
c, d } on the circumference of all the four circles as shown in the diagram below. All 4 joggers
jog in different grounds along the circumference of that ground. They could jog in either
clockwise (left to right) or anticlockwise (right to left) direction. Finally they may also jog at
different speeds.
Given starting position, direction of jogging and speed of jogging of all the 4 joggers, find the
summation of length of 3 segments between the four joggers at a given point in time since the
start of the jog.
Note : All the computation has to be accurate up to 6 digits after the decimal point.
Input
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Herbivores like Elephant, Deer are prime attractions. Similarly, Lion and Tiger are prime
attractions amongst carnivores. Finally, Dolphins and Shark are prime attractions amongst
aquatics for tourists.
Aman being a savvy businessman realizes that in order to minimize the cost of building the zoo
without compromising on the attractions, he has to decide how much area to allocate to each
animal type. Each animal type requires a certain area to thrive in. This in turn impacts the area
allocation, which in turn has cost implications.
Your task is to help Aman workout the mathematics such that the zoo building cost is
minimized subject to the following constraints:
Zoo needs to have minimum of X herbivores, Y carnivores and Z aquatic animals
Different types of animals will need different minimum area to thrive in
For animals of a given type, the minimum area required is the same
There is also a maximum limit for the overall area allocated for each animal type
Cost of fencing etc. is included in cost of enclosure
Exclude the essentials like pathways for tourists, from area and cost calculations
Consider all areas in square meters and cost in Rupees.
Input
First line contains three space separated integers denoting the cost per square meter of building
the enclosure for each type of animals viz. herbivorous, carnivorous and aquatic respectively
Second line contains three space separated integers denoting the maximum area that can be
allocated to each type of animal viz. herbivorous, carnivorous and aquatic respectively
Next three lines, each will contain two space separated integers M and N, for each type of
animal viz. herbivorous, carnivorous and aquatic respectively, where M denotes minimum
number of animals of that type and N denotes minimum area required for that animal type
Last line contains an integer which represents the total area of land on which the zoo needs to
be built
Output
Single integer containing the minimum cost required to build the zoo.
Examples
Input : 10000 1000 1500
250 250 300
55
15 5
10 10
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
500
Output : 837500
Explanation
·The cost of constructing the enclosure for herbivores is high. However, since we need to
accommodate 5 herbivores as per given constraints, a 25 sq. meter land will need to allocated
for the herbivores.
·Since the cost of constructing the enclosure for carnivores is cheapest we are able to allocate
them the maximum limit that we can allocate. Thus we are allocating 250 sq. meters for
carnivores.
·The remaining 225 sq. meters can thus be allocated to aquatics without violating any
constraint.
·Thus the minimum cost of constructing the zoo adhering to all constraints is (25 * 10000 +
250 * 1000 + 225 * 1500) = 837500
Example 2
Input : 100 1000 1500
250 250 300
55
15 5
10 10
500
Output : 325000
Explanation
·Since the cost of constructing the enclosure for herbivores is cheapest we are able to allocate
them the maximum limit that we can allocate. Thus we are allocating 250 sq. meters for
herbivores.
·The cost of constructing the enclosure for aquatics is high. However, since we need to
accommodate 10 aquatics as per given constraints, a 100 sq. meter land will need to allocated
for the aquatic animals.
·The remaining 150 sq. meters can thus be allocated to carnivores without violating any
constraint.
·Thus the minimum cost of constructing the zoo adhering to all constraints is (250 * 100 + 150
* 1000 + 100 * 1500) = 325000
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
6. Suppose on dd-mm-yyyy an eclipse occurred. Now, we are interested to calculate the date
when next eclipse occurs. (Didn’t solve)
Input:
Input: The date in format dd-mm-yyyy
Output: Desired date in yyyy-mm-dd format
Constraints:
It is guaranteed that given date is valid.
01 <= dd <= 31
01 <= mm <= 12
1900 <= yy <= 2100
I felt some details were missing here.
7. Given the amount invested, final amount got in return and the period of investment, found
out the simple rate of return and annualized return for this investment.
Input:
1st line contains amount invested.
2nd line contains amount returned.
3rd line contains period of investment.
Output:
1st line contains simple rate of return.
2nd line contains annualized return.
Output must be rounded off to up to 2 decimal places.
8. Sam is interested in markets and investments. He often buys new stock and sell the non-
profiting once. In order to do the same, he takes help for a broker who charges Sam certain
amount. Find out how much does Sam pay the broker for given transactions. (Unsolved –
some test cases failing)
Input:
1st line contains no. of stocks Sam deals with (N). 2nd line contains constant brokerage rate
that the broker takes from Sam for every transaction (B).
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
The next lines will have stock details in the form: Volume or numbers of a stock, stock name,
unit price of stock, bought/sold (B/S).
Output:
Total amount Sam pays to the broker. The output will be upto 2 decimal places and the value
will be rounded off to DOWN.
9. Consider a set of web pages, numbered from 1 to N. Each web page has links to one or more
web pages. Clicking on a link in a page, takes one to the other web page. You are provided
numbers of two web pages viz, starting web page and end web page. Your task is to find the
minimum number of clicks required to reach the end page from the start page. If end page cannot
be reached from start page, print -1 as the output. For better understanding
refer Examples section.
Constraints
0 < L < 10
Input
Next N lines contain L space separated integers depicting linked webpage number(s) from that
webpage
Output
Print the minimum number of clicks required to open the end page from start page. If not
possible, print -1 as output.
Example 1
Input
24
15
23
23
Output
Explanation:
Second line conveys that there are links from page 1 to pages 2 and 4.
Fourth line conveys that there are links from page 3 to pages 1 and 5.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Fifth line conveys that there are links from page 4 to pages 2 and 3.
Sixth line conveys that there is a links from page 5 to page 5 itself.
From page 2, we can open only page 1. From page 1, we can open page 4. From page 4, we can
open page 3. So, minimum 3 clicks are required, and this is the output.
10. Imagine you are a video games developer. You are developing a game which requires the
player to collect coins and cross hurdles. Let’s call the character in your video game to be Mario.
As Mario moves to collect coins and cross hurdles, the game keeps a count of relevant metrics.
Write code to implement this flow.
Mario will run from left to right and jump from ground in the air to collect coins or cross hurdles.
The Game Screen will be provided as input in form of a matrix comprising of three characters
viz {0, C and H}, where
All coins are of the same type, whereas there are two types of hurdles – simple hurdle and ring
hurdle. Simple hurdle is referred to as Hurdle hereafter.
A Hurdle always begins from the ground and a series of letter H stacked vertically make up the
height of the hurdle.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
A Ring Hurdle on the other hand, has a hole in it i.e., between H characters there will be exactly
one hole denoted by 0 character. This hole is big enough for Mario to jump through it to cross
that hurdle.
The screen will be depicted in the input as a M * N matrix. The index of row and
columns of this matrix begin from zero.
The left bottom cell of this matrix is (0, 0). As we move right and up, the row and column
indices increase
Row zero is considered as Ground and anything above row zero is considered as Air
Coins will always be in air, whereas hurdles will always manifest from the ground
Hurdle will never be so tall that Mario cannot cross it
Once Mario crosses all the columns, the game is over
To collect coins Mario will jump vertically in the column where the coin is. Mario always
jumps to the highest point where a coin is, on the screen. On his way down from that
point, he grabs all coins lower in height in that column. Thus, one jump in one column is
enough to fetch all coins in that column
Jumping consumes energy. Jumping one row consumes 2 calories. Similarly, if Mario
jumps R rows in a column, his calorific expenditure is 2 * R
Mario never jumps unless he must collect coins or cross a hurdle
When crossing a ring hurdle, the calories consumed in clearing it is 2 * height of the hole
in the ring hurdle. Refer Examples section for better clarity
Walking i.e., moving from one column to another consumes no energy
Your task is to keep a track of how many coins Mario collects and how many calories are
expended in collecting them.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
0000000000
0CCC00000H
0CCC0H0000
00000H0H0H
00000H0H0H
The above two images describe collection of coins and energy spent in collecting them.
Column 1 has two coins at a height of 2 and 3 respectively. So, Mario will jump 3 units high and
collect the highest coin. On his way down he will collect the coin at height 2. Total calories
expended in collecting both coins in Column 1 is 3 * 2 = 6 calories.
Columns 2 and 3 are identical to Column 1. Hence Mario will have collected 6 coins and spent
18 calories in traversing the grid up to column 3.
Column 4 is empty. So, no energy is expended traversing it. Next, there are hurdles at Column 5
and 7.
For clearing these hurdles, he must jump over two hurdles, and by doing this he will consume 3 *
2 + 2 * 2 calories.
For clearing these hurdles, he must jump over two hurdles, and by doing this he will consume 2 *
2 calories.
Note: Assume Mario can jump any hurdle of any height and collect coins at any height
Constraints
0 < M <= 10
Input
First line contains two space separated integers M and N which denote the size of grid (screen)
Next M lines will contain string of size N characters. The string will be comprised of {0, C and
H} characters
Output
Print two space delimited integers. First integer denotes the number of coins grabbed and second
integer denotes the calories expended in crossing the screen
1
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Examples
Example 1
Input
5 10
0000000000
0CCC00000H
0CCC0H0000
00000H0H0H
00000H0H0H
Output
6 32
Explanation:
11. It rains only on certain days in Primevilla. It is a rainy day when the number of days since a
certain date is prime as well as the month is prime (i.e., month is one of Feb, Mar, May, Jul,
Nov). Primevilla follows same calendar that we use.
Given the date d, identify if it would ever rain on a given weekday w within the next given n
days. Also calculate the number of days r (where r > 0) after which it would rain within the next
n days.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Constraints
2 <= n <= 10 ^ 10
Input
Input consists of three space delimited parts viz. <Date, DOW, n> where
Output
If it would rain on Ddd, r days after d within the next n days, print ‘Yes r’
Else if p is the least prime > n such that it would rain on Ddd after p days, print ‘No p’
Else print ‘No 0’, if it would never rain on Ddd.
Examples :
Example 1
Input
Output
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Yes 67
Explanation
Starting from 20211201 we start checking for prime number days whether it would rain. The
process will be as depicted below
20211201+2 is 20211203 Fri, month 12 is not prime —> It would not rain
20211201+3 20211204 Sat, month 12 is not prime —> It would not rain
..
20211201+31 is 20220101 Sat, month 1 is not prime —> It would not rain
..
Hence it could rain on a Sunday 67 days after the given date and within the given 100 days.
Hence, output is “Yes 67”
Imagine you are an MLA of a district and there are N number of villages in your constituency.
Your job is to vaccinate all the people in your constituency in minimum amount of time. There
are two centres where vaccination is going on. First centre takes m1 minutes as average time for
vaccinating one person and second centre takes m2 minutes as average time.
Population of every village is known to you prior to the vaccination drive. Schedule all the
villagers to any centre such that overall time for vaccinating all the people of all the villages will
be minimum. Assume that there is no wait time in between vaccinating two people. Also, people
belonging to the same village will need to be vaccinated in the same centre.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
For example:
v1 = 10, v2 = 30, v3 = 20
Consider if schedule is drawn by distributing equal number of people to both centres, then
Hence,
minimum time required to vaccinate all the people will be = 120 min.
Constraints
0 < N < 10 ^ 3
Input
First line contains an integer m1 which is average time in minutes taken for vaccination by the
first centre
Second line contains an integer m2 which is average time in minutes taken for vaccination by the
second centre
Fourth line contains N space delimited integers denoting the population of villages
Output
Single integer value denoting the maximum time taken in minutes to vaccinate all villagers from
all villages in your constituency
Examples
Example 1
Input
5
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
10 50 20 30 40
Output
180
Explanation:
First centre takes 2 min as average time. Second centre takes 3 min as average time. Your
constituency has 5 villages.
Minimum time required to vaccinate all the people will be = 240 min
Minimum time required to vaccinate all the people will be = 180 min
There are M snakes present in the matrix. They will move in a specific range the movement is
given below.
Snake movement-
1)If it is vertically oriented in the matrix. It will move up or down. Based on the start and end
block provided in the input.
2)If it is horizontally oriented in the matrix. It will move left or right. Based on the start and end
block provided in the input.
4)If it reaches the boundary(ith row or jth column) of the matrix it will come from another end of
the matrix in the same ith row or jth column.
Note: start_block and end_block represent the snake occupying these cells and the cells between
them.
For example, if start_block is 1,5 and end_block is 1,8 then snake occupies (1, 5), (1, 6), (1, 7),
(1, 8)
For Example-
Snake_name
Start_block
End_block
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Snake1
1,8
1,5
In this case, snake1 will move towards west all the time because the start block is towards the
east and the end block is towards the west, when it reaches the end of the matrix it will again
start from the start of row 1 towards east.
To achieve Nirvana the priest has to cross the matrix. The priest moves one step at a time. He
can start from any side of the matrix and reach the other side. If he starts from the north, he needs
to go to the south but cannot go in east and west direction, if he starts from the east, he needs to
go to the west but not in south and south directions and
vice versa.
Check whether he will be able to get Nirvana, if not print which snake killed him at which
location.
DirectionNumber where Direction represents directions (E for East, w for west, N for
For north and south directions, number always represents the column. The row of
For east and west directions, number always represents the row. The column of east
For example
Ex- W5 -> This means it will start from the west and move towards the east. Initially, it will be
the 1st column and 5th row.
N2 -> This means it will start from the north and move towards the south. Initially, it will be the
1st row and 2nd column.
Constraints
10<=N<50
1<=M<20
Input
First-line contains an integer N denoting the number of rows and columns in a matrix.
Next M lines contain space-separated data about each snake’s initial position. In the below-given
Format
The next line contains string denoting the block and direction from which the priest will start to
move.
Output
Print “NIRVANA” in case of priest reaches the other side of the matrix.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
OR
Print the which snake killed the priest and at which position.
Examples
Input
10
W2
Output
NIRVANA
Explanation-
Example 2
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input
10
S5
Output
Snake1 6,5
13. Consider a Jug of capacity L liters. Given N cups of different capacities Ci (in liters), fill the
Jug with the help of cups, according the specification.
The specification according to which the cups may be used to fill the Jug is as below
1. Cups can be used integral number of times i.e., zero or more times, but never partially
i.e., a cup of 1L can be used 0, 1, 2 etc. times, but never 0.5, 1.5, 2.5 .. times
2. The Jug must not overflow because of cup filling the Jug
3. The number of distinct cups (i.e., different cup sizes) used to fill the Jug must be
maximized
4. The summation of number of times all cups are used must be minimized.
5. Consider point 3 to be more important than point 4 when meeting the optimisation goals.
For better understanding of how cups can be used to fill the Jug, go through
the Examples section. Both examples clearly explain, when there are multiple ways to achieve
the objective, what is the correct answer and why.
Constraints :
0 < N < 10
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input :
First line contains an integer N denoting the number of cups available.
Second line contains N space separated integers denoting the capacity of the cups.
Third line contains an integer L which denotes the capacity of Jug in liters.
Output :
Output consists of two lines.
First line must comprise of N or less space delimited integers, in ascending order of cup size, for
the cups used to fill the Jug
Second line must comprise of equal number of space delimited integers which denote the
frequency i.e. the number of times the corresponding cup in first line is used to fill the Jug.
Example 1 :
Input :
4
3 7 10 11
88
Output :
3 7 10 11
1261
Explanation :
The first and second lines indicate that you are provided with 4 cups of capacities – 3 liters, 7
liters, 10 liters and 11 liters. The third line indicates that the capacity of the Jug is 88 liters.
One possible solution for filling the Jug is
7 10 11
523
i.e., one can use 7L cup for 5 times to get 35L. Next one can use the 10L cup twice. After that
the Jug will contain 55L. Finally, one can use 11L cup thrice. Thus, the Jug will be filled.
However, this solution uses cups of only 3 different capacities when 4 different capacities are
available. Hence the Jug is perhaps not filled according to the specification. Let’s see if we can
achieve our objective by using all 4 cup sizes.
We can use all the available cups if we use them as follows
3 7 10 11
1261
Hence, this is our final solution which adheres to the specification.
Example 2 :
Input :
3
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
2 5 10
50
Output :
2 5 10
523
Explanation :
The first and second lines indicate that you are provided with 3 cups of capacities – 2 liters, 5
liters, 10 liters. The third line indicates that the capacity of the Jug is 50 liters.
Here one can easily fill the Jug by using the 10L cup 5 times. However, this does not obey the
specifications. According to the specifications, one must use all available cups of capacity 2L,
5L and 10L. If there are multiple ways in which the Jug can be filled by using maximum number
of distinct sized cups, then as per specifications one needs to minimize the summation of number
of times cups are used.
A worker will still need to be assigned even if a task can be done only by the machine
Tasks need to be processed in sequential order i.e., T1 has to be allocated before T2
Initially when all workers are free, worker Wi will be allocated task before worker Wi+1
i.e., in general a worker with lower suffix will be assigned to the task before worker with
a higher suffix.
If one or more workers are available at the same time, then the worker who processed
lower suffix task will get the next task allocated prior to the other workers.
Assume the switching time from one task to another as 0 min
Refer Examples section for better understanding of how tasks are allocated to workers
Compute which task was completed at what time and which worker performed that task. The
output specifications provide information on how output should be printed.
Constraints :
1 <= N <= 10
0 < M <= 100
Input :
First line contains an integer N which denotes the number of workers
Second line contains an integer M which denotes the number of tasks
Next M lines contain a task information tuple as described in the previous section.
Output :
Output should adhere to the following specifications.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Each output should be a tuple comprising of 3 pieces of information viz <Worker name,
task name, time at which the task was completed>
The tuple should be first sorted in ascending order of completion time and then in
ascending order of task name
Example 1 :
Input :
3
4
T1 Machine
T2 Manual 5
T3 Machine
T4 Machine
Output :
W1 T1 0
W3 T3 0
W1 T4 0
W2 T2 5
Explanation :
Here, N=3 denotes number of workers W1, W2, W3.
First, Workers W1, W2, W3 will be assigned with tasks T1, T2, T3 at the 0th minute,
respectively.
Here, T1 is Machine-bound so it will be completed in 0th minute and then W1 will be available
for the remaining tasks. T2 is Manual and it will be completed in 5th minute. So, W2 will be free
after 5 minutes. T3 again is Machine-bound so it will be completed in 0th minute and then W3
will be available for remaining tasks.
Now, Workers available for pending tasks in 0th minute = {W1, W3}
Here, W1 will be assigned with next pending task first, because the worker W1 completed task
with lower suffix (T1) than W3 (T3).
W1 will be assigned the next task T4 at 0th minute which is a Machine-bound task which will
also be completed in 0th minute.
As the number of pending tasks are zero, no further assignment takes place.
W2 will complete T2 at the end of 5th minute. Hence,
First line of output is “W1 T1 0”, where T1 is the task completed by Worker W1 0th minute.
Second line of output is “W3 T3 0”, where T3 is the task completed by Worker W3 in 0th
minute.
Third line of output is “W1 T4 0”, where T4 is the task completed by worker W1 in 0th minute.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Fourth line of output is “W2 T2 5”, where T2 is the task completed by W2 in 5th minute.
So, the output is as follows:
W1 T1 0
W3 T3 0
W1 T4 0
W2 T2 5
14. College Admissions are done by allocating a seat to a student based on his/her preference and
percentage scored. Students are asked to provide three colleges of their choice. Each college will
have a quota of S seats (S can vary per college). Admissions will be processed based on
‘percentage scored’ and availability of seats as per ‘choice of preference’.
Admissions will first be granted based on percentage scored. If there is a tie, on percentage
scored, then admission will be granted based on student Id i.e. student with a lower Id will be
given preference over student with higher Id.
In Round 1 all admissions will be processed based on students’ choice i.e. if a student is eligible
to get admitted in any of the 3 colleges, s/he will have to be admitted. Similarly, it will be
binding on the student to get admitted. Obviously, first choice will get first preference, second
choice will get second preference and so on.
Round 2 will process all the remaining students (those who didn’t get admitted in Round 1)
according to their percentages and in order of maximum availability of seats in colleges.
For E.g.
<college, vacant seats>
C-1, 15
C-22, 14
C-32, 13
C-43, 12
<student-id, percentage>
Student-88, 64.0
Student-103, 63.7
Student-128, 58.28
Here, now Student-88 will get admitted to C-1.
Now, Student-103 could potentially get admitted to C-1 or C-22. Suppose we mandate that ties
should be broken in favour of college with least ID, then again Student-103 will get admitted to
C-1. Now C-1 has 13 vacant seats whereas C-22 has 14 vacant seats.
Next, Student-128 will get admitted to C-22. Now again C-1, C-22 and C-32 have 13 vacant
seats. So, the next three students (hypothetically) will get admitted to C-1, C-22 and C-32
respectively.
Constraints :
3<=C<=25
1<=N<=10000
1<=S<=120
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input :
First line contains two integers viz. C and N where,
C is number of colleges and
N is number of students
Second line contains C spaced integers denoting S1,S2 and so on till SC – where S1 is number of
seats in college 1, S2 in college 2 etc.
Next, N lines comprise of 5 data items, viz <student-id, percentage, Choice 1, Choice 2, Choice
3>
Output :
Display the cut-off percentages of all the colleges in sorted order (descending order). Display the
college with no students in last line as ‘n/a.
The output format is <college cut-off_percentage>
For better understanding go through the Examples given below.
Time Limit :1 secs
Example 1 :
Input :
3 5
3 1 2
Student-1,97.05,C-1,C-3,C-2
Student-2,48.03,C-1,C-2,C-3
Student-3,85.69,C-1,C-3,C-2
Student-4,80.83,C-1,C-3,C-2
Student-5,41.23,C-1,C-2,C-3
Output :
C-1 80.83
C-2 48.03
C-3 41.23
Explanation :
Here student-1 with highest percentage gets his first preferred college, then the next top scorer,
Student-3 gets his first preferred college and so on.
However, we can see that there are only three seats in college 1 so only students with good
percentage get admitted (i.e., student-1, student-3, student-4).
Now college 1 allocation quota is complete. Hence no new student can be admitted to college 1.
college 2 and college 3 still have one and two seats respectively. Now, Student-2 and Student-5
are yet to be admitted.
Both student’s priority is college 2 as second choice, but Student-2 is admitted to college 2 due
to higher percentage (i.e., Student-2 Percentage> Student-5 Percentage).
Now there are only 0, 0, 2 seats left in college 1, college 2 and college 3 respectively. So,
Student-3 is admitted to college 3 based on his preference. Here there is no need of round 2 as all
students are admitted to colleges and none of them are awaiting admissions.
Now, C-1 = [Student-1, Student-3, Student-4], C-2=[Student-2], C-3=[Student-5]. For C-1, Cut-
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
off is 80.83 because Student with least percentage in C-1 is Student-4. Similarly for C-3, it is
41.23 Display these Cut-off in sorted order.
15. The people of Kingdoms of Westeros are very organized. They are very devoted to their
leader and cannot live without a leader even for a single day. Marriages, divorces, births, and
deaths are everyday things in Westeros and because of these events people of Westeros need to
spend their time on choosing the leader. People badly need a programme to find the new leader
in case of these events. The criteria to choose the leader is as below.
The leader of the family will be the oldest person. [Age of each member in a particular
family will be different]. For simplicity, consider surname as family name. In the input
though family name will be mentioned explicitly.
2 or more families are said to be related if a boy from one family has married a girl in the
other family. Thus, related families will have a single leader who will be the senior most
person from the newly formed cluster of families. If 2 members from this cluster have the
same age, then the person with larger family will be the leader of the new cluster. If that
also results in a tie, then the person whose name comes first in lexicographical order will
be the leader
After marriage the wife will assume husband’s family name and will be counted as a
family member of the husband’s family.
If new Birth happens, children will take fathers family name.
If Divorce happens 2 families will split, the wife will assume her maiden family name.
All children will be counted as members of their father’s family. The families will choose
new leaders.
After divorce the wife will assume her birth family name and hence husband’s family
may no longer be relatives, provided there is no other marriage bond between these two
families.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
If any Death happens and the deceased person was the leader, the family / cluster will
choose a new leader. If a married women dies, the relation between 2 families will break
i.e. they will split by family name
If a married woman dies the relation between 2 families (husband and wife) will break
provided there is no other marriage bond between 2 families. From perspective of
answering queries, unless the husband remarries, the name of the dead wife should be
printed as Spouse Name
If a married man dies the relation between 2 families (husband and wife) will not break.
Wife will still be considered as husband’s family until she marries someone else. From
perspective of answering queries, unless the wife remarries, the name of the dead
husband should be printed as Spouse Name
Every Person in Westeros has a unique name.
Every person in a particular family will have different age.
Polygamy or polyandry is not permitted. A person can have only one spouse at any time.
Although Remarriage after divorce is possible
NA will appear in input wherever not applicable
Constraints :
1 <= N <= 500
1 <= E <= 100
Input :
First line contains an integer denoting the number of records (N).
Next N lines contain one record each i.e., space separated data about every person in the format
Firstname FamilyName BirthFamilyName Gender FatherName SpouseName Age
Next line contains an integer denoting the number of events (E).
Next E lines contain data about respective event.
The events are recognized by keywords and apply to one of more persons as explained below
MA Person1 Person2
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
DI Person1 Person2
DE Person1
YP
Print All:
PA
Print One:
PO Person1
Firstname
Family Name
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
16.In this superhero epic, the denizens of the Marvel Universe are forced to pick sides when
Captain America and Iron Man come to blows over ideological differences.
The government decides to push for the Hero Registration Act, a law that limits a hero’s actions.
This results in a division in The Avengers. Iron Man stands with this Act, claiming that their
actions must be kept in check otherwise cities will continue to be destroyed, but Captain America
feels that saving the world is daring enough and that they cannot rely on the government to
protect the world. And here the civil war begins.
They are trying make their team stronger by adding more avengers to their team. There are N
avengers lined up.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Any team can start first. But they will alternatively only.
They can select avenger from any side. But if they start from one side they can’t move to
other side in current chance.
They can select consecutive avengers as many they want.
They will stop only when all the avengers are part of either side.
Every Avenger has a power associated with him
There are some spurious avengers who will decrease the overall power of the team.
Both teams will select players optimally. Find the difference of powers of the two teams
Constraints
1<= N <= 10^6
-10^9 <= p[i] <= 10^9
Input
First line contains an integer denoting the number of Avengers(N).
Next lines contain N space separated values denoting power of every avenger(P[i]).
Output
Print the difference of the powers of teams
– Time Limit (secs)
1
Examples :
Input
5
2-78-1 20
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Output
2
17.John is working in high security organization, where he needs to deal with lot of confidential
documents. He must encrypt the important number in documents. Please help John to write a
program where the system should identify the integer number and encrypt number based on
John’s actions.
Rules
Constraints
0 <n<= I where I is length of the input string.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input
First line contains a string comprising of numbers. This is referred to as input string in the rest of
the document.
Second line contains the actions denoted by values mentioned in the table above. This is referred
to as action string in the rest of the document.
Output
Single string comprising of numbers.
Examples
Input
123456
RLTDRRTRS2S1
Output
244156
Explanation
Action: RLTDRRTRS2S1
R: 1[2]3456
L: [1]23456
T: [2]23456
D: [1]23456
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
R: 1[2]3456
R: 12[3]456
T:12[4]456
R: 124[4]56
S2: 144[2]56
S1: 244[1]56
output string.
Since all the actions from the action string are consumed and only first four characters of the
input string are processed leave the last two as they are and make them the part of
18.You are given N comma-separated Strings. You need to form all possible legal subsets of
these N strings. These subsets will be a combination of zero or more of these N Strings After
forming the subsets, they will be ranked in a particular onder. The legal subset formation and
ranking logic is as described below
Example: you are having an input string “aa,cc,bb” in this string we can see we have three
strings which are comma separated. Now from this group of string we have to create all possible
subset of strings. 8 subsets can be formed from these strings. And they are as follows:
1. {}
2. {aa}
3. {cc}
4. {bb}
5. {aa,}
Note: here we can see the ranks given to the subsets are first by size i.e., the subset with lesser
number of strings is ranked higher than the subset with higher size. If the subsets have equal
number of strings then, the combination which is formed earlier (by virtue of combining strings
in order they appear in input), gets a higher rank.
For example, rank of su bset (aa,cc) > rank of (aa,bb) because string cc is appearing prior to
string bb in the input. Similarly, rank of (cc) > rank of (bb).
You are provided one rank R and for that you have to print the Rth subset from all legal subsets.
Constraints:
0<N<=10^2
0<R<=10^18
Input
Second line contains an integer R, for which you have to find Rth subset from all legal subsets.
Third line contains N comma-separated strings basis which the subsets should be formed
Output:
From all possible legal subsets find the subset whose rank is R
Input
a,b
Output
a,b
Explanation:
{}-1
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
{a} -2
{b}-3
{a, b}-4
19.You are a caretaker of a waiting room and you have to take care of empty seats such that all
the people should sit together. Imagine the seats are in a straight line like in a movie theatre.
People are seated on random seats initially. Your task is to make them sit together so that
minimum number of people change their position. Also, they can be made to sit together in many
ways. Find the number of ways you can make them sit together by requiring only minimal
people movement.
“E” depicts an empty seat and “O” depicts an occupied seat. Input will be given in the form of a
string.
Example: OEOEO
As we can see, only seat number 1, 3, 5 are occupied and 2 and 4 are empty.
Case 1: If we move 5th person to 2nd position, they can all be together with only one person
moving his/her place.
Case 2: If we movement 1st person to 4th position, they can all be together with only one person
moving his/her place.
They can all be together with only one movement and this can be done in 2 ways. Print the
minimum number of movements required and the number of ways this minimum movement can
help achieve the objective.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Constraints
0
Input
Second line contains N characters each of which are either “O” or “E”. “O” denotes an occupied
seat and “E” denotes an empty seat.
Output
Print minimum number of movements required and the number of ways in which all people can
be made to sit together without exceeding minimum number of movements by space
Time Limit (secs)
1
Examples
Input
5
OEOEO
Output
12
Explanation:
Seat number 2 and 4 are unoccupied and all the other seats are occupied.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
We can make them sit together by moving only one person near to the other. It can be done in 2
ways:
20.You are a caretaker of a waiting room and you have to take care of empty seats such that all
the people should sit together. Imagine the seats are in a straight line like in a movie theatre.
People are seated on random seats initially. Your task is to make them sit together so that
minimum number of people change their position. Also, they can be made to sit together in many
ways. Find the number of ways you can make them sit together by requiring only minimal
people movement.
“E” depicts an empty seat and “O” depicts an occupied seat. Input will be given in the form of a
string.
Example: OEOEO
As we can see, only seat number 1, 3, 5 are occupied and 2 and 4 are empty.
Case 1: If we move 5th person to 2nd position, they can all be together with only one person
moving his/her place.
Case 2: If we movement 1st person to 4th position, they can all be together with only one person
moving his/her place.
They can all be together with only one movement and this can be done in 2 ways. Print the
minimum number of movements required and the number of ways this minimum movement can
help achieve the objective.
Constraints
0
Input
Second line contains N characters each of which are either “O” or “E”. “O” denotes an occupied
seat and “E” denotes an empty seat.
Output
Print minimum number of movements required and the number of ways in which all people can
be made to sit together without exceeding minimum number of movements by space
Time Limit (secs)
1
Examples
Input
5
OEOEO
Output
12
Explanation:
Seat number 2 and 4 are unoccupied and all the other seats are occupied.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
We can make them sit together by moving only one person near to the other. It can be done in 2
ways:
21.You are given N number of coordinates and you have to create a polygon from these points
such that they will make a polygon with maximum area.
Note: coordinates provided in the input may or may not be in sequential form.
Constraints
1 <= N <= 10
Input:
Next N lines consist of two space separated integer depicting coordinates of in form of xy
Output:
Print the maximum possible area possible by creating a polygon by joining the coordinates.
Examples:
Input:
4
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
0 0
2 0
0 2
2 2
Output:
Explanation:
As we can imagine that these points will make a square shape and the maximum possible area
made by the polygon will be 4.
22.A 10cm x 10cm x 10cm solid cube rests on the ground. It has a beetle on it, as well as
some sweet honey spots on the cube’s surface. The beetle begins at a point on the cube’s
surface and moves in a clockwise direction along the cube’s surface to the honey spots.
If it goes from one point on the same face to another (say, X to Y), it goes in an arc of a
circle that subtends an angle of 60 degrees at the circle’s center.
If it travels from one point to another on a different face, it takes the shortest path on the
cube’s surface, except that it never travels along its bottom.
The beetle is a Cartesian geometry student who knows the coordinates (x, y, z) of all the points it
needs to visit. Its coordinate origin is one of the cube’s corners on the ground, and the z-axis
points up. As a result, z=0 is the bottom surface (on which it does not crawl), and z=10 is the top.
The beetle keeps track of all distances traveled and rounded the distance to two decimal places
when it arrives at the following location so that the final distance is a sum of the rounded
distances from spot to spot.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input
The first line returns an integer N, the total number of points visited by the beetle (including the
starting point).
The second line contains 3N non-negative numbers, each with two decimal places. These are to
be interpreted as the x, y, and z coordinates of the points the beetle must visit in the given order.
Output
One line containing a number representing the total distance traveled by the beetle to two
decimal places. Even if the travel distance is an integer, the output should have two decimal
places.
Constraints
None of the points visited by the beetle are on the bottom face (z=0) or on any of the cube’s
edges (the lines where two faces meet)
2<=N<=10
Example
Input : 3
1 1 10 2 1 10 0 1 9
Output : 4.05
Explanation :The beetle visits three different locations (N=3). The beetle begins on the cube's
top face (z=10) at point (1,1,10) and moves to another point on the same face (2,1,10). Although
the straight line distance is one, it travels on the arc of a circle with an angle of 60 degrees at its
center and thus travels (2*pi)/6 or 1.05 (note that it rounds the distance at each leg of the
journey). It moves along the cube's surface from (2,1,10) on the face z=10 to (0,1,9) on the face
x=0. This is a three-mile distance. The total travel distance is 1.05+3=4.05. The result is 4.05
23. Some prime numbers can be expressed as a sum of other consecutive prime numbers.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
For example
o 5 = 2 + 3,
o 17 = 2 + 3 + 5 + 7,
o 41 = 2 + 3 + 5 + 7 + 11 + 13.
Your task is to find out how many prime numbers which satisfy this property are
present in the range 3 to N subject to a constraint that summation should always
start with number 2.
Write code to find out the number of prime numbers that satisfy the above-mentioned property in
a given range.
Output Format: Print the total number of all such prime numbers which are less than or equal
to N.
Constraints: 2<N<=12,000,000,000
24. There are two banks – Bank A and Bank B. Their interest rates vary. You have received
offers from both banks in terms of the annual rate of interest, tenure, and variations of the rate of
interest over the entire tenure.You have to choose the offer which costs you least interest and
reject the other. Do the computation and make a wise choice.
The loan repayment happens at a monthly frequency and Equated Monthly Installment (EMI) is
calculated using the formula given below :
Constraints:
Input Format:
Explanation:
Example 1
o Input
o 10000
o 20
o 3
o 5 9.5
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
o 10 9.6
o 5 8.5
o 3
o 10 6.9
o 5 8.5
o 5 7.9
Output: Bank B
Example 2
o Input
o 500000
o 26
o 3
o 13 9.5
o 3 6.9
o 10 5.6
o 3
o 14 8.5
o 6 7.4
o 6 9.6
Output: Bank A
25. A positive integer d is said to be a factor of another positive integer N if when N is divided
by d, the remainder obtained is zero. For example, for number 12, there are 6 factors 1, 2, 3, 4, 6,
12. Every positive integer k has at least two factors, 1 and the number k itself.Given two positive
integers N and k, write a program to print the kth largest factor of N.
Input Format: The input is a comma-separated list of positive integer pairs (N, k).
Output Format: The kth highest factor of N. If N does not have k factors, the output should be 1.
Constraints:
1<N<10000000000
1<k<600.
You can assume that N will have no prime factors which are larger than 13.
Example 1
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input: 12,3
Output: 4
Explanation: N is 12, k is 3. The factors of 12 are (1,2,3,4,6,12). The highest factor is 12 and the
third largest factor is 4. The output must be 4.
Example 2
Input: 30,9
Output: 1
Explanation: N is 30, k is 9. The factors of 30 are (1,2,3,5,6,10,15,30). There are only 8 factors.
As k is more than the number of factors, the output is 1.
A solid cube of 10 cm x 10cm x 10 cm rests on the ground. It has a beetle on it, and some sweet
honey spots at various locations on the surface of the cube. The beetle starts at a point on the
surface of the cube and goes to the honey spots in order along the surface of the cube.
If it goes from a point to another point on the same face (say X to Y), it goes in an arc of
a circle that subtends an angle of 60 degrees at the center of the circle
If it goes from one point to another on a different face, it goes by the shortest path on the
surface of the cube, except that it never travels along the bottom of the cube
The beetle is a student of cartesian geometry and knows the coordinates (x, y, z) of all the points
it needs to go to. The origin of coordinates it uses is one corner of the cube on the ground, and
the z-axis points up.Hence, the bottom surface (on which it does not crawl) is z=0, and the top
surface is z=10.The beetle keeps track of all the distances traveled, and rounds the distance
traveled to two decimal places once it reaches the next spot so that the final distance is a sum of
the rounded distances from spot to spot.
Input Format:
The first line gives an integer N, the total number of points (including the starting point)
the beetle visits
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
The second line is a set of 3N comma separated non-negative numbers, with up to two
decimal places each. These are to be interpreted in groups of three as the x, y, z
coordinates of the points the beetle needs to visit in the given order.
Output Format:
One line with a number giving the total distance traveled by the beetle accurate to two
decimal places. Even if the distance traveled is an integer, the output should have two
decimal places
Constraints:
None of the points the beetle visits is on the bottom face (z=0) or on any of the edges of
the cube (the lines where two faces meet)
2<=N<=10
Sample Input 1:
3
1, 1, 10, 2, 1, 10, 0, 5, 9
Sample Output 1:
6.05
Sample Input 2:
3
1, 1, 10, 2, 1, 10, 0, 1, 9
Sample Output 2:
4.05
26. Krishna loves candies a lot, so whenever he gets them, he stores them so that he can eat them
later whenever he wants to.
He has recently received N boxes of candies each containing Ci candies where Ci represents the
total number of candies in the ith box. Krishna wants to store them in a single box. The only
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
constraint is that he can choose any two boxes and store their joint contents in an empty box
only. Assume that there are an infinite number of empty boxes available.
At a time he can pick up any two boxes for transferring and if both the boxes contain X and Y
number of candies respectively, then it takes him exactly X+Y seconds of time. As he is too
eager to collect all of them he has approached you to tell him the minimum time in which all the
candies can be collected.
Input Format:
Output Format: Print minimum time required, in seconds, for each of the test cases. Print each
output on a new line.
Constraints:
1 < T < 10
1 < N< 10000
1 < [Candies in each box] < 100009
S. No. Input
1 1 19
4
1234
2 1 34
5
12345
The task is to count all the possible paths from top left to bottom right of a m x n matrix with the
constraints that from each cell you can either move only to right or down.
Input:
First line consists of T test cases. First line of every test case consists of N and M,
denoting the number of rows and number of columns respectively.
Output:
Single line output i.e count of all the possible paths from top left to bottom right of a m x
n matrix..
Constraints:
1<=T<=100
1<=N<=100
1<=M<=100
Question:- There are n houses build in a line, each of which contains some value in it.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
A thief is going to steal the maximal value of these houses, but he can’t steal in two
adjacent houses because the owner of the stolen houses will tell his two neighbours left
and right side.
Sample Output: 20
There are n stairs, a person standing at the bottom wants to reach the top. The person can climb
either 1 stair or 2 stairs at a time.
Count the number of ways, the person can reach the top.
The problem solvers have found a new Island for coding and named it as Philaland.These smart
people were given a task to make purchase of items at the Island easier by distributing various
coins with different value.Manish has come up with a solution that if we make coins category
starting from $1 till the maximum price of item present on Island, then we can purchase any item
easily. He added following example to prove his point.
Let’s suppose the maximum price of an item is 5$ then we can make coins of {$1, $2, $3, $4,
$5}to purchase any item ranging from $1 till $5.
Now Manisha, being a keen observer suggested that we could actually minimize the number of
coins required and gave following distribution {$1, $2, $3}. According to him any item can be
purchased one time ranging from $1 to $5. Everyone was impressed with both of them.Your task
is to help Manisha come up with minimum number of denominations for any arbitrary max price
in Philaland.
Input Format
o First line contains an integer T denoting the number of test cases.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
o Next T lines contains an integer N denoting the maximum price of the item
present Philaland.
Output Format
o For each test case print a single line denoting the minimum number of
denominations of coins required.
Constraints
o 1<=T<=100
o 1<=N<=5000
Sample Input:
2
10
5
Sample Output:
4
3
Explanation:
27. Print a line containing all the divisors in increasing order separated by space.
Input Format: The first line of input contains an integer ‘N’ denoting the number.
Output Format: Print a line containing all the divisors in increasing order separated by
space.
Constraints:
1 <= N <= 10^8
28.Find the minimum number of coins required to form any value between 1 to N,both
inclusive.Cumulative value of coins should not exceed N. Coin denominations are 1 Rupee, 2
Rupee and 5 Rupee.Let’s Understand the problem using the following example. Consider the
value of N is 13, then the minimum number of coins required to formulate any value between 1
and 13, is 6. One 5 Rupee, three 2 Rupee and two 1 Rupee coins are required to realize any value
between 1 and 13. Hence this is the answer.However, if one takes two 5 Rupee coins, one 2
rupee coin and two 1 rupee coin, then too all values between 1 and 13 are achieved. But since the
cumulative value of all coins equals 14, i.e., exceeds 13, this is not the answer.
Input Format:
o A single integer value.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Output Format:
o Four space separated integer values.
1st – Total number of coins.
2nd – number of 5 Rupee coins.
3rd – number of 2 Rupee coins.
4th – number of 1 Rupee coins.
Constraints:
o 0 < n < 1000
Sample Input
13
Sample Output
6132
Explanation
Using these coins, we can form any value with in the given value and itself, like below:
29.Football League Table Statement : All major football leagues have big league tables.
Whenever a new match is played, the league table is updated to show the current rankings (based
on Scores, Goals For (GF), Goals Against (GA)). Given the results of a few matches among
teams, write a program to print all the names of the teams in ascending order (Leader at the top
and Laggard at the bottom) based on their rankings.
Rules:
A win results in 2 points, a draw results in 1 point an
d a loss is worth 0 points. The team with the most goals in a match wins the match. Goal
Difference (GD) is calculated as Goals For (GF) Goals Against (GA). Teams can play a
maximum of two matches against each other Home and Away matches respectively.
The ranking is decided as follows: Team with maximum points is ranked 1 and minimum points
is placed last Ties are broken as follows Teams with same points are ranked according to Goal
Difference(GD).
If Goal Difference(GD) is the same, the team with higher Goals For is ranked ahead
If GF is same, the teams should be at the same rank but they should be printed in case-insensitive
alphabetic according to the team names. More than 2 matches of same teams, should be
considered as Invalid Input.
A team can’t play matches against itself, hence if team names are same for a given match, it
should be considered Invalid Input
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input Format:
First line of input will contain number of teams (N) Second line contains names of the teams
(Na) delimited by a whitespace character Third line contains number of matches (M) for which
results are available Next M lines contain a match information tuple {T1 T2 S1 S2}, where tuple
is comprised of the following information
Output Format:
Team names in order of their rankings, one team per line OR Print “Invalid Input” where
appropriate.
Constraints:
Example:
Consider 5 teams Spain, England, France, Italy and Germany with the following fixtures:
Match 1: Spain vs. England (2-0) (Spain gets 2 points, England gets 0)
Match 2: England vs. France (1-1) (England gets 1 point, France gets 1)
Match 3: Spain vs. France (0-2) (Spain gets 0 points, France gets 2)
Team Name Matches Played Goals for Goals Against Goal Differen
Spain 2 3 2 1
England 2 1 4 -3
France 2 3 1 2
Italy 0 0 0 0
Germany 0 0 0 0
Since, Italy and Germany are tied for points, goals difference is checked. Both have same, so,
Goals For is checked. Since both are same. Germany and Italy share the 4th rank. Since
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Germany appears alphabetically before Italy, Germany should be printed before Italy. Then the
final result is: France Spain England Germany Italy
Sample Input 1:
5
Spain England France Italy Germany
Spain England 3 0
England France 1 1
Spain France 0 2
Sample Output 1:
France
Spain
England
Germany
Italy
Sample Input 2:
5
Spain England France Italy Germany
Spain England 3 0
England France 1 1
Spain Spain 0 2
Sample Output 2:
Invalid Input
30.The parcel section of the Head Post Office is in a mess. The parcels that need to be loaded to
the vans have been lined up in a row in an arbitrary order of weights. The Head Post Master
wants them to be sorted in the increasing order of the weights of the parcels, with one exception.
He wants the heaviest (and presumably the most valuable) parcel kept nearest his office.
You and your friend try to sort these boxes and you decide to sort them by interchanging two
boxes at a time. Such an interchange needs effort equal to the product of the weights of the two
boxes.
Input Format:
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
The first line consists of two space-separated positive integers giving the number of
boxes (N) and the position of the Head Post Masters office (k) where the heaviest box
must be.
The second line consists of N space-separated positive integers giving the weights of the boxes.
You may assume that no two weights are equal
Output Format:
The output is one line giving the total effort taken to get the boxes in sorted order, and the
heaviest in position k.
Constraints:
Sample Input 1:
52
20 50 30 80 70
Sample Output 1:
3600
31.Compute the nearest larger number by interchanging its digits updated.Given 2 numbers a and
b find the smallest number greater than b by interchanging the digits of a and if not possible print
-1.
Input Format
2 numbers a and b, separated by space.
Output Format
A single number greater than b.
Constraints
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Example 1:
Sample Input:
459 500
Sample Output:
549
Example 2:
Sample Input:
645757 457765
Sample Output:
465577
32.Roco is an island near Africa which is very prone to forest fire. Forest fire is such that it
destroys the complete forest. Not a single tree is left.This island has been cursed by God , and the
curse is that whenever a tree catches fire, it passes the fire to all its adjacent tree in all 8
directions,North, South, East, West, North-East, North-West, South-East, and South-West.And it
is given that the fire is spreading every minute in the given manner, i.e every tree is passing fire
to its adjacent tree.Suppose that the forest layout is as follows where T denotes tree and W
denotes water.
Your task is that given the location of the first tree that catches fire, determine how long would it
take for the entire forest to be on fire. You may assume that the lay out of the forest is such that
the whole forest will catch fire for sure and that there will be at least one tree in the forest
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input Format:
First line contains two integers, M, N, space separated, giving the size of the forest in
terms of the number of rows and columns respectively.
The next line contains two integers X,Y, space separated, giving the coordinates of the
first tree that catches the fire.
The next M lines, where ith line containing N characters each of which is either T or W,
giving the position of the Tree and Water in the ith row of the forest.
Output Format:
Single integer indicating the number of minutes taken for the entire forest to catch fire
Constrains:
3 ≤ M ≤ 20
3 ≤ N ≤ 20
Sample Input 1:
33
WTT
TWW
WTT
Sample Output 1:
Explanation:
In the second minute,tree at (1,2) catches fire,in the third minute,the tree at (2,1) catches
fire,fourth minute tree at (3,2) catches fire and in the fifth minute the last tree at (3,3) catches
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
fire.
Sample Input 2:
66
16
WTTTTT
TWWWWW
WTTTTT
WWWWWT
TTTTTT
TWWWWW
Sample Output 2:
16
33.Here on earth, our 24-hour day is composed of two parts, each of 12hours. Each hour in each
part has a corresponding hour in the other partseparated by 12 hours: the hour essentially
measures the duration sincethe start of the day part. For example, 1 hour in the first part of the
day is equivalent to 13, which is 1 hour into the second part of the day.Now, consider the
equivalent hours that are both prime numbers.
5~17
7~19
11~23
Accept two natural numbers D, P >1 corresponding respectively to numberof hours per day and
number of parts in a day separated by a space. D should be divisible by P, meaning that the
number of hours per part (D/P) should be a natural number. Calculate the number of instances of
equivalent prime hours. Output zero if there is no such instance.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Note – That we require each equivalent hour in each part in a day to be a prime number.
Example:
Input:
24 2
Output:
3 (We have 3 instances of equivalent prime hours: 5~17, 7~19 and 11~23.)
Constraints:
Input:
Single line consists of two space separated integers, D and P corresponding to number of
hours per day and number of parts in a day respectively.
Output:
Time Limit:
1
Examples
Example 1
Input
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
36 3
Output
Explanation
2~14~X
3~15~X
11~23~X
34.In this 3 Palindrome, Given an input string word, split the string into exactly 3 palindromic
substrings. Working from left to right, choose the smallest split for the first substring that still
allows the remaining word to be split into 2 palindromes. Similarly, choose the smallest second
palindromic substring that leaves a third palindromic substring.
If there is no way to split the word into exactly three palindromic substrings, print “Impossible”
(without quotes). Every character of the string needs to be consumed.
After finding 3 palindromes using above instructions, if any character of the original
string remains unconsumed.
No character may be shared in forming 3 palindromes.
Constraints
Input
First line contains the input string consisting of characters between [a-z].
Output
Time Limit
Examples
Example 1
Input
nayannamantenet
Output
nayan
naman
tenet
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Explanation
The original string can be split into 3 palindromes as mentioned in the output.
However, if the input was nayanamantenet, then the answer would be “Impossible”.
35.Dr. Vishnu is opening a new world class hospital in a small town designed to be the first
preference of the patients in the city. Hospital has N rooms of two types – with TV and without
TV, with daily rates of R1 and R2 respectively.
However, from his experience Dr. Vishnu knows that the number of patients is not constant
throughout the year, instead it follows a pattern. The number of patients on any given day of the
year is given by the following formula –
(6-M)^2 + |D-15| ,
where M is the number of month (1 for jan, 2 for feb …12 for dec) and D is the date (1,2…31).
All patients prefer without TV rooms as they are cheaper, but will opt for with TV rooms only if
without TV rooms are not available. Hospital has a revenue target for the first year of operation.
Given this target and the values of N, R1 and R2 you need to identify the number of TVs the
hospital should buy so that it meets the revenue target. Assume the Hospital opens on 1st Jan and
year is a non-leap year.
Constraints
Input Format
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
First line provides an integer N that denotes the number of rooms in the hospital
Second line provides two space-delimited integers that denote the rates of rooms with TV
(R1) and without TV (R2) respectively
Third line provides the revenue target
Output
Minimum number of TVs the hospital needs to buy to meet its revenue target. If it cannot
achieve its target, print the total number of rooms in the hospital.
Test Case
Example-1 :
Input
20
1500 1000
7000000
Output
14
Explanation
Using the formula, the number of patients on 1st Jan will be 39, on 2nd Jan will be 38 and so on.
Considering there are only twenty rooms and rates of both type of rooms are 1500 and 1000
respectively, we will need 14 TV sets to get revenue of 7119500. With 13 TV sets Total revenue
will be less than 7000000
During the battle of Mahabharat, when Arjuna was far away in the battlefield, Guru Drona made
a Chakravyuha formation of the Kaurava army to capture Yudhisthir Maharaj. Abhimanyu,
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
young son of Arjuna was the only one amongst the remaining Pandava army who knew how to
crack the Chakravyuha. He took it upon himself to take the battle to the enemies.
Abhimanyu knew how to get power points when cracking the Chakravyuha. So great was his
prowess that rest of the Pandava army could not keep pace with his advances. Worried at the rest
of the army falling behind, Yudhisthir Maharaj needs your help to track of Abhimanyu’s
advances. Write a program that tracks how many power points Abhimanyu has collected and
also uncover his trail.
A Chakravyuha has a very well-defined co-ordinate system. Each point on the co-ordinate
system is manned by a certain unit of the army. The Commander-In-Chief is always located at
the center of the army to better co-ordinate his forces. The only way to crack the Chakravyuha is
to defeat the units in sequential order.
A Sequential order of units differs structurally based on the radius of the Chakra. The radius can
be thought of as length or breadth of the matrix depicted above. The structure i.e. placement of
units in sequential order is as shown below
The entry point of the Chakravyuha is always at the (0,0) co-ordinate of the matrix above. This is
where the 1st army unit guards. From (0,0) i.e. 1st unit Abhimanyu has to march towards the
center at (2,2) where the 25th i.e. the last of the enemy army unit guards. Remember that he has
to proceed by destroying the units in sequential fashion. After destroying the first unit,
Abhimanyu gets a power point. Thereafter, he gets one after destroying army units which are
multiples of 11. You should also be a in a position to tell Yudhisthir Maharaj the location at
which Abhimanyu collected his power points.
Input Format:
First line of input will be length as well as breadth of the army units, say N.
Output Format:
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Print NxN matrix depicting the placement of army units with unit numbers delimited by
(\t) Tab character
Print total power points collected
Print coordinates of power points collected in sequential fashion (one per line )
Constraints:
Sample Input:
Sample Output:
12345
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
(0,0)
(4,2)
(3,2)
Sam is an eligible bachelor. He decides to settle down in life and start a family. He goes bride
hunting.He wants to marry a girl who has at least one of the 8 qualities mentioned below:-
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
He is in search of a bride who has some or all of the 8 qualities mentioned above. On bride
hunting, he may find more than one contenders to be his wife.
In that case, he wants to choose a girl whose house is closest to his house. Find a bride for Sam
who has maximum qualities. If in case, there are more than one contenders who are at equal
distance from Sam’’s house; then
Given a Matrix N*M, Sam’s house is at (1, 1). It is denoted by 1. In the same matrix, the location
of a marriageable Girl is also denoted by 1. Hence 1 at location (1, 1) should not be considered
as the location of a marriageable Girl’s location.
The qualities of that girl, as per Sam’’s criteria, have to be decoded from the number of non-zero
neighbors (max 8-way) she has. Similar to the condition above, 1 at location (1, 1) should not be
considered as the quality of a Girl. See Example section to get a better understanding.
Find Sam, a suitable Bride and print the row and column of the bride, and find out the number of
qualities that the Bride possesses.
NOTE: – Distance is calculated in number of hops in any direction i.e. (Left, Right, Up, Down
and Diagonal)
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Constraints
Input Format
First Line contains the row (N) and column (M) of the houses.
Next N lines contain the data about girls and their qualities.
Output
It will contain the row and column of the bride, and the number of qualities that Bride
possess separated by a colon (i.e. :).
Explanation
Example 1
Input:
29
101101111
000101001
Output:
1:7:3
Explanation:
The girl who is closest to Sam’s house is at (1,7). Hence, she is the bride.
36.Given an array of integers, perform atmost K operations so that the sum of elements of final
array is minimum. An operation is defined as follows –
Constraints
1 <= N
K <= 10^5.
Input
First line contains two integers N and K representing size of array and maximum
numbers of operations that can be performed on the array respectively.
Second line contains N space separated integers denoting the elements of the array, arr.
Output
Print a single integer denoting the minimum sum of the final array.
Input
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
43
20 7 5 4
Output
17
Explanation
37.Given schedule of trains and their stoppage time at a Railway Station, find minimum number
of platforms needed.
Note –
If Train A’s departure time is x and Train B’s arrival time is x, then we can’t
accommodate Train B on the same platform as Train A.
Constraints
Input
Output
Example 1
Input
10 2
5 10
13 5
Output
Explanation
The earliest arriving train at time t = 5 will arrive at platform# 1. Since it will stay there till t =
15, train arriving at time t = 10 will arrive at platform# 2. Since it will depart at time t = 12,
train arriving at time t = 13 will arrive at platform# 2.
Constraints
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input
First line contains two integers N and K where N is size of the array and K is a number as
described above.
Second line contains N integers separated by space.
Output
Example 1
Input
63
5 5 7 9 15 2
Output
Explanation
Other than number 15, everyone has at least 1 element in the range [X-3, X+3]. Hence they are
all happy elements. Since these five are in number, the output is 5.
39.Given a string consisting of lower case English alphabets, the task is to find the number of
distinct subsequences of the string
Note: Answer can be very large, so, ouput will be answer modulo 109+7.
Example 1:
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input:
s = "gfg"
Output:
7
Explanation:
The seven distinct subsequences are "", "g", "f", "gf", "fg", "gg" and "gfg" .
Example 2:
Input:
s = "ggg"
Output:
4
Explanation:
The four distinct subsequences are "", "g", "gg", "ggg".
Your task:
You do not need to read any input or print anything. The task is to complete the
function distinctSubsequences(), which takes a string as input and returns an integer.
Constraints:
1 ≤ |s| ≤ 105
s contains lower case English alphabets
40.Given an array of size N-1 such that it only contains distinct integers in the range of 1 to N.
Find the missing element.
Example 1:
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input:
N=5
A[] = {1,2,3,5}
Output: 4
41.Given an array a of size N which contains elements from 0 to N-1, you need to find all the
elements occurring more than once in the given array. Return the answer in ascending order. If
no such element is found, return list containing [-1].
Note: The extra space is only for the array to be returned. Try and perform all operations within
the provided array.
Example 1:
Input:
N=4
a[] = {0,3,1,2}
Output:
-1
42.Problem Statement – An automobile company manufactures both a two wheeler (TW) and a
four wheeler (FW). A company manager wants to make the production of both types of vehicle
according to the given data below:
The task is to find how many two-wheelers as well as four-wheelers need to manufacture as per
the given data.
Example :
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Input :
200 -> Value of V
540 -> Value of W
Output :
TW =130 FW=70
Explanation:
130+70 = 200 vehicles
(70*4)+(130*2)= 540 wheels
Constraints :
2<=W
W%2=0
V<W
43.At a fun fair, a street vendor is selling different colours of balloons. He sells N number of
different colours of balloons (B[]). The task is to find the colour (odd) of the balloon which is
present odd number of times in the bunch of balloons.
Note: If there is more than one colour which is odd in number, then the first colour in the array
which is present odd number of times is displayed. The colours of the balloons can all be either
upper case or lower case in the array. If all the inputs are even in number, display the message
“All are even”.
Example 1:
7 -> Value of N
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
[r,g,b,b,g,y,y] -> B[] Elements B[0] to B[N-1], where each input element is sepārated by
ṉew line.
Output :
r -> [r,g,b,b,g,y,y] -> “r” colour balloon is present odd number of times in the bunch.
Explanation:
From the input array above:
r: 1 balloon
g: 2 balloons
b: 2 balloons
y : 2 balloons
Hence , r is only the balloon which is odd in number.
2.Example 2:
Input:
10 -> Value of N
[a,b,b,b,c,c,c,a,f,c] -> B[], elements B[0] to B[N-1] where input each element is separated
by new line.
Output :
b-> ‘b’ colour balloon is present odd number of times in the bunch.
Explanation:
From the input array above:
a: 2 balloons
b: 3 balloons
c: 4 balloons
f: 1 balloons
Here, both ‘b’ and ‘f’ have odd number of balloons. But ‘b’ colour balloon occurs first.
Hence , b is the output.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Constraints:
3<=N<=50
B[i]={{a-z} or {A-Z}}
44.There is a JAR full of candies for sale at a mall counter. JAR has the capacity N, that is JAR
can contain maximum N candies when JAR is full. At any point of time. JAR can have M
number of Candies where M<=N. Candies are served to the customers. JAR is never remain
empty as when last k candies are left. JAR if refilled with new candies in such a way that JAR
get full.
Write a code to implement above scenario. Display JAR at counter with available number of
candies. Input should be the number of candies one customer can order at point of time. Update
the JAR after each purchase and display JAR at Counter.
Output should give number of Candies sold and updated number of Candies in JAR.
K =< 5, where k is number of minimum candies that must be inside JAR ever.
Example 1:(N = 10, k =< 5)
Input Value
3
Output Value
NUMBER OF CANDIES SOLD : 3
NUMBER OF CANDIES AVAILABLE : 7
Input Value
0
Output Value
INVALID INPUT NUMBER OF
CANDIES LEFT : 10
Display the most fit trainee (or trainees) and the highest average oxygen level.
Note:
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
The oxygen value entered should not be accepted if it is not in the range between 1
and 100.
If the calculated maximum average oxygen value of trainees is below 70 then declare the
trainees as unfit with meaningful message as “All trainees are unfit.
Average Oxygen Values should be rounded.
Example 1:
INPUT VALUES
95
92
95
92
90
92
90
92
90
OUTPUT VALUES
Trainee Number : 1
Trainee Number : 3
Note:
Input should be 9 integer values representing oxygen levels entered in order as
Round 1
Round 2
Round 3
Output must be in given format as in above example. For any wrong input final output
should display “INVALID INPUT”
46.Problem Statement
A washing machine works on the principle of Fuzzy System, the weight of clothes put inside it
for washing is uncertain But based on weight measured by sensors, it decides time and water
level which can be changed by menus given on the machine control area.
For low level water, the time estimate is 25 minutes, where approximately weight is between
2000 grams or any nonzero positive number below that.
For medium level water, the time estimate is 35 minutes, where approximately weight is between
2001 grams and 4000 grams.
For high level water, the time estimate is 45 minutes, where approximately weight is above 4000
grams.
Write a function which takes a numeric weight in the range [0,7000] as input and produces
estimated time as output is: “OVERLOADED”, and for all other inputs, the output statement is
“INVALID INPUT”.
Example:
Input value
2000
Output value
Time Estimated: 25 minutes
47.We want to estimate the cost of painting a property. Interior wall painting cost is Rs.18
per sq.ft. and exterior wall painting cost is Rs.12 per sq.ft.
Take input as
1. Number of Interior walls
2. Number of Exterior walls
3. Surface Area of each Interior 4. Wall in units of square feet
Surface Area of each Exterior Wall in units of square feet
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
If a user enters zero as the number of walls then skip Surface area values as User may
don’t want to paint that wall.
48.Problem Statement
There are total n number of Monkeys sitting on the branches of a huge Tree. As travelers offer
Bananas and Peanuts, the Monkeys jump down the Tree. If every Monkey can eat k Bananas and
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
j Peanuts. If total m number of Bananas and p number of Peanuts are offered by travelers,
calculate how many Monkeys remain on the Tree after some of them jumped down to eat.
At a time one Monkeys gets down and finishes eating and go to the other side of the road. The
Monkey who climbed down does not climb up again after eating until the other Monkeys finish
eating.
Monkey can either eat k Bananas or j Peanuts. If for last Monkey there are less than k Bananas
left on the ground or less than j Peanuts left on the ground, only that Monkey can eat
Bananas(<k) along with the Peanuts(<j).
Write code to take inputs as n, m, p, k, j and return the number of Monkeys left on the Tree.
Where, n= Total no of Monkeys
k= Number of eatable Bananas by Single Monkey (Monkey that jumped down last may get
less than k Bananas)
j = Number of eatable Peanuts by single Monkey(Monkey that jumped down last may get
less than j Peanuts)
m = Total number of Bananas
p = Total number of Peanuts
Remember that the Monkeys always eat Bananas and Peanuts, so there is no possibility of k and j
having a value zero
Example 1:
Input Values
20
2
3
12
12
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Output Values
Number of Monkeys left on the tree:10
Note: Kindly follow the order of inputs as n,k,j,m,p as given in the above example. And output
must include the same format as in above example(Number of Monkeys left on the Tree:)
For any wrong input display INVALID INPUT
49.Problem Statement
Coffee
1. Espresso Coffee
2. Cappuccino Coffee
3. Latte Coffee
Tea
1. Plain Tea
2. Assam Tea
3. Ginger Tea
4. Cardamom Tea
5. Masala Tea
6. Lemon Tea
7. Green Tea
8. Organic Darjeeling Tea
Soups
Beverages
Write a program to take input for main menu & sub menu and display the name of sub
menu selected in the following format (enter the first letter to select main menu):
Welcome to CCD
Enjoy your
Example 1:
Input:
c
1
Output
Welcome to CCD!
Enjoy your Espresso Coffee!
Example 2:
Input:
t
9
Output
INVALID OUTPUT!
MCQ
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
1. A data type is stored as a 6 bit signed integer. Which of the following cannot be represented
by this data type?
A. -12
B. 5
C. 25
D. 32
View Answer
Ans : D
Explanation: 2^6 = 64. So you can represent 64 values. This means 0 to 63 for unsigned integer
and -32 to 31 for signed integer (twos complement).
Explanation: A function is a piece of code that is called by name. It can be passed data to operate
on and can optionally return data. All data that is passed to a function is explicitly passed.
int main()
int a=5,b=7
switch(a)
break
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
break;
default:printf(""I am different"");
return 0;
A. I am 5
B. I am not 5
C. I am different
D. Error
View Answer
Ans : D
Explanation: This program will generate an error as the break statement does not end with an
semi-colon in case 5.
A. 0
B. -1
C. 1
D. infinite
View Answer
Ans : B
A. Subscripted variable
B. Ordinary variable
C. Similar Quantities variable
D. Collective array
View Answer
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Ans : A
Explanation: All elements refer to the same name.That is each element can be identified with the
same name including different index value(subscript value). Hence,an array is also called as a
Subscripted variable.
#include
void main()
static int i;
A. Zero
B. 1
C. Garbage Value
D. Runtime Error
View Answer
Ans : A
Explanation: Since i is declared as static variable and the default value is zero for static variables.
A. break
B. goto
C. continue
D. return
View Answer
Ans : C
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
Explanation: Continue is used to skip current block of statements for one iteration and to jump to
the beginning of the loop for condition checking so that it can begin next iteration. Break
however is to exit from the loop and directly go to the end of the loop.
A. float
B. unsigned long int
C. double
D. long int
View Answer
Ans : C
A. Not possible
B. By implementing union
C. Structure data type
D. Both B and C
View Answer
Ans : D
Explanation: Union and structure are the special data type that allows to store different data types
in the same memory
A. imperative polymorphism
B. adhoc polymorphism
C. predicative polymorphism
D. inclusion polymorphism
View Answer
Ans : A
11. Tricha wants to store a list of binary data.Which of following data types should she use?
A. Boolean
B. Integer
C. Character
D. Floating
View Answer
Ans : A
Explanation: As boolean can store only two values(i.e, 1 and 0), so tricha can store a list of
binary data in boolean datatype.
12. Which of the following accessibility modes can be the specifier of a top level class’ ?
A. only private
B. protected and private
C. public and no modifier
D. only no modifer
View Answer
Ans : C
Explanation: Top-level classes can only have public, abstract, and final modifiers, and it is also
possible to not define any class modifiers at all. This is called default/package accessibility.
Besides that, private, protected, and static modifiers cannot be used when declaring top-level
classes.
A. Switch Case
B. Loop
C. If-else
D. None
View Answer
Ans : B
Explanation: In recursion, the function will call itself until the base condition is not true. So,
Recursion is similar to a loop and it will call itself until the base condition is not true.
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
14. A mode which is used to open an existing file for both reading and writing ______
A. "W"
B. "W+"
C. "R+"
D. "A+"
View Answer
Ans : C
Explanation: R+ mode is used to open an existing fiel for both reading and writing.
A. Subscripted variable
B. Collective array
C. Ordinary variable
D. Similar Quantites variable
View Answer
Ans : A
Explanation: All elements refer to the same name.That is each element can be identified with the
same name including different index value(subscript value). Hence,an array is also called as a
Subscripted variable.
Explanation: Within the block, it appear and Within the blocks of the block it appears.
17. The following code ‘for(;;)’ represents an infinite loop. It can be terminated by.
A. break
B. exit(0)
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
C. abort()
D. all of the mentioned
View Answer
Ans : A
Explanation: If we write the break statement inside the infinite loop it will terminate the infinite
loop.
A. Array of pointers
B. pointer to a character array
C. Array of character pointers
D. Array of Strings
View Answer
Ans : C
Explanation: argv(Argument Vector) is array of character pointers listing all the arguments. If
argc is greater than zero,the array elements from argv[0] to argv[argc-1] will contain pointers to
strings. Argv[0] is the name of the program , After that till argv[argc-1] every element is
command -line arguments.
Explanation: The call to an overloaded function can be ambiguous if the two or more functions
have the same name and same function signature.
20. What type of method is used to place a method onto the top of the Stack.
A. pop()
B. push()
JAI SHRIRAM ENGINEERING COLLEGE
TIRUPPUR – 638 660
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai
Recognized by UGC & Accredited by NAAC and NBA (CSE and ECE)
C. Evaluation()
D. Create()
View Answer
Ans : B
Explanation: when we want to add or place something in the stack so we need to perform push()
operation.