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

Half-open intervals [0,4), [1,3), [2,6), [5,7), [6,9), [8,10). What is the minimum number of integer points such that every interval contains at least one of the chosen points?

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

Correct answer: B. 3

Stabbing: sort by right end and pick a point at the right end of the first interval that is not yet hit. For half-open intervals the chosen point must lie strictly before the end, so the last integer of each interval is the point to use.

More Coding Interview Problems questions

Exams that ask this topic