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

Closed intervals [0,3], [2,5], [4,8], [6,9], [8,12] are available. What is the minimum number of them needed so that every point of the set {1, 3, 4, 7, 8, 10} lies in at least one chosen interval?

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

Correct answer: A. 3

Choosing the longest intervals first is not optimal; a point-driven greedy picks the interval covering the leftmost uncovered point with the furthest right end. Brute force over small subsets confirms the minimum.

More Coding Interview Problems questions

Exams that ask this topic