Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.