CodeVita Sample Questions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

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.
Salary Paid
Problem Description
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
Number of tax slabs = Number of percentage on tax slabs

0<= Rebate, tax paid, slab <=1000000

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 (' ')

Third Line will provide the Rebate considered

Fourth line will provide the tax paid by each employee, separate by space (' ')

Output
Total Salary paid by the organization to its employees

Test Case
Explanation
Example 1

Input

300000 600000 900000

10 20 30

100000

90000 150000 210000 300000

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.
Prime Face
Problem Description
Accept a number N up to 5 digits long in the positional numeral system formed by symbols 0, 1, ... 9, A, ...,
Z. Also, accept another symbol S other than zero. Separate N and S with a space. Considering N to be
represented in the least base possible between 2 and 36, identify the smallest prime number greater than or
equal to N that contains at least one occurrence of S in it in base S + 1. (Refer example section for a better
understanding). Prime number should be identified with respect to Base 10 i.e. a regular prime number.

Constraints
1. Length of N <= 5

2. Max Base = 36

3. Face values for symbols:


Symbol => Value in base 10
0 => 0
1 => 1
2 => 2
….
9 => 9
A => 10
B => 11
….
Z => 35
Input Format
One line containing two integers, N and S separated with space.

Output
Print the smallest prime number greater than or equal to N that contains at least one occurrence of S in it, in
base S + 1.

Test Case
Explanation
Example 1

Input

10 B

Output

Explanation

The least possible base for N is 2 and its value in that base is 2. We want the smallest prime number in base
12 (1 more than the face value of B, 11) that contains symbol B and is greater than or equal to 2. The first
few numbers in ascending order in base 12 containing face value B are B (value 11), 1B (value 1 * 12 + 11
= 23), 2B (value 2 * 12 + 11 = 35): of these the smallest number that is prime is 11, which is greater than N.
Hence, the output is B.

Example 2

Input

ZZ Z

Output

11Z

Explanation

The least possible base for N is 36 and its value in that base is 35 * 36 ^1 + 35 = 1295. The first few numbers
in ascending order in base 36 (1 more than the face value of Z, 35) containing face value Z and greater than
N are 10Z (1 * 36^2 + 0*36^1 + 35 = 1331, non-prime), 11Z (1 * 36^2 + 1 * 36^1 + 35 = 1367, a prime).
Hence, the output is 11Z.
Marathon Winner
Problem Description
Race is generally organized by distance but this race will be organized by time.

In order to predict the winner we will check every 2 seconds.

Let’s say total race time is 7 seconds we will check for (7-1) seconds.

For 7 sec : We will check who is leading at 2 sec, 4 sec and 6 sec.

Participant who is leading more number of times is winner from prediction perspective.

Now our task is to predict a winner in this marathon.

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
1 <= T <= 100

1 <= N <= 100

Input Format
First line contains a single integer N denoting the number of participants

Second line contains a single integer T denoting the total time in seconds of this Marathon.

Next N lines (for each participant) are as follows :

We have T+1 integers separated by space.

First T integers are as follow:

ith integer denotes the number of steps taken by the participant at the ith second.

T+1st integer denotes the Distance (in meters) of each step.

Output
Index of Marathon winner, where index starts with 1.

Test Case
Explanation
Example 1

Input

224352623

357439322

124275324

Output

Explanation

3 (No. of candidate)

8 (Total time of Sprint (In seconds))

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).

3 5 7 4 3 9 3 2 2 (similarly, 2nd candidate’s data).

1 2 4 2 7 5 3 2 4 (similarly, 3rd candidate’s data).

At time 2: Here 2nd marathoner is leading

12 (2*3+2*3)

16 (3*2+5*2)

12 (1*4+2*4)

At time 4 :Here also 2nd marathoner is leading

33 ( 2*3+2*3 +4*3+3*3)

38

36

At time 6 :Here 3rd marathoner is leading

57

62

84

Output:

2
Since, 2nd marathoner is leading more number of times, so 2 is the winner.
Friend Circle
Problem Description
2N friends (A,B,C... , 2N) are standing in a circle. There is exactly one person standing opposite of one other
person. Some of them are facing inwards and some of them are facing outwards. Here given some facts your
task is to build the standing positions and answer a few Questions. If the arrangement is not possible or more
than one arrangement is possible, then print "ARRANGEMENT NOT POSSIBLE".

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

1 < Total Facts < 30

1 < Total Questions < 20

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

4 people- A, B, C and D are standing in circle.


There are 6 facts separated in semicolons:
2AB ==> A and B are standing opposite
72 ==> 2 people are facing inwards
1AC ==> A and C are standing nearby
6D ==> D is facing outwards
4BD ==> B is standing immediate right of D
6C ==> C is facing outwards
From the above facts, we can build the standing positions as below image:

There are 5 questions:


?2D ==> who is standing opposite of D? Ans:C
?3C ==> who is standing immediate left of C? Ans:B
?4B ==> who is standing immediate right of B? Ans:D
?5A ==> is A facing inwards? Ans:Y
?6B ==> is B facing outwards? Ans:N
Finally printing all answers in a single line separated by semicolon.

Example 2

Input

2
4BA;3CA;3CD;5C;5B
?5A;?3D;?4C;?6B

Output

ARRANGEMENT NOT POSSIBLE

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.
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.

You might also like