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

Half-open intervals [0,2), [1,3), [2,4), [3,5), [4,6). What is the minimum number of intervals to remove so the remaining intervals are pairwise disjoint?

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

Correct answer: A. 2

Keep the maximum disjoint set and remove the rest; with half-open intervals a touching pair such as [0,2) and [2,4) is compatible. The answer is the number of intervals minus the size of the best kept set.

More Coding Interview Problems questions

Exams that ask this topic