Codevita PDF
Codevita PDF
Programming languages available are:C, C++, C#, Java, PHP, Perl, Python, Ruby
3) Grand Finale:
This round will be held in one of the TCSL offices in India. Top 3 contestants will be declared as winners of the contest. The grand
finale is tentatively scheduled to be conducted in the last week of February 2021.
Each round is followed by an interview, you can proceed to the next round, only after you have cleared the interview. The interview
is conducted on the basis of your previous round only, where they ask you questions based upon the answers and techniques which
you have used in the previous round. There is no surety that you will get qualified for the next round if you have solved all the
questions, or will not be qualified for the next round if you have solved only 3 questions, it is solely based upon the programming
techniques you are using, and your interview.
There is no particular syllabus as defined by TCS CodeVita Team, however, you can expect the coding problems from following
topics, in round-1 :
Greedy Algorithm
Stack
Queue
Mapping Concepts
Array manipulation
String manipulation
Tree
Dynamic Programming
BackTracking
Graph
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)
Constraints
2 <= N,M <= 10^2
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 and qualities are present at (1,3),(1,4),(1,6),(1,7),(1,8),(1,9),(2,4),(2,6),(2,9).
The girl present at (1,3) has 2 qualities (i.e. (1,4)and (2,4)).
As we see, there are two contenders who have maximum qualities, one is at (1,7) and another at (1,8).
The girl who is closest to Sam's house is at (1,7). Hence, she is the bride.
Hence, the output will be 1:7:3.
Example 2
Input:
66
100000
000000
001110
001110
001110
000000
Output:
4:4:8
Explanation:
The bride and qualities are present at (3,3),(3,4),(3,5),(4,3),(4,4),(4,5),(5,3),(5,4),(5,5)
The Bride present at (3,3) has 3 qualities (i.e. (3,4),(4,3) and (4,4)).
As we see, the girl present in (4,4) has maximum number of Qualities. Hence, she is the bride.
Hence, the output will be 4:4:8.
Telegram: @CareerClimbers or
http://t.me/CareerClimbers
Skateboard
Problem Description
The amusement park at Patagonia has introduced a new skateboard competition. The skating surface is a grid of N x N squares. Most
squares are so constructed with slopes that it is possible to direct the skateboard in any of up to three directions of the possible four
(North ,East, South or West, represented by the letters N, E, S and W respectively). Some squares however have a deep drop from
the adjacent square from which it is impossible to go to any adjacent square. These are represented by D (for Drop) in that square.
The objective is to maneuver the skateboard to reach the South East corner of the grid, marked F.
Each contestant is given a map of the grid, which shows where the Drop squares are (marked D), where the Final destination is
(marked F), and, for each other square, the directions it is possible to maneuver the skateboard in that square.
The contestant draws lots to determine which of the squares on the boundaries of the grid on the North or the West of the grid (the
top or the left in the diagram) he or she should start in. Then, using a map of the grid, he or she needs to try to reach the South East
corner destination by maneuvering the skateboard.
.
In some cases, it is impossible to reach the destination. For example, in the diagram above, if one starts at the North East corner (top
right in the diagram), the only way is to go is South, until the Drop square is reached (three squares South), and the contestant is stuck
there.
A contestant asks you to figure out the number of squares at the North or West boundary (top or left boundary in the map) from which
it is feasible to reach the destination.
Constraints
5<=N<=50
Input Format
The first line of the input is a positive integer N, which is the number of squares in each side of the grid.
The next N lines have a N strings of characters representing the contents of the map for that corresponding row. Each string may be
F, representing the Final destination, D, representing a drop square, or a set of up to three of the possible four directions (N,E,S,W)
in some random order. These represent the directions in which the contestant can maneuver the skateboard when in that square.
Output
The output is one line with the number of North or West border squares from which there is a safe way to maneuver the skateboard
to the final destination.
Explanation
Example 1
Input
6
ES,ES,SE,ES,ES,S
SE,ES,SE,ES,ES,S
ES,ES,SE,ES,SE,S
ES,SE,ES,SE,E,D
SE,ES,D,WSE,NES,NS
E,E,NE,E,E,F
Output
9
Explanation
N =6, and the size of the grid is 6x6. The map of the grid is as below.
There are many ways to maneuver the skateboard. For example, if the contestant starts from the North West corner (top left in the
map) and goes East all the way until he reaches the top right corner in the map, and then goes South, he will reach a Drop square. But
if he goes South all the way from the same square until he reaches the bottom left square on the map, and keeps going East from
there, the Final destination will be reached. Hence the top left square (1,1) is safe.
Similarly, from the square (1,5), all the paths lead to a drop square., The other 9 North and West border squares have ways skateboard
to get to the final destination. The output is 9
Example 2
Input
5
ES,SE,ES,SE,S
S,EWS,SE,E,S
E,D,SEW,NSE,S
NE,N,SEW,D,W
EN,EN,E,EN,F
Output
4
Explanation
N=5, and the grid is 5 x 5 squares. The map of the grid looks like this.
It can be seen that from squares (1,4) and (1,5), there is no way to maneuver the skateboard to the Final destination, and hence are
not safe starting points.. Similarly, squares (2,1),(3,1), and (4,1) are not safe starting points. The only safe starting points on the North
and West borders are (1,1),(1,2),(1,3),(5,1). Hence the output is 4
ESESSEESESS
SEESSEESESS
ESESSEESSES
ESSEESSEED
SEESDWSENESNS
EENEEEF
ESSEESSES
SEWSSEES
EDSEWNSES
NENSEWDW
ENENEENF
Telegram: @CareerClimbers or
http://t.me/CareerClimbers
Cross Words
Problem Description
A crossword puzzle is a square grid with black and blank squares, containing clue numbers (according to a set of rules) on some of
the squares. The puzzle is solved by obtaining the solutions to a set of clues corresponding to the clue numbers.
The solved puzzle has one letter in each of the blank square, which represent a sequence of letters (consisting of one or more words
in English or occasionally other languages) running along the rows (called “Across”, or “A”) or along the columns (called “Down”
or “D”). Each numbered square is the beginning of an Across solution or a Down solution. Some of the across and down solutions
will intersect at a blank square, and if the solutions are consistent, both of them will have the same letter at the intersecting square.
In this problem, you will be given the specifications of the grid, and the solutions in some random order. The problem is to number
the grid appropriately, and associate the answers consistently with the clue numbers on the grid, both as Across solutions and as Down
solutions, so that the intersecting blank squares have the same letter in both solutions.
Constraints
5<=N<=15
5<=M<=50
Input Format
The input consists of two parts, the grid part and the solution part
The first line of the grid part consists of a number, N, the size of the grid (the overall grid is N x N) squares. The next N lines
correspond to the N rows of the grid. Each line is comma separated, and has number of pairs of numbers, the first giving the position
(column) of the beginning of a black square block, and the next giving the length of the block. If there are no black squares in a row,
the pair “0,0” will be specified. For example, if a line contains “2,3,7,1,14,2”, columns 2,3,4 (a block of 3 starting with 2), 7 (a block
of 1 starting with 7) and 14,15 (a block of 2 starting with 14) are black in the corresponding row.
The solution part of the input appears after the grid part. The first line of the solution part contains M, the number of solutions. The
M subsequent lines consist of a sequence of letters corresponding to a solution for one of the Across and Down clues. All solutions
will be in upper case (Capital letters)
Output
The output is a set of M comma separated lines. Each line corresponds to a solution, and consists of three parts, the clue number, the
letter A or D (corresponding to Across or Down) and the solution in to that clue (in upper case)
The output must be in increasing clue number order. Ifa clue number has both an Across and a Down solution, they must come in
separate lines, with the Across solution coming before the Down solution.
Explanation
Example 1
Input
5,1
1,1,3,1,5,1
0,0
1,1,3,1,5,1
1,1
EVEN
ACNE
CALVE
PLEAS
EVADE
Output
1,A,ACNE
2,D,CALVE
3,D,EVADE
4,A,PLEAS
5,A,EVEN
Explanation N is 5, and the disposition of the black squares are given in the next 5 (N) lines. The grid looks like this
The solutions are fitted to the grid so that they are consistent, and the result is shown below. Note that this is consistent, because the
letter at each intersecting blank square in the Across solution and the Down solution.
Based on this the output is given in clue number order. 1 Across is ACNE, and hence the first line of the output is 1,A,ACNE. The
same logic gives all the remaining solutions.
Example 2
Input
1,1
1,1,3,2
0,0
1,1,3,2
0,0
ASIAN
RISEN
FEAR
CLAWS
FALLS
Output
1,A,FEAR
1,D,FALLS
2,D,RISEN
3,A,CLAWS
4,A,ASIAN
Explanation
N=5, and the grid looks like this
M=5, and the 5 solutions are given
The numbered grid looks like this
The consistently populated grid (with the solutions) look like this
The output can be easily given from this. Note that clue number 1 has both an Across solution (FEAR) and a DOWN solution
(FALLS). The Across solution must precede the Down solution in the output.
Telegram: @CareerClimbers or
http://t.me/CareerClimbers
Bank Compare
Problem Description
There are two banks; Bank A and Bank B. Their interest rates vary. You have received offers from both bank in terms of annual rate
of interest, tenure and variations of 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
1 <= P <= 1000000
1 <=T <= 50
1<= N1 <= 30
1<= N2 <= 30
Input Format
First line : P – principal (Loan Amount)
Second line : T – Total Tenure (in years).
Third Line : N1 is number of slabs of interest rates for a given period by Bank A. First slab starts from first year and second slab
starts from end of first slab and so on.
Next N1 line will contain the interest rate and their period.
After N1 lines we will receive N2 viz. the number of slabs offered by second bank.
Next N2 lines are number of slabs of interest rates for a given period by Bank B. First slab starts from first year and second slab starts
from end of first slab and so on.
Output
Your decision – either Bank A or Bank B.
Explanation
Example 1
Input
10000
20
3
5 9.5
10 9.6
5 8.5
3
10 6.9
5 8.5
5 7.9
Output
Bank B
Example 2
Input
500000
26
3
13 9.5
3 6.9
10 5.6
3
14 8.5
6 7.4
6 9.6
Output
Bank B
Before opening the park, club authority decides to calculate Safety index of the park. The procedure of the calculation is described
below. Please help them to calculate.
Safety Index calculation
Assume a person stands on grassland(x) and a Smilodon escapes from the cage situated on grassland(y). If the person can escape from
any of those three gates before the Smilodon able to catch him, then the grassland(x) is called safe else it is unsafe. A person and a
Smilodon both take 1 second to move from one area to another adjacent area(top, bottom, left or right) but a person can move only
over grasslands though Smilodon can move over grasslands and mountains.
If any grassland is unreachable for Smilodon(maybe it is unreachable for any person also), to increase safe index value Club Authority
use to mark those grasslands as safe land. Explained below
Input Format
The first line of the input contains two space-separated integers R and C, denoting the size of the park (R*C)
The second line contains eight space-separated integers where
First two integers represent the position of the first gate
Output
Safety Index accurate up to two decimal places using Half-up Rounding method
Explanation
Example 1
Input
44
11213113
GGGG
GWWM
GGWW
MGMM
Output
75.00
Explanation
G G G G
G W WM
G G WW
MG M M
Mountains 4
Waters 4
Cage Pos.-unsafe 1
Input
46
16364634
WMGGGG
MGWGMM
GWGGGG
WGWMWG
Output
69.23
Constraints
1 <= Length of original string <= 30
1<= q <= 10
Output
YES or NO
Explanation
Example 1
Input
carrace
3
L2
R2
L3
Output
NO
Explanation
After applying all the rotations the FIRSTCHARSTRING string will be "rcr" which is not anagram of any sub string of original
string "carrace".
Telegram: @CareerClimbers or
http://t.me/CareerClimbers
Chakravyuha
Problem Statement
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, 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 hel p
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 la st of the enemy
army unit guards. Remember that he has to proceed by destroying the units in sequential fashion. After destroying the first u nit,
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:
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)
12
1 2 43
Total Power points : 1
(0,0)
12345
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
2 5
13 12 11 10 9
Total Power points : 3
(0,0)
(4,2)
(3,2)
Telegram: @CareerClimbers or
http://t.me/CareerClimbers
Exam Efficiency
In an examination with multiple choice questions, the following is the exam question pattern.
X1 number of One mark questions, having negative score of -1 for answering wrong
X2 number of Two mark questions, having negative score of -1 and -2 for one or both options wrong
X3 number of Three mark questions, having negative score of -1, -2 and -3 for one, two or all three options wrong
Score Required to Pass the exam : Y
For 1,2 and 3 mark questions, 1,2 and 3 options must be selected. Simply put, once has to attempt to answer all
questions against all options.
Identify the minimum accuracy rate required for each type of question to crack the exam.
Calculations must be done up to 11 precision and printing up to 2 digit precision with ceil value
Input Format:
First line contains number of one mark questions denoted by X1,
Second line contains number of two mark questions denoted by X2
Third line contains number of three mark questions denoted by X3
Fourth line contains number of marks required to pass the exam denoted by Y.
Output Format:
Minimum Accuracy rate required for one mark question is 80%
Minimum Accuracy rate required for Two mark question is 83.33%
Minimum Accuracy rate required for Three mark question is 90%
Note: - If the mark required to pass the exam can be achieved by attempting without attempting any particular type of question
then show message similar to, One mark question need not be attempted, so no minimum accuracy rate applicable
See Example Test cases for better understanding.
Calculate the Final Salary & Final Accumulated PF of an Employee working in ABC Company Pvt. Ltd. The Company gives
two Increments (i.e. Financial Year Increment & Anniversary Increment) to an Employee in a Particular Year.
The Employee must have Completed 1 Year to be Eligible for the Financial Year Increment. The Employee who are joining in
the month of Financial Year Change (i.e. April) are considered as the Luckiest Employee's, because after completion of 1 Year,
From 4th Year, the Financial Year Increment will be revised to 9%.
From 8th Year, the Financial Year Increment will be revised to 6%.
The Company is giving special Increment for the Employee who have completed 4 years & 8 years respectively.
So, the Anniversary Increment of the Employee for the 4th Year will be 20% and the Anniversary Increment of the Employee for
Calculate the Final Salary after N number of Years as well as Calculate the Accumulated PF of the Employee after N number of
Years.
Please Note that, the Rate of Interest for calculating PF for a Particular Month is 12%. Moreover, take the upper Limit of th e
amount if it is in decimal (For e.g. - If any Amount turns out to be 1250.02, take 1251 for the Calculation.)
Input Format:
2. Current CTC.
Output Format:
1. Salary after the Specified Number of Years (i.e. CTC after N number of Years) in the following format
Final Salary =
Final Accumulated PF =
Constraints:
1. Calculation should be done upto 11 digit precision and output should be printed with ceil value
5
1 01/01/2016 Final Salary = 13924
10000 Final Accumulated PF = 2655
2
19/01/2016
2 Final Salary = 14718
6500
Final Accumulated PF = 4343
4
The group stage of ISL features N teams playing against each other with following set of rules:
1. N teams play against each other twice - once at Home and once Away
4. A team cannot play more than two back to back Home or Away matches
Day 3 has two matches and Day 4 has one match and so on
6. Gap between two successive matches of a team cannot exceed floor(N/2) days where floor is the mathematical function
floor()
Input Format:
Output Format:
Constraints:
Note :
Derby is a football match between two teams from the same state
#1 T1-vs-T6 T3-vs-T5
1 8
#2 T7-vs-T4
12543166
#3... and so on
Note:- There can be multiple correct answers for the same test cases.
Explanation:
Input Format:
1. First line contains 2 numbers delimited by whitespace where, first number M is number of rows and second number N is
number of columns
2. Second line contains number of hurdles H followed by H lines, each line will contain one hurdle point in the matrix.
Output Format:
Output should display the length of the longest route from point A to point B in the matrix.
Constraints:
3. A route will only consider adjacent hops. The route cannot consist of diagonal hops.
5. The values MxN signifies that the matrix consists of rows ranging from 0 to M-1 and columns ranging from 0 to
N-1.
6. If the destination is not reachable or source/ destination overlap with hurdles, print cost as -1
Sample Input and Output
3 10
3 10 3 -- (no. of hurdles )
3 12
12 15
1
15 24 18
18 0 0 -- (position of A)
00 1 7 -- (position of B)
17
So if you examine matrix below shown in Fig 1, total hops
( ->) count is 24. So final answer will be 24. No other route longer
than this one is possible in this matrix.
22
1
2
00 -1 No path is possible in this 2*2 matrix so answer is -1
11
00
Then order for a random number of different drinks, say {A, B, C, D, E, F} of quantities {a, b, c, d, e, f} respectively.
If quantity of any three drinks add up to X then we'll have it else we'll return the order.
2. Next N lines, contain a positive integer corresponding to the size of the beverage
Your task is to help find out if there can be any combination of three beverage sizes that can sum up to the quantity the y intend
Input Format:
2. Next N lines, contains a positive integer A i, the size of the ith bottle
3. Last line contains the quantity they intend to consume denoted by X in text above
Output Format:
Constraints:
N >= 3
Ai > 0
1 <= i <= N
X>0
1 45
True
6
10
22
2 3
False
12
14
The sum of 2nd, 5th and 6th beverage size is equal to 22. So the output will be True.
Explanation for sample input and output 2:
Since no combination of given beverage sizes sum up to X i.e. 14, the output will be False.
Description of game:
2. Since two players are playing the game, they will make their moves alternatively.
a. A player will choose a number from the table and will replace that number with one of its divisor. For example,
6 can be replaced with 1, 2, or 3 (since these are the divisors of 6). Similarly, 12 can be replaced with 1, 2, 3, 4
or 6.
d. As 1 does not have any divisor other than itself, a player cannot replace 1 with any other number. So soon a
situation will arise when there will be only all 1s on the table. In that situation the player will not be able to
make any move. The player who will not be able to make the move, loses.
4. Both the players are masters of this game. So they will play the game optimally.
You will be given N integers that are on the table. You have to predict, who will win the game - Aman or Jasbir.
Input Format:
First line contains information about the numbers present of the table, denoted by N
Output Format:
Print the name of the player who will win the game in upper case i.e. AMAN or JASBIR.
Constraints:
1 <= N <= 100000
A number cannot be replaced itself, i.e. 6 can be replaced with 1, 2 or 3 only , not with 6.
1 1
AMAN
6
2 2
AMAN
18 6
3 4
JASBIR
24 45 45 24
There is only one number placed on the table do AMAN will replace it with 1. Jasbir will play next. As there is only 1 left on the
table. And it cannot be replaced with any other number; he is not able to make any move. So he loses the game.
There are 2 numbers present on the table. Since every move is the optimal move, Aman will replace 18 with 6. Now (6, 6) will
be left on the table. Now, whatever move Jasbir will make. Aman will also make the same move. So whenever Jasbir will
replace any number with 1. In the next move Aman will also replace the other number with 1. So both the numbers will be one
Now, Jasbir WILL NOT BE ABLE TO MAKE ANY MOVE. So, Amanwill WIN.
In this case, game is already symmetric. Aman has to make the first move. So whatever move Aman will make Jasbir will just
repeat the same. So In the Aman will go out of moves and Jasbir will win the game.
Now, Aman WILL NOT BE ABLE TO MAKE ANY MOVE. So, Jasbir will WIN. It is easy to see that just by mimicking
Three friends set out to explore a remote area. They choose a safe place and make it their Base Camp. To speed up exploration
time they decide to work independently. At any given point, either one or more of them can set out to explore the area. They set
a protocol that after exploring the area they must meet back at the Base Camp in the evening and exchange notes.
The remote area consists of accessible and inaccessible pieces of land. Being ordinary humans, they must walk only the
accessible piece of land. In order to maximize their exploration time, each one is interested in knowing about a shortest path
Given that the area under exploration is arranged in form of a rectangular grid, help the explorers to chalk out a shortest p ath
back to the base camp. Properties of a rectangle can be used as heuristic in computing distance between their positions and the
Base Camp. Your task is to find out and mark the shortest path for each explorer and print each path as a separate grid.
The input and output specification sections describe how inputs will be provided on console and how output is expected back on
console.
Input Format:
Output Format:
1. Number of grids in the output should be same as number of explorers i.e. 's' characters in the input grid
2. Each output grid should be of the same dimension as the input grid
3. Each output grid should contain path from explorer location s to base camp location d
4. If there are more than one explorers, explorer with smallest value should be printed first in the output. Next smallest
explorer location should be printed next followed by the last explorer grid.
5. First explorer path should be marked by 'a' character, second by 'b' character and third by 'c' character
6. The 's' character in the grid must be replaced by {a, b or c} whichever is appropriate for the given explorer
7. The 's' character(s) in the grid must be replaced by '-' character for other explorer(s)
Constraints:
1. It is guaranteed that there will always be exactly one shortest path for one explorer from a given location
w-d-
44 waw-
w-d- waww
w-w- a---
1
w-ww w-d-
s--s wbw-
-1 wbww
--bb
a---
44
-a--
s--s
2 --a-
----
---d
----
---b
s--d ---b
-1 ---b
---d
----
----
----
cccd
Figure 1.
Figure 2.
Note: - The output format shown above is for understanding purpose such that it highlights the shortest path between the
explorer and the base camp. The examples in above table depicts output in text format as you will be required to provide.
Telegram: @CareerClimbers or
http://t.me/CareerClimbers
Saving for a rainy day
By nature, an average Indian believes in saving money. Some reports suggest that an average Indian manages to save
approximately 30+% of his salary. Dhaniram is one such hard working fellow. With a view of future expenses, Dhaniram
resolves to save a certain amount in order to meet his cash flow demands in the future.
Dhaniram wants to buy a TV. He needs to pay Rs 2000/- per month for 12 installments to own the TV. If let's say he gets 4%
interest per annum on his savings bank account, then Dhaniram will need to deposit a certain amount in the bank today, such that
he is able to withdraw Rs 2000/- per month for the next 12 months without requiring any additional deposits throughout.
Your task is to find out how much Dhaniram should deposit today so that he gets assured cash flows for a fixed period in the
future, given the rate of interest at which his money will grow during this period.
Input Format:
Third line contains rate per annum R expressed in percentage at which deposited amount will grow
Output Format:
Print total amount of money to be deposited now rounded off to the nearest integer
Constraints:
M>0
T>0
R >= 0
meter in T units of time. On Robot's path there is a ditch at a distance FD from initial position in forward direction as well as a
ditch at a distance BD from initial position in backward direction. This forward and backward movement is per formed
Your task is to calculate amount of time taken, before the Robot falls in either ditch, if at all it falls in a ditch.
Input Format:
F B T FD BD, where
Output Format:
For each test case print time taken by the Robot to fall in the ditch and also state which ditch he falls into. Print F for f orward
OR
Constraints:
3
63 F
1 9 4 3 13 10
25 F
9 7 1 11 13
No Ditch
4 4 3 8 12
5
133 F
8 4 7 11 22
216 B
2 4 5 4 25 6
231 B
4 9 3 6 29
408 B
7 10 6 24 12
9F
10 10 1 9 7
Example:
Company ABC has 25734 shares in the market. The current value of the share is 77 INR. The change in the Share Value from
yesterday is +10(or 10) Today's rating of ABC is 87 (out of 100). The change in rating from yesterday is +2 (or 2). The credit and
risk calculator will work in the following way-
Similarly, company XYZ has 30000 shares in the market. The current value of the share is 90 INR. The change in the Share Value
from yesterday is -15. Today's rating of XYZ is 83 (out of 100). The change in rating from yesterday is -4. The credit and risk
calculator will work in the following way-
PCredit
Change in Previous PCompany Previous PMax Credit
No. Of Share Change Allotted (CA)
Share Share Value Value (CV) Company Rating Company is
Shares Value in Rating = CE *
Value (SV') = SV- =N*min Rating (R) (R')= Eligible for (CE)
(N) (SV) ( CR) (min(R',
(CSV) CSV (SV, SV') R-CR =CV * (50%)
R)/100)
=
= (N*67)
(CE*85/100)
= 1724178.00
= 25734 * 67 *0.5
25734 77 10 67.00 87 2 85.00 = 862089 *
0.85
= = 862089.00
1724178.00
= 732775.65
OR
1 <= T <=100
20000 <= N <= 10000000
20.00 <= SV <= 10000.00 (Note:- This is a numerical constraint only)
-2000.00 <= CSV <= 2000.00 (Note:- This is a numerical constraint only)
0.01 <= R <= 99.99 (Note:- This is a numerical constraint only)
-10.00 <= CR <= 10.00 (Note:- This is a numerical constraint only)
Calculation should be done upto 11-digit precision
The Change in Share Value (CSV) and Change in Rating (CR) are dependent as below:
The values of CV, CE and CA are to be rounded to 2 Decimal Places, always to the Ceiling or Upper Value
The range of the calculated values are-
4
25000
35
5
85
6
20000
30.00
19
79.00
2
750000.00
60
1 375000.00
3
296250.00
25658
Invalid Input
520
Invalid Input
510
Invalid Input
65
3
22000
30
-5
46
6
The car is currently not without defects and hence often hits the wall. The scientists are devising a strategy to prevent this from
happening. Your task is to help the scientists by providing them with exact information on amount of time available before the car
hits the wall.
Input Format:
Output Format:
For each test case print time taken by the Car to hit the wall
Constraints:
First move will always be in backward direction
1 <= N <= 100
backward displacement > forward displacement i.e. (B > F)
forward displacement (F) > 0
backward displacement (B) > 0
time (T) > 0
distance (D) > 0
All input values must be positive integers only
2
1 162
6 9 3 18
220
3 7 5 20
Conversation:-
The Witch : To find the equi pair, you must know how to find the slices first.
Harry : What is a slice?
The Witch : If Z is an array with N elements, a slice of indices (X, Y) is Z[X] + Z[X+1]...Z[Y]
Harry : How can I use it to find equi pair?
The Witch : (a, b) is an equi pair if slice of (0, a-1) = slice of (a+1, b-1) = slice of (b+1, N-1) and b>a+1 and size of array > 4
Input Format:
OR
Print "Array does not contain any equi pair" if there are no equi pairs in the array
Constraints:
Zi >= 0 and 1<= i <=N
size of array (N) > 4
b > (a+1)
Sample Input and Output
Your task is to find out if he will slip over the banana skin on forward path or banana skin on backward path and in how much time.
It is also possible that by his good fortune he might not step over either banana skins. Write a program to calculate the outcome.
Input Format:
Output Format:
For each test case, print time taken by the Drunkard to slip over the forward or backward banana skin. Print F if he slips over
forward banana skin and B if he slips over the backward banana skin. Both the outputs must be delimited by whitespace
OR
Print "Hurray" if the Drunkard is lucky to not slip over either banana skin
Constraints:
1 <= N <= 100
forward movement (FM) > 0
backward movement (BM) > 0
time (T) > 0
Distance to banana skin in forward direction (FBS) > 0
Distance to banana skin in backward direction (BBS) > 0
All input values must be integer only
6
28 B
B 14 12 7 25 4
156 F
B 11 4 6 10 17
1 675 B
F 2 3 9 12 15
102 B
F 1 12 3 22 28
Hurray
B 8 8 5 9 18
35 F
F88579
Earthquake Damage Estimator
Due to the latest earthquake occurrences, the government of "Intelligent Country" is trying to devise a mechanism which can
accurately identify the danger zones based on the origin / epicenter of the earthquake. The mechanism requires that the local map,
the co-ordinates of the epicenter and the intensity (measured in Richter scale) are provided as inputs to the program. The output of
the program would be the map marked with affected areas.
The local map is represented as a grid with square dimensions containing 0's and 1's only. 0's denote the areas which are water
whereas 1 denotes the land areas. Based on the epicenter co-ordinates, all the neighboring inhabited areas that would be affected
needs to be marked as '2'. This process will continue until all the neighboring land areas are processed. Based on the intensity
provided, the areas which would be most affected should be marked as "high risk zones" denoted by '3'. The below table should be
used for reference.
Intensity Impact
<=3.0 All reachable land areas would be marked as affected areas.
>3.0 and <=5.0 The immediate neighbors to the epicenter are the high risk zones.
>5.0 and <=8.0 The first three immediate neighbors would be marked as high risk zones.
>8.0 All reachable land areas would be marked as high risk zones.
Table 1: Intensity-Impact Table
Input Format:
File name, where file contains the information in format described below:
1. First line contains an integer N which denotes the size of the grid
2. Next N lines each contain N elements delimited by space. These elements are only 0's and 1's
3. Next line contains the coordinate of the epicenter. The following applies to the Epicenter
a. It always has to be a land area i.e. it has to be denoted by 1
b. Row and column indexes of the grid start with 1, not 0
c. Coordinates are delimited by space and are of format
4. Last line contains a float value, which denotes intensity of the earthquake in Richter scale
Output Format:
The output or the resulting map (in the form of the square matrix) should be displayed
Sample Input and Output
1022
1 0003
Map1.txt
1030
0033
033020202
000322220
2
Map2.txt 333020022
333302000
030320000
300002222
333320222
002202222
102222002
1033
3 0003
Map3.txt
1003
0033
1022
4 0002
Map4.txt
1002
0022
Explanation:
To understand the input and the output, following content of the file are depicted along with output for better understanding.
File
Contents of file Output Comments
Name
4
1011
Note how epicenter (3, 3) is highlighted in 3rd row and 3rd column.
0001 1022
The intensity of quake is 3.5. Hence according to Intensity-Impact Table we have to
Map1.txt 1 0 1 0 0003
consider immediate neighbours. The immediate land neighbours are [(2,4) (4,3) and
0011 1030
(4,4)]. Per rules, they are set to high risk zone, denoted by 3. The epicenter is also
33 0033
marked as high risk zone.
3.5
033020
202
000322
220
9
333020
011010101
022
000111110
333302
111010011
000 The intensity of quake is 6.95. Hence according to Intensity-Impact Table we have to
111101000
030320 consider three immediate neighbours. Three immediate neighbours is a perimeter of 3
Map2.txt 0 1 0 1 1 0 0 0 0
000 units from the epicenter. In this case the epicenter is (4,1). Hence the perimeter is
100001111
300002 from coordinates (1, 1) to (7, 4).Now applying, the rules we get the depicted output.
111110111
222 Note that the epicenter is also marked as high risk zone.
001101111
333320
101111001
222
41
002202
6.95555930016315
222
102222
002
4
1011
0001 1033
Map3.txt 1 0 0 1 0003 The intensity of quake is 8.95. Hence according to Intensity-Impact Table we have to
0011 1003 consider all reachable land neighbours through which the quake can propagate.
44 0033
8.95
4
1011
0001 1022
The intensity of quake is 1.95. Hence according to Intensity-Impact Table we have to
Map4.txt 1 0 0 1 0002
consider all reachable land neighbours and mark them as affected areas, denoted by 2.
0011 1002
The epicenter is also marked as affected area.
13 0022
1.95
Manisha is a smart investor. She has opened a Recurring Deposit (RD) account with a bank. She has negotiated smartly with the
bank. Bank has agreed to vary the interest rate on her RD account such that she is always able to comfortably beat inflation.
Your task is to calculate maturity value of her RD account in face of varying interest rates that she will enjoy.
Input Format:
Print the maturity amount after specified tenure or month in the format "Final_Amount "
Constraints:
P > 0 ; it can be float value
R >=0 ; it can be float value
T >0 ; it can be integer only
Calculation should be done upto 11-digit precision
Maturity amount should be printed to its nearest integer value
Sample Input and Output
5000
10
1 12
Final_Amount 63657
3 7 11
8 12 12
-1
2565.50
7.5
2
12 Final_Amount 32097
6 12 8
-1
200.75
3 6.9
Final_Amount 1021
5
-1
We are only interested in finding out the communities with the member count being an even number. Your task is to find out those
communities.
Input Format:
C I J, connect I and J
Q 0 0, print the number of communities with even member-count
Output Format:
For each query Q, output the number of communities with even member-count
Constraints:
1<=N<=10^6
1<=I, J<=N
5
Q00
C12
0
Q00
1 1
C23
0
Q00
1
C45
Q00
-1
Explanation:
For first query there are no members in any of the groups hence answer is 0.
After C 1 2, there is a group (let's take it as G1) with 1 and 2 as members hence total count at this moment is 1.
After C 2 3 total members in G1 will become {1, 2, 3} hence there are no groups with even count.
After C 4 5 there formed a new group G2 with {4, 5} as members, hence the total groups with even count is 1.
Matrix Rotations
You are given a square matrix of dimension N. Let this matrix be called A. Your task is to rotate A in clockwise direction
byS degrees, where S is angle of rotation. On the matrix, there will be 3 types of operations viz.
1. Rotation
2. Querying
3. Updation
Update the element at row X and column Y with value Z, presented as input in form of U X Y Z
Print the output of individual operations as depicted in Output Specification
Input Format:
Output Format:
For each Query operation print the element present at K-L location of the matrix in its current state.
Constraints:
1<=N<=1000
1<=Aij<=1000
0<=S<=160000
1<=K, L<=N
1<=Q<=100000
Explanation:
Initial Matrix
12
34
Again the angle of rotation is 90 degree, now after the rotation the matrix will become
43
21
Now the element at A11 is 4.
After updating, apply all the previous rotations (i.e. 180 = two 90 degree rotations).
The matrix will now become
43
26
Now A22 is 6.
If any of the above conditions is not satisfied, then the program will generate compilation errors. Today Raj has written a few
programs, but he is not sure about the correctness of the programs. Your task is to help him to find out whether his program will
compile without any errors or not.
Input Format:
First line starts with T, number of test cases. Each test case will contain a single line L, where L is a program written by Raj.
Output Format:
Print "No Compilation Errors" if there are no compilation errors, else print "Compilation Errors".
Constraints:
1<=T<=100
L is a text and can be composed of any of the characters {, }, (, ), <, >and P, where P will represents the instruction.
3
No Compilation Errors
1 {<>(P)}
Compilation Errors
{<{}>({}))
Compilation Errors
{({})}
In the Byteland country a string "S" is said to super ascii string if and only if count of each character in the string is equal to its ascii
value.
Your task is to find out whether the given string is a super ascii string or not.
Input Format:
First line contains number of test cases T, followed by T lines, each containing a string "S".
Output Format:
For each test case print "Yes" if the String "S" is super ascii, else print "No"
Constraints:
1<=T<=100
1<=|S|<=400, S will contains only lower case alphabets ('a'-'z').
2
1 Yes
bba
No
scca
Explanation:
Input Format:
1. The total number of zombies (N) and the maximum time allowed (T)
2. Array of size N, which represents the energy of zombies (E)
3. The initial energy level a player (P) and the minimum energy required to advance (D)
Output Format:
Print "Yes" if a player can advance to the next level else print "No".
Constraints:
1<=K<=10
1<=N<=50
1<=Ei<=500
1<=T<=100
1<=D<=2000
1<=P<=500
1
1 23
Yes
45
57
Alice and Bob are playing a game called "Stone Game". Stone game is a two-player game. Let N be the total number of stones. In
each turn, a player can remove either one stone or four stones. The player who picks the last stone, wins. They follow the "Ladies
First" norm. Hence Alice is always the one to make the first move. Your task is to find out whether Alice can win, if both play the
game optimally.
Input Format:
First line starts with T, which is the number of test cases. Each test case will contain N number of stones.
Output Format:
Constraints:
1<=T<=1000
1<=N<=10000
3
Yes
1 1
Yes
6
No
7
Input Format:
Note:
Output Format:
Print "Yes" if the rats can reach each other, else print "No"
Constraints:
1<=N<=350
Aij = {'O','X'}
1<=R<=N*N
1<=Xi<=N
1<=Yi<=N
3
OOX
OXO
OOX
1
4 Yes
11
12
21
32
3
OOX
OXO
OOX
2
4 No
11
12
21
23
On A Cube
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
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-Output:
Input
3
1,1,10,2,1,10,0,5,9
Output
6.05
Input
3
1,1,10,2,1,10,0,1,9
Output
4.05
Starting point of Angel can only be on border but not corners of the board and will be provided as input. He will walk in a straight
line (horizontal or vertical only) across the board, one cell every second. For example, if he is placed on the left border he will
move right towards the right border. Starting points and types of devils will be provided as input, their powers are as follows
(please also refer the image in Example 1).
OGRE (O): He cannot move but he can kill with his breath. His powers change with time.
· In 1st second Ogre can kill angel if the angel reaches Ogre’s location
· In 2nd second Ogre can kill angel surrounding upto 8 neighbouring cells (see diagram)
· In 3rd second Ogre can kill angel if the angel reaches Ogre’s location
· In 4th second Ogre is powerless i.e. even if angel reaches Ogre’s location, Ogre cannot harm him
XiXi (X): He has the power to kill an angel only if both the following conditions are true
· He is active
· Angel is on same colored cell as XiXi
XiXi is active only for 1 particular second in this game. According to Figure 1, XiXi is on cell D8. What this means is – XiXi
will be active only in 8th second and if and only if angel is on blue colored square at 8th second, XiXi can kill the angel.
ZeeSNAKE (Z): He leaves a poison trail and moves in 'Z' shape. His first move is 'down' and then 'right' and keeps on making a
trail in that order until he reaches the border. If he reaches the 'Bottom Border' he starts moving 'up' instead of 'down' and vice-
versa. If he reaches the 'Right Border' he starts moving 'left' instead of 'right' and vice-versa. Angel coming on the poison box will
die immediately. Trail created by him till 12th second is shown in Figure 1
You need to provide the box number on which the Angel gets killed, or output 'SS' if Angel successfully crosses the board
Constraints
Angel starts from the border but not from the corners (i.e. cells A1, A12, L1 and L12)
Powers of devils do not conflict. Thus if an angel reaches a cell which is under influence of more than one devil’s power, the
angel will still get killed
Input Format
Cell number where the angel gets killed, if angel does not get killed then print "SS"
Test Case
Explanation
Example 1
Input
K12
O,X,Z
I3,D8,C4
Output
K5
Explanation
Angel will be killed by the Devil XiXi as at the 8th second, he can kill angel on blue boxes
Figure. 1.
Example 2
Input
I12
Z,O,X
K2,B10,G3
Output
SS
Explanation
Note: if you don't know how to play chess and how chess pieces moves, please refer below link (you can concentrate only on how
the above mentioned pieces moves).
https://www.instructables.com/id/Playing-Chess/
Given an N*N chessboard with K number of Knights, R number of Rooks, B number of Bishops and Q number of queens. Your
task is to find out number of squares on the chess board such that your King is not checked by any of your opponents pieces.
Constraints
2<=N<=50
0<=K+R+B+Q <=N*N
0<=i, j <=N-1
Input Format
First line provides an integer N
Next line contains K, no. of Knights. Next K lines provide 2 space separated integers denoting the rank and the file of the Knights
(i,j)
Next line contains R, no. of Rooks. Next R lines provide 2 space separated integers denoting the rank and the file of the Rooks
(i,j)
Next line contains B, no. of Bishops. Next B lines provide 2 space separated integers denoting the rank and the file of the Bishops
(i,j)
Next line contains Q, no. of Queens. Next Q lines provide 2 space separated integers denoting the rank and the file of the Queens
(i,j)
Output
Number of squares where King can be placed safely.
00
11
22
33
Output 2
Explanation
The image shows the arrangement of the pieces. After the placement of all the Pieces as per
the input chess board looks like the image above,
You can place king in 2 places safely, i.e. (0,1) and (1,0)
Example 2
Input
8
4
26
32
56
77
4
22
46
64
75
4
04
11
16
51
2
35
60
output 5
Explanation
A square glass sheet of size 'S' cm fell down and broken down into N+1 pieces.
A man collected the broken pieces and he is trying to arrange the pieces to get the original shape. He found that exactly one piece
is missing. To find the exact position of the missing piece, he noted down all (x,y) coordinates of each broken piece. Please help
him to find the coordinates of the missing piece.
Note 1 : The input order of corners of known glass pieces are in the clockwise direction starting from the corner having least X
value. If more than one corners having the same least X value, then start from the corner having least X and least Y value.
Note 2 : The corners of missing glass piece should output in the clockwise direction starting from the corner having least X value.
If more than one corners have same least X value, then start from the corner having least X and least Y value.
Constraints
Input Format
Next N lines contain set of space separated integers indicates the details of N known glass pieces as follows:
Output
Test Case
Explanation
Example 1
Input
400
Output
(0,250) (100,250) (200,400) (0,400)
Explanation
The size of the square glass plate is 400 cm * 400 cm. The glass plate broke into 4 pieces and he got 3 pieces.
Figure. 1
Figure. 2
Figure. 4
Lastly, display the coordinates of missing glass piece in the clockwise direction starting from the corner (0,250), as output
There are 360 Longitudes on the Earth, which are equidistant vertical imaginary lines drawn on the Earth,
separated by 1 degree each from center of the Earth. Period of the rotation of the Earth on its axis is 24 hours. All
countries have their own official times and hence time zones.
UTC is universal time coordinate which passes through 0 (Zero degree) longitude.
Time at a particular location on Earth can be calculated using period of the rotation of Earth and longitude of that
particular location. For example, Indian time zone IST (Indian standard Time) is located at 82.5° E longitude.
Hence, Indian time can be calculated as below:-
Now suppose we changed period of rotation of the earth using some imaginary power, this will change the time
at every longitude on the earth.
Calculate the smallest angle between hour and minute hand of the clock , which shows the difference of time at a
particular longitude and the time at UTC i.e. we have to take smaller of the two angle formed between hour and
minute hand.
Constraints
To show the time difference on clock, 12-hour clock (as shown below) shall be used, irrespective of period of the
earth's rotation, for this question only.
Input Format
Output
Smallest angle between hour and minute hand of the clock, which shows the difference between time at a
particular longitude and time at UTC, up to 2 decimal places.
Test Case
Explanation
Example 1
Input
24
82.50
Output
15.00
Explanation
If period of rotation of earth is 24 hours then time at 82.5 degree longitude will be (24/360)*82.50 = 5:30 and
minimum angle at this time between minute and hour hand will be 15 degree.
Example 2
Input
12
360.00
Output 0.00
Explanation
If period of rotation of earth is 12 hours then time at 360 degree longitude will be (12/360)*360 = 12:00 and
minimum angle at this time between minute and hour hand will be 0 degree.
In a country, there are 'N' slabs for Income tax which are common for all age groups and genders. As an income
tax officer, investigating a case, you have the amount of tax paid by each employee of an organization. Considering
the income tax slabs and rebates offered, you need to find the total amount paid by the organization in salaries to
the employees to match it with the amount reported by the organization in its filed Income tax Returns. Information
regarding the income tax slabs, rebate amount and the income tax paid by each employee of the organization will
be provided. Rebate amount is subtracted from the total salary of each employee. Tax is calculated on the
remaining amount. You need to calculate the sum of total salary paid to the employees in that year.
Constraints
Input Format
First Line will provide the Amount in each slab, separate by space (' ')
Second Line will provide the percentage of tax applied on each slab. Number of values in this line will be same
as that in line one, separate by space (' ')
Fourth line will provide the tax paid by each employee, separate by space (' ')
Output
Input
Output
5300000
Explanation
Slabs and tax percentage indicate that for salary:
Between 0 - 300000, tax is 0%
Between 300001 - 600000, tax is 10%
Between 600001 - 900000, tax is 20%
Greater than 900001, tax is 30%
First, we exclude the rebate from the salary of each employee. This will be the taxable component of salary. Upon,
taxable salary apply the slab and tax percentage logic. Upon computation, one finds that employees are paid
amounts 1000000, 1200000, 1400000, 1700000 respectively, as salaries. So, the total salary paid to all employees
in that year will be 5300000.
Hint: - It may be helpful to browse the internet to know general rules regarding income tax calculations.
Marathon Winner
Problem Description
Race is generally organized by distance but this race will be organized by time. In
Let’s say total race time is 7 seconds we will check for (7-1) seconds. For
Participant who is leading more number of times is winner from prediction perspective. Now
Note:
1) At particular time let say at 4th second, top two (top N, in general) participants are at same distance, then
in this case both are leading we will increase count for both (all N).
2) And after calculating at all time slices, if number of times someone is leading, is same for two or more
participants, then one who come first in input sequence will be the winner.
Ex: If participant 2 and 3 are both leading with same number, participant 2 will be the winner.
Constraints
Input Format
Second line contains a single integer T denoting the total time in seconds of this Marathon. Next
ith integer denotes the number of steps taken by the participant at the ith second.
Output
Example 1
Input
3
8
224352623
357439322
124275324
Output 2
Explanation
3 (No. of candidate)
2 2 4 3 5 2 6 2 3 ( data for 1st candidate. First 8 integers denote number of steps per second and last integer
denotes distance covered in each step i.e. 3).
12 (2*3+2*3)
16 (3*2+5*2)
12 (1*4+2*4)
2*3+2*3 +4*3+3*3)
38
36
62
84
Output: 2
M,T <= N
Input Format
First line contains single integer T denoting the number of test cases.
First line of each test case contains 3 integers separated by space denoting N, T, and M.
Output
If probability is p/q where p & q are co-prime, print (p*mulInv(q)) modulo 1000000007, where mulInv(x) is
multiplicative inverse of x under modulo 1000000007.
Test Case
Explanation
Example 1
Input
421
Output
500000004
Explanation
The formats of Facts & Questions and its meanings are as follows.
Facts
"1AB" means : A and B are standing adjacent to each other
"2AB" means : A and B are standing opposite to each other
"3AB" means : A is standing to the immediate left of B
"4AB" means : A is standing to the immediate right of B
"5A" means : A is facing inwards
"6A" means : A is facing outwards
"7n" means : n people are facing inwards, where n is a number
"8n" means : n people are facing outwards, where n is a number
Questions
"?2A" means : who is standing opposite of A?
'?3A" means : who is standing to the immediate left of A?
"?4A" means : who is standing to the immediate right of A?
"?5A" means : is A facing inwards? Ans:Y/N
"?6A" means : is A facing outwards? Ans:Y/N
Constraints
1 < N < 10
Input Format
N Multiple facts, separated by semicolon multiple questions, separated by semicolon
Output
Answers, separated by semicolon corresponding to order of questions OR "ARRANGEMENT NOT
POSSIBLE"
Test Case
Explanation
Example 1
Input
2
2AB;72;1AC;6D;4BD;6C
?2D;?3C;?4B;?5A;?6B
Output
C;B;D;Y;N
Explanation
Example 2
Input
2
4BA;3CA;3CD;5C;5B
?5A;?3D;?4C;?6B
Output
Explanation
We can arrange 4 people in two different ways as the image below, from the facts provided. Directions of A
and D can be set differently.
For more Placement Preparation
Materials
Join our Community today!
Telegram: @CareerClimbers or
http://t.me/CareerClimbers