Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Min Platforms for Train Schedules
00:00
5 left

Min Platforms for Train Schedules

EasyPython

Problem

MakeMyTrip needs to determine the minimum number of railway platforms required at a station so that no arriving train must wait. Given the arrival and departure time of every train, return the maximum number of trains present at the station simultaneously.

A platform is occupied from a train's arrival time through its departure time. If one train arrives at the exact moment another departs, treat the arrival as occurring first, so an additional platform is required.

Formal Specification

Implement min_platforms(arrivals, departures), where:

  • arrivals is a list of integer times in HHMM format.
  • departures is a list of integer times in HHMM format.
  • arrivals[i] and departures[i] describe the same train.
  • Return an integer representing the minimum number of platforms required.

The input lists have equal lengths, and each train's arrival time is earlier than or equal to its departure time.

Constraints

  • 1 <= len(arrivals) <= 10^5
  • len(arrivals) == len(departures)
  • 0 <= arrivals[i], departures[i] <= 2359
  • Times are valid HHMM values
  • arrivals[i] <= departures[i] for every train

Function Signature

def min_platforms(arrivals, departures):
Interviewer

Your question is Min Platforms for Train Schedules. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.