## techInterview Discussion |
||

A part of techInterview.org: answers to technical interview questions.
Your host: Michael Pryor |
The answer is that the train is moving 2x the speed of the man.
Let T = speed of the train Let M = speed of the man Let S = size of the tunnnel Let D = distance of the train from the start of the tunnel. Since Distance = Rate * Time, we also have Time = Distance / Rate. The first part of the problem tells us that: D/T = (S/4)/M Substituting T = 2*M gives us: D/2*M = (S/4)/M D/2 = S/4 or 4D = 2S If tunnel is 2 km, then the train is 1 km away from the start of the tunnel. So, let's assume D = 1km, S = 2km. The second part of the problem tells us that: (D + S)/T = (3S/4)/M which gives us: (3km)/2M = (6km/4)/M The solution comes from solving for T/M from the following two equations: D/T = (S/4)/M (D+S)/T = (3S/4)/M
You can also apply a little bit of logic to the problem to come up with the solution, for the people I interview its more important than someone who can work through the math.
We know that the train and man will reach the start of the tunnel at the same time if the man turns around, in that time the man travels 1/4th the length of the tunnel. If the man travels on towards the end of the tunnel he will be able to travel an additional 1/4th of the length of the tunnel before the train reaches the start of the tunnel, putting the man at the half way point. For both the man and the train to reach the end of the tunnel at the same time, the man has to travel 1/2 the length of the tunnel while the train has to travel the full length of the tunnel. Therefor the train must be travelling twice as fast as the man (and as an aside must have been half the length of the tunnel away from the start of the tunnel when it blew its whistle). |

Powered by FogBugz