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

Closed integer intervals [1,3], [2,5], [4,7], [6,9], [8,10], [5,6] are available. What is the minimum number needed so that every integer from 1 to 10 lies in at least one chosen interval?

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

Correct answer: C. 3

Greedy cover: from the leftmost uncovered integer, pick the interval containing it that reaches furthest right, and repeat. Brute force over subsets of the six intervals confirms the minimum.

More Coding Interview Problems questions

Exams that ask this topic