Step 1: Sort arrivals and departures separately
arrivals = [9:00, 9:40, 9:50, 11:00, 15:00, 18:00]
departures = [9:10, 11:20, 11:30, 12:00, 19:00, 20:00]
Why: Sorting helps us compare events in order of time.
Step 2: Initialize pointers i=0 (arrivals), j=0 (departures), platforms=0, max_platforms=0
i=0, j=0, platforms=0, max_platforms=0
Why: We track how many trains are currently at the station.
Step 3: Compare arrival[i] and departure[j]: 9:00 < 9:10, so a train arrives before the first departs
platforms=1, max_platforms=1, i=1, j=0
Why: One train occupies a platform.
Step 4: Compare arrival[i] and departure[j]: 9:40 > 9:10, so a train departs before next arrival
platforms=0, max_platforms=1, i=1, j=1
Why: A platform frees up as a train leaves.
Step 5: Compare arrival[i] and departure[j]: 9:40 < 11:20, train arrives before next departure
platforms=1, max_platforms=1, i=2, j=1
Why: Another train occupies a platform.
Step 6: Compare arrival[i] and departure[j]: 9:50 < 11:20, another train arrives before departure
platforms=2, max_platforms=2, i=3, j=1
Why: Two trains overlap, need two platforms.
Step 7: Compare arrival[i] and departure[j]: 11:00 < 11:20, another train arrives before departure
platforms=3, max_platforms=3, i=4, j=1
Why: Three trains overlap, need three platforms.
Step 8: Compare arrival[i] and departure[j]: 15:00 > 11:20, train departs freeing platform
platforms=2, max_platforms=3, i=4, j=2
Why: One train leaves, platform count decreases.
Step 9: Compare arrival[i] and departure[j]: 15:00 > 11:30, train departs freeing platform
platforms=1, max_platforms=3, i=4, j=3
Why: Another train leaves, platform count decreases.
Step 10: Compare arrival[i] and departure[j]: 15:00 > 12:00, train departs freeing platform
platforms=0, max_platforms=3, i=4, j=4
Why: Another train leaves, platform count decreases.
Step 11: Compare arrival[i] and departure[j]: 15:00 < 19:00, train arrives
platforms=1, max_platforms=3, i=5, j=4
Why: Train arrives, platform count increases.
Step 12: Compare arrival[i] and departure[j]: 18:00 < 19:00, train arrives
platforms=2, max_platforms=3, i=6, j=4
Why: Another train arrives, platform count increases.
Step 13: Compare arrival[i] and departure[j]: no more arrivals, remaining departures free platforms
platforms=1, max_platforms=3, j=5
Why: Trains depart, platforms free up.
Step 14: Last departure frees last platform
platforms=0, max_platforms=3, j=6
Why: All trains have left, no platforms occupied.
Result: Final state: max_platforms = 3
Answer: Minimum 3 platforms needed