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

Weighted intervals (start, end, value): (0,5,4), (3,9,6), (6,10,3), (9,12,5). Choose two intervals that do not overlap (touching at an endpoint is allowed) to maximise total value. What is the maximum total value?

  1. A. 11
  2. B. 14
  3. C. 9
  4. D. 12

Correct answer: A. 11

Compare every pair of intervals: two intervals are compatible when one ends no later than the other starts. Among compatible pairs, the best total here is the answer; the pair with the single highest value may not be compatible with a second high-value interval.

More Coding Interview Problems questions

Exams that ask this topic