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

Closed intervals [2,9], [4,7], [6,12], [10,14], [11,13], [15,18]. What is the total length of the set of points covered by at least one interval (measured as the length of the union)?

  1. A. 25
  2. B. 10
  3. C. 13
  4. D. 8

Correct answer: B. 10

Merge overlapping intervals after sorting by start; the union is [2,14] plus [15,18], total 12 + 3 = 15. Adding raw lengths counts the overlapped parts twice, which is why that total is larger.

More Coding Interview Problems questions

Exams that ask this topic