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

Jobs are triples (start, end, weight): (1,3,2), (2,5,4), (4,6,3), (6,8,5), (5,9,6). Jobs may be chosen together only when one ends no later than the next begins. What is the maximum total weight?

  1. A. 12
  2. B. 9
  3. C. 19
  4. D. 10

Correct answer: D. 10

This is weighted interval scheduling: sort by end, use dp over the predecessor job that ends by the current start, and take the max of skipping or taking. Enumerating every subset gives the same optimum; for example (1,3), (4,6), (6,8) gives 2 + 3 + 5 = 10, and so does (2,5), (5,9).

More Coding Interview Problems questions

Exams that ask this topic