Data Structures & AlgorithmsHardGATE CS

Lectures occupy half-open intervals [start, end): [0, 3), [0, 7), [3, 7), [4, 12), [8, 12), [10, 16), [12, 18), [19, 27). A lecture ending at t frees its room for one starting at t. What is the minimum number of rooms needed?

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

Correct answer: B. 3

Sweep the times, processing an end before a start at the same instant; the peak number of overlapping lectures is 3. Treating touching intervals as overlapping gives 4.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic