Data Structures & AlgorithmsModerateProduct Company SDE · Amazon OA

Problem: Given the intervals [1,4], [2,6], [3,5], [5,8], [7,9], [8,10] (closed, integer endpoints), what is the largest number of intervals that contain some common integer point?

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

Correct answer: B. 3

The maximum overlap is attained at some interval's start point, so sweeping integer points finds it. Counting intervals that merely intersect each other pairwise is a different measure.

More Coding Interview Problems questions

Exams that ask this topic