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

Busy intervals [2,5), [4,7), [9,12), [11,13), [15,16) lie inside the working day [0, 20). How many time units in the day are free, i.e. not covered by any busy interval?

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

Correct answer: B. 10

Sort the busy intervals, merge the overlapping ones, and subtract the merged total from the day length. Adding the raw lengths double-counts the overlap between [2,5) and [4,7) and gives the trap.

More Coding Interview Problems questions

Exams that ask this topic