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.
- a pair of lists of times: arrivals and departures; the two lists have same length; arrival
icorresponds to the same train as departure
- alternatively, a list of pairs of times, or any equivalent.
- times are numbers between
0, included, and
- 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
- one integer, the minimum required number of platforms.
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
- This is code-golf, the shortest code in bytes wins!