Minimum Platforms Required
Problem Description
Given arrival and departure times of trains at a station, find the minimum number of platforms required so no train waits.
Example:
Input: arrival=[900,940,950,1100,1500,1800], departure=[910,1200,1120,1130,1900,2000]
Output: 3
Explanation: At time 1100, trains arriving at 940, 950, and 1100 are all present.
DE Shaw Tier 2 — classic GfG problem.
Optimal O(n log n): sort both arrays, use two pointers. Increment platforms when a new train arrives before the earliest scheduled departure. Decrement when a train departs. Track maximum.
Example Test Cases
Example 1
Input: [[900,940,950,1100,1500,1800],[910,1200,1120,1130,1900,2000]]
Expected: 3
Example 2
Input: [[100,200,300],[400,500,600]]
Expected: 3
Example 3
Input: [[100],[200]]
Expected: 1
Run your code to see the results