Back to Practice
#0044

Train Crossing a Platform

MediumAptitude12 min15 XP

Problem

A train 180 m long crosses a 120 m platform at 54 km/h. How many seconds does it take to completely cross the platform?

Why This Matters

Train questions are just relative distance over speed, but the distance is often hidden in the wording.

Examples

Example 1
Inputtrain length 180 m, platform 120 m, speed 54 km/h
Output20 seconds

Total distance is 300 m. Speed is 15 m/s. Time = 300/15 = 20 seconds.

Constraints

  • Convert km/h to m/s by multiplying by 5/18.
  • Use train length + platform length for complete crossing.
CodeReasoning
A train 180 m long crosses a 120 m platform at 54 km/h. How many seconds does it take to completely cross the platform?
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Complete platform crossing
Input180 m train, 120 m platform, 54 km/h
Expected20 seconds

The front of the train travels train length plus platform length before the whole train clears the platform.

Hidden Test Categories
Train crossing a pole uses only train lengthTwo trains crossing each other use relative speedSpeed given directly in m/s