Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

Trains arrive at [900, 940, 950, 1100, 1500, 1800] and depart at [910, 1200, 1120, 1130, 1900, 2000] (matched train by train). A platform serves one train at a time, and a train arriving at the moment another departs can use the same platform. What is the minimum number of platforms?

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

Correct answer: A. 3

Sort arrivals and departures separately and sweep: process an arrival before a departure only when the arrival is strictly earlier, so an equal time frees a platform first. The peak count of simultaneously present trains is the answer.

More Coding Interview Problems questions

Exams that ask this topic