Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Simultaneous Trips in 24 Hours

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

Your question is Simultaneous Trips in 24 Hours. 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

Via Transportation needs to identify the busiest period in its On-Demand trip schedule. Given trips scheduled within one 24-hour day, determine the maximum number of trips active simultaneously and the earliest minute at which that maximum occurs.

A trip is active on the half-open interval [start, end): it includes start but excludes end. Therefore, a trip ending at minute t does not overlap with a trip starting at minute t.

Formal Specification

Implement max_simultaneous_trips(trips), where trips is a list of pairs [start, end]. Each value is an integer minute from midnight, with 0 <= start < end <= 1440. Return [peak_count, earliest_start], where peak_count is the largest number of simultaneous trips and earliest_start is the smallest minute at which that count is active. Return [0, 0] when the list is empty.

Constraints

  • 0 <= len(trips) <= 200,000
  • 0 <= start < end <= 1440
  • All times are integer minutes from midnight
  • The input contains trips from one 24-hour period

Function Signature

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