Minimum Number of Platforms
Given train arrival and departure times, find the minimum platforms so no train waits.
Open on GeeksforGeeks ↗Intuition
The answer is the maximum number of trains present at once. Sort arrivals and departures separately and sweep: an arrival is +1 platform, a departure is −1. The peak of that running count is the answer.
Approach
Separate the two event streams
Platform need only changes at an arrival or a departure — sort each list and merge-walk them chronologically.
Sweep with a counter
If the next arrival is ≤ the next departure, a train arrives before any leaves: need += 1. Otherwise one leaves: need -= 1. Track the max.
Why ≤ matters
If a train arrives exactly when another departs, both briefly need platforms — count the arrival first.
Solution & live demo
Edge cases
Tie processed as arrival first → correctly demands an extra platform.
Counter climbs to n and never drops until the end.