Directi Interview Question for Software Developers
- 0of 0 votes
AnswersYou are walking down the escalator to catch a subway train. The escalator itself moves at a speed of Ve meters per minute. You can walk down the escalator at a relative speed of Vy meters per minute. The length of the escalator is L meters. Trains arrive T minutes apart. Let t be the time between your arrival to the station if you stand still on the escalator and the arrival of the last train before your arrival. Assume that t is a random variable uniformly distributed between 0 and T. Return the probability of catching an earlier train if you choose to walk down the escalator instead of standing still on it.
- praveensinghraghav96 July 02, 2017 in India
Input :
The first line of the input contains an integer Tc denoting the number of test cases. Each test case contains the following 4 lines
Ve - velocity of escalator
Vy - your relative velocity with the escalator
L - length of escalator
T - Time Period of Trains
Output
For each test case, output a single line containing the expected probability having an absolute or relative error less than 10^-6.
Constraints
0 ≤ Tc ≤ 5 * 10 ^ 7
1 ≤ Ve ≤ 1000
1 ≤ Vy ≤ 1000
1 ≤ L ≤ 10 ^ 5
1 ≤ T ≤ 10 ^ 6
Example
Input:
2
10
10
20
2
10
10
100
4
Output:
0.5
1.0
Explanation
Example case 1. If you stand still, it'll take you 20/10 = 2 minutes to reach the bottom of the escalator. If you choose to walk, it'll make you 20/(10+10) = 1 minute. In the second case you save 1 minute and in 50% of the cases it'll allow you to catch an earlier train.
Example Case 2. Here, if you choose to walk instead of stand still, you will save 5 minutes and you will certainly be guaranteed to catch an earlier train.| Report Duplicate | Flag | PURGE
Directi Software Developer