Intervals Merging and scheduling
513. Minimum Platforms
A railway station has to serve n trains. Train i arrives at time arr[i] and departs at time dep[i].
Times are whole numbers. While a train is at the station it needs a platform to itself, and it keeps the same
platform for its whole stay. Return the smallest number of platforms the station needs so that no train ever
waits for one.
A train holds its platform from its arrival to its departure, including both moments. So when one train
departs at time t and another arrives at time t, both are at the station at t, and they need two
platforms. A train with arr[i] = dep[i] still needs a platform at that moment.
Meeting Rooms II uses the other rule: there, a meeting that ends at time t frees its room in time for a
meeting that starts at t.
Example 1
Input: arr = [3, 1, 10, 4, 7], dep = [6, 4, 12, 9, 8]
3Explanation: At time 4, train 1 departs and train 3 arrives, while train 0 is still at the station. All three need a platform at that moment. At every other moment, at most two trains are at the station.
Example 2
Input: arr = [0, 0, 0], dep = [0, 1000000000, 0]
3Explanation: All three trains are at the station at time 0. Trains 0 and 2 depart the moment they arrive, but each still needs a platform for that moment.
Example 3
Input: arr = [5, 1, 8], dep = [6, 10, 9]
2Explanation: Train 1 stays from time 1 to time 10. Trains 0 and 2 are never at the station together, so they can use the same second platform, one after the other.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ arr.length ≤ 105dep.length = arr.length0 ≤ arr[i] ≤ dep[i] ≤ 109
Clarifying questions
What you would ask an interviewer before writing any code.