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

Trains arrive at 100, 140, 150, 180, 200 and depart at 120, 160, 190, 210, 230 (times are not paired). A platform holds one train at a time, and a train arriving exactly when another departs may use the platform. What is the minimum number of platforms?

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

Correct answer: D. 2

Merge the sorted arrival and departure lists: process a departure before an arrival only when it is not later. Pairing trains in input order is not required; the sweep uses the sorted lists independently.

More Coding Interview Problems questions

Exams that ask this topic