Clock Angle
Problem Description
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:-
IST = UTC + (24/360)*82.5 = UTC + 5:30Hrs
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
1. Period of the earth’s rotation in Hours (Integer only)
2. Value of Longitude up to 2 place of decimal
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.
Lexi String
Problem Description
Little Jill jumbled up the order of the letters in our dictionary. Now, Jack uses this list to find the
smallest lexicographical string that can be made out of this new order. Can you help him?
You are given a string P that denotes the new order of letters in the English dictionary.
You need to print the smallest lexicographic string made from the given string S.
Constraints
1 <= T <= 1000
Length (P) = 26
1 <= length (S) <= 100
All characters in the string S, P are in lowercase
Input Format
The first line contains number of test cases T
The second line has the string P
The third line has the string S
Output
Print a single string in a new line for every test case giving the result
Test Case
Explanation
Example 1
Input
polikujmnhytgbvfredcxswqaz
abcd
qwryupcsfoghjkldezxvbintma
ativedoc
Output
bdca
codevita
Explanation
The transformed smallest lexicographical strings are in order they would be if order of letters are
changed to string P.
Dole Out Cadbury
Problem Description
You are a teacher in reputed school. During Celebration Day you were assigned a task to distribute
Cadbury such that maximum children get the chocolate. You have a box full of Cadbury with
different width and height. You can only distribute largest square shape Cadbury. So if you have a
Cadbury of length 10 and width 5, then you need to break Cadbury in 5X5 square and distribute to
first child and then remaining 5X5 to next in queue
Constraints
0<P<Q<1501
0<R<S<1501
Input Format
First line contains an integer P that denotes minimum length of Cadbury in the box
Second line contains an integer Q that denotes maximum length of Cadbury in the box
Third line contains an integer R that denotes minimum width of Cadbury in the box
Fourth line contains an integer S that denotes maximum width of Cadbury in the box
Output
Print total number of children who will get chocolate.
Test Case
Explanation
Example 1
Input
Output
24
Explanation
Length is in between 5 to 7 and width is in between 3 to 4.
So we have 5X3,5X4,6X3,6X4,7X3,7X4 type of Cadbury in the box.
If we take 5X3 :
First, we can give 3X3 square Cadbury to 1st child .Then we are left with 3X2. Now largest square
is 2X2 which will be given to next child. Next, we are left with two 1X1 part of Cadbury which will
be given to another two children.
And so on
ODI Score
Problem Description
In a remote location, a student is watching a game of ODI cricket on TV. At some point, power
goes off; the student is assured about the current run rate of the batting team, which batsman is
on strike and individual scores of both the batsmen playing currently but is unsure of exact number
of runs the batting team has scored. After some time, power is restored for a moment and at that
point in time, a 'Timeline' of runs scored in last 'D' no. of deliveries and current run rate is being
shown on TV. Exactly 'D' no. of deliveries were bowled in between the power outage.
Given these details, you need to find out the total number of runs scored by the team and score of
batsmen currently playing.
- Wickets falling will be shown as 'W'. Assume batsmen can only be 'bowled' in these 'D' deliveries
- Consequent overs are bowled from opposite ends. (ie. batsmen change sides at the end of an
over)
Constraints
· Runs scored per delivery can be between 0 and 6
· No extra deliveries are bowled and no extra runs scored (Leg byes, No balls, etc.)
· Number of deliveries 'D' <50
· RR1 is not equal to RR2
· Number of wickets falling in the timeline < 10
Input Format
First line will provide the run rate at first instance (RR1)
Second line will provide Batsmen scores, space separated (striker's score will be given first)
Third line will provide comma separated list of runs scored in 'D' deliveries
Fourth line will provide the run rate at second instance (RR2)
Output
Space separated values of 'Total Runs', 'Striker', 'Non-Striker' at the second instance (after
Timeline). Consider side change if an over is completed at the end of the timeline.
Test Case
Explanation
Example 1
Input
21 13
11111000042001601100
8.3182
Output
122 20 34
Explanation
Assuming number of deliveries bowled at the first instance is 'b' and number of runs scored is 'r'
Solving for these we will get b=68 and r=102. So current run score will be 102+20 = 122
We also get that 4 deliveries remained in the 'Over' when the power goes off (an 'Over' consists of
6 consecutive deliveries bowled from one end). So adding the runs individually to batsmen scores
we get current scores as 20 and 34.
Example 2
Input
21 13
1111100004200160110W
8.3182
Output
122 0 34
Explanation
Here wicket goes does at the last ball. Hence, the striker, who is the new batsman, has zero runs.
Lazy Student
Problem Description
There is a test of Algorithms. Teacher provides a question bank consisting of N questions and
guarantees all the questions in the test will be from this question bank. Due to lack of time and his
laziness, Codu could only practice M questions. There are T questions in a question paper selected
randomly. Passing criteria is solving at least 1 of the T problems. Codu can't solve the question he
didn't practice. What is the probability that Codu will pass the test?
Constraints
0 < T <= 10000
0 < N, T <= 1000
0 <= M <= 1000
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
For each test case, print a single integer.
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 probability is ½. So output is 500000004.
Death Battle
Problem Description
In a crossover fantasy universe, Houin Kyoma is up in a battle against a powerful monster Nomu
that can kill him in a single blow. However being a brilliant scientist Kyoma found a way to pause
time for exactly M seconds. Each second, Kyoma attacks Nomu with certain power, which will
reduce his health points by that exact power. Initially Nomu has H Health Points. Nomu dies when
his Health Points reach 0. Normally Kyoma performs Normal Attack with power A. Besides from
Kyoma’s brilliance, luck plays a major role in events of this universe. Kyoma’s Luck L is defined as
probability of performing a super attack. A super attack increases power of Normal Attack by C.
Given this information calculate and print the probability that Kyoma kills Nomu and survives. If
Kyoma dies print “RIP”.
Constraints
0 < T <= 50
1 <= A, H, C, L1, L2 <= 1000
1 <= M <= 20.
L1<=L2
Input Format
First line is integer T denoting number of test cases.
Each test case consist of single line with space separated numbers A H L1 L2 M C. Where luck L
is defined as L1/L2. Other numbers are, as described above.
Output
Print probability that Kyoma kills Nomu in form P1/P2 where P1<=P2 and gcd(P1,P2)=1. If
impossible, print “RIP” without quotes.
Test Case
Explanation
Example 1
Input
10 33 7 10 3 2
10 999 7 10 3 2
Output
98/125
RIP