Data Structures & AlgorithmsVery hardGATE CS · DSA

Trains occupy a platform from arrival to departure INCLUSIVE, so a train arriving at the same minute another departs needs a separate platform. Times are in minutes after 9:00: [15, 75], [70, 115], [75, 85], [100, 120], [120, 140], [130, 160], [145, 165]. Sorting arrivals and departures and sweeping with two pointers, what is the minimum number of platforms?

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

Correct answer: D. 3

With inclusive occupancy, an arrival at time t must be processed before a departure at the same t. The running count then peaks at 3. Processing departures first at ties (the exclusive convention) gives 2.

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

Exams that ask this topic