Data Structures & AlgorithmsHardICPC regional · Product Company SDE

Problem: For the 'minimum number of platforms needed for a railway station given arrival and departure times' problem, what is the standard efficient approach and its time complexity?

  1. A. Sort arrivals and departures separately, then use two pointers to simulate overlapping intervals: O(n log n)
  2. B. Dynamic programming over all subsets of trains: O(2^n)
  3. C. A single pass without sorting: O(n)
  4. D. Brute-force check every pair of trains for overlap: O(n^2), and this is optimal

Correct answer: A. Sort arrivals and departures separately, then use two pointers to simulate overlapping intervals: O(n log n)

Sorting arrival and departure times separately and merging them with two pointers (incrementing a platform counter on an arrival, decrementing on a departure) tracks the maximum simultaneous overlap in O(n log n), dominated by the sort.

More Coding Interview Problems questions

Exams that ask this topic