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

Closed intervals [1,4], [2,6], [5,8], [7,9], [8,12], [10,11] must each contain at least one chosen integer point. What is the minimum number of points needed?

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

Correct answer: C. 3

Sort by right endpoint and place a point at the right end of the first unhit interval; every interval containing that point is hit. This matches the count of greedy disjoint intervals, where two intervals share a point exactly when they overlap.

More Coding Interview Problems questions

Exams that ask this topic