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

Half-open intervals [1,2), [2,3), [3,4) and [1,3) are given. What is the minimum number of intervals that must be removed so that the remaining ones are pairwise disjoint?

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

Correct answer: A. 1

Removing the fewest intervals equals n minus the largest disjoint set. For half-open intervals an interval ending at t and one starting at t are disjoint, so [1,2), [2,3), [3,4) are compatible and [1,3) must go. Answer: 1.

More Coding Interview Problems questions

Exams that ask this topic