Menu
CoddyTech

Minimum Platforms

A station has one day's timetable: train i arrives at arrival[i] and leaves at departure[i]. Times are HHMM numbers, the clock time without its colon, so 930 is 09:30.

A train holds its platform from the minute it arrives through the minute it leaves, both included. So a train arriving in the minute another leaves cannot take that train's platform.

Return the fewest platforms the station needs so that no train has to wait.

Function

minimumPlatforms(arrival: integer-array, departure: integer-array) → integer
arrivalinteger-array
the arrival time of each train, as an HHMM number
departureinteger-array
the departure time of each train, as an HHMM number; departure[i] belongs to arrival[i]
Returnsinteger
the largest number of trains at the station in the same minute, which is the fewest platforms needed

Constraints

  • 1 ≤ arrival.length == departure.length ≤ 5000
  • 0 ≤ arrival[i] ≤ departure[i] ≤ 2359
  • Every time is a valid HHMM time: its last two digits are at most 59.
  • All trains run on the same day. The arrays are not sorted.

Examples

Input
arrival = [900, 1500, 920, 1520, 1000, 1530]departure = [930, 1600, 1010, 1535, 1100, 1545]
Output
3
Explanation
At 15:30 three trains stand at the station: the ones from 15:00 to 16:00, from 15:20 to 15:35 and from 15:30 to 15:45. No minute has four, so 3 platforms are enough.
challenge icon

Follow-up

Some night trains arrive before midnight and leave after it, so their departure number is smaller than their arrival. How would you count platforms when the timetable wraps around midnight?

Reset code
def minimumPlatforms(arrival, departure):
    # Write code here

Test #1

Test #2

Test #3

Arguments

arrival = [900, 1500, 920, 1520, 1000, 1530]
departure = [930, 1600, 1010, 1535, 1100, 1545]

Expected Output

3