Data Structures & AlgorithmsHardGATE CS · TCS NQT

What is the most efficient general technique for the platform problem above (minimum platforms needed given arrival and departure times)?

  1. A. Build a graph of all trains and run Dijkstra
  2. B. Try every subset of trains
  3. C. Sort arrivals and departures separately and sweep with two pointers, tracking the maximum overlap
  4. D. Use dynamic programming over train numbers in arrival order

Correct answer: C. Sort arrivals and departures separately and sweep with two pointers, tracking the maximum overlap

After sorting both lists, a two-pointer sweep tracks the current number of trains present in O(n log n) total time. Graph search or subset enumeration is unnecessary.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic