Answer:
They will cross each other in 30 seconds
Explanation:
Let the length of the trains be l,
now, let train 1 be the train that covers this length l in 5 seconds
and train 2 be the train that covers it in 6 seconds.
After 5 seconds, train 1 has covers a distance of l while train 2 lags behind by 1 second.
After 10 seconds, train 1 has covered a distance of 2l while train 2 lags behind by 2 seconds and so on.
They will cross each other when train 1 covers l more distance than train 2.
This happens when they both cover a whole number distance for the first time simultaneously.
This corresponds to their LCM,
so,
LCM(5, 6) = 30 seconds
So, the time is 30 seconds
We can illustrate this as follows,
Now,
we check every 5 seconds,
At each step of 5 seconds, we add 1 to the distance covered by train 1 and 5/6 to the distance covered by train 2
after 5 seconds, train 1 has covered l distance and train 2 has covered 5/6l distance
after 10 seconds, we get, for train 1, 2l; for train 2, 5/3l
after 15 seconds, train 1 has 3l distance and train 2 has 5/2l
after 20 seconds train 1 has 4l distance and train 2 has 10/3l
after 25 seconds train 1 has 5l and train 2 has 25/6l
after 30 seconds train 1 has 6l and train 2 has 5l
Hence they cross each other after 30 seconds