Skip to interview prep
Apexed
Problem list101 / 125

101. Minimum Railway Platforms

MediumGreedy

Train i arrives at arrivals[i] and leaves at departures[i] (times as integers such as 930 for 9:30, with arrival ≤ departure). A train occupies a platform from its arrival to its departure, inclusive, so a train arriving at the same time another leaves needs a different platform.

Return the minimum number of platforms so that no train waits.

Example 1

Input: arrivals = [900, 940, 950, 1100, 1500, 1800], departures = [910, 1200, 1120, 1130, 1900, 2000]
Output: 3

Constraints

  • 0 ≤ trains ≤ 5 · 10⁴

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Minimum Railway Platforms — coding interview practice — Apexed