Directi Interview Question for Software Developers
- 0of 0 votes
You 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
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
For each test case, output a single line containing the expected probability having an absolute or relative error less than 10^-6.
0 ≤ Tc ≤ 5 * 10 ^ 7
1 ≤ Ve ≤ 1000
1 ≤ Vy ≤ 1000
1 ≤ L ≤ 10 ^ 5
1 ≤ T ≤ 10 ^ 6
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
Open Chat in New Window