Data Structures & AlgorithmsVery hardICPC regional · greedy theory

Problem: Which statement about the greedy algorithm for 'minimum number of lecture rooms' (interval partitioning) is correct?

  1. A. The answer is always the number of intervals
  2. B. Sorting by length gives the optimum
  3. C. Sorting by start time and reusing the room that frees earliest uses exactly the maximum overlap number of rooms
  4. D. The answer equals the minimum number of overlapping intervals at any point

Correct answer: C. Sorting by start time and reusing the room that frees earliest uses exactly the maximum overlap number of rooms

The number of rooms needed equals the maximum number of intervals alive at once, and the start-time greedy achieves it. Using the minimum overlap is the trap.

More Coding Interview Problems questions

Exams that ask this topic