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

Trains (arrival, departure) in minutes are (900,930), (940,1200), (950,1120), (1100,1130), (1500,1800), (1130,1140). A platform holds one train at a time and a train may leave as another arrives at the same minute. What is the minimum number of platforms needed?

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

Correct answer: B. 3

Sort arrival and departure times separately and merge them, moving the pointer for the smaller time; a departure at the same minute as an arrival frees a platform first. The peak number of trains present at once is the answer.

More Coding Interview Problems questions

Exams that ask this topic