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

Closed intervals [1,3], [2,6], [3,5], [4,8], [7,9], [9,11], [10,12]. Two intervals conflict if they share any point, endpoints included. What is the largest number of pairwise non-conflicting intervals?

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

Correct answer: A. 3

Sort by right endpoint and greedily take the next interval whose start is strictly greater than the last chosen end. Closed endpoints matter: [7,9] and [9,11] share the point 9 and conflict, which changes the count.

More Coding Interview Problems questions

Exams that ask this topic