Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA

Problem: Trains arrive at times 900, 940, 950, 1100, 1500, 1800 and depart at 910, 1200, 1120, 1130, 1900, 2000 (all as 24-hour clock times, minutes counted as integers). What is the minimum number of platforms needed so that no train waits?

  1. A. 4
  2. B. 3
  3. C. 2
  4. D. 5

Correct answer: B. 3

Sort arrivals and departures separately and sweep them in time order, counting trains currently at the station. Matching each arrival to the most recent departure is the trap.

More Coding Interview Problems questions

Exams that ask this topic