Minimum Number of Platforms Problem
Minimum Number of Platforms Problem — ExecCode Medium DSA Practice
Solve the Minimum Number of Platforms problem on ExecCode. Free online medium DSA practice in Searching & Sorting. Write and run code in Java, C++, Python — no signup required to run.
Problem description
You are given arrival and departure times of trains at a railway station. arrival[i] is the arrival time of train i, and departure[i] is its departure time. Times are integers in HHMM form. A platform is required for every train while it is at the station. Return the minimum number of platforms so that no train has to wait. A train that arrives at the same time another departs still needs its own platform. You are given: arrival — arrival times departure — departure times Return the minimum number of platforms. Assume every departure is at or after its arrival. Sort both arrays, then walk them with two pointers: an arrival takes a platform, and a departure frees one.
Examples
Input {'arrival': [900, 940, 950, 1100, 1500, 1800], 'departure': [910, 1200, 1120, 1130, 1900, 2000]}; Output 3. Input {'arrival': [900, 1000, 1100], 'departure': [930, 1030, 1130]}; Output 1. Input {'arrival': [900, 900, 900], 'departure': [1000, 1000, 1000]}; Output 3
Constraints
1 <= arrival.length <= 100000 departure.length == arrival.length 0 <= arrival[i] <= departure[i] <= 2359
Practice Minimum Number of Platforms free on ExecCode. Browse DSA problems, topic map, and placement guides.