Challenge
Given daily arrival and departure times of every train that reaches a railway station, find the minimum number of platforms required for the railway station so that no train waits.
In other words, find the maximal number of trains simultaneously present in the station.
Input
- a pair of lists of times: arrivals and departures; the two lists have same length; arrival
i
corresponds to the same train as departurei
. - alternatively, a list of pairs of times, or any equivalent.
- times are numbers between
0
, included, and24
, excluded. - there are no dates, only times: input is the daily schedule and repeats every day.
- the departure time of a train can be lower than its arrival time; in that case, the train is understood to arrive on a day and depart on the next day; that train will require a platform before midnight and after midnight.
- if the arrival time is lower than the departure time, the train is understood to arrive and depart on the same day.
- input can be restricted to integers
Output
- one integer, the minimum required number of platforms.
Test cases
arrivals = [10, 13, 16]
departures = [12, 15, 18]
out = 1
arrivals = [10, 11]
departures = [12, 13]
out = 2
arrivals = [ 1, 3, 7, 9,10,10,19,23]
departures = [11, 4,11,10,11, 2, 2, 2]
out = 5
arrivals = [1, 2]
departures = [2, 3]
out = 2
arrivals = [1, 2]
departures = [3, 2]
out = 2
arrivals = [2, 22]
departures = [5, 6]
out = 2
Rules
- This is code-golf, the shortest code in bytes wins!
the departure time of a train can be lower than its arrival time
. \$\endgroup\$