Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

Half-open intervals [1,4), [2,6), [3,5), [5,8), [7,9), [8,10) are given. What is the largest number of them you can select so that no time point lies in more than two selected intervals?

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

Correct answer: B. 5

Brute force over all 64 selections checks the peak depth of each one; the answer is the largest selection whose peak depth is at most 2. A selection rule that only looks at the earliest end can exceed the depth limit.

More Coding Interview Problems questions

Exams that ask this topic