Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Crossing Time Math Puzzle

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Crossing Time Math Puzzle. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

A J.P. Morgan operations dashboard needs to estimate how long a moving train takes to pass a fixed signal pole. Given the train's length in meters and speed in kilometers per hour, calculate the crossing time in seconds.

A train crosses a pole when its entire length has passed the pole. Therefore, the distance traveled is exactly the train's length.

Formal Specification

Implement train_crossing_time(length_meters, speed_kmh). Return the crossing time as a floating-point number of seconds. Do not round the result.

Convert the speed from kilometers per hour to meters per second before applying:

time = distance / speed

Constraints

  • 1 <= length_meters <= 10^6
  • 1 <= speed_kmh <= 10^6
  • Inputs are positive numbers
  • Return the result in seconds without rounding

Function Signature

def train_crossing_time(length_meters, speed_kmh):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output