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

Four tasks each have (time, value): (3,2), (2,5), (4,4), (5,3). Choose any subset of tasks with total time at most 9 to maximise total value. What is that maximum value?

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

Correct answer: C. 11

Enumerating all 16 subsets, the best within time 9 is (3,2) + (2,5) + (4,4): time 9, value 11. Requiring time < 9 gives 9, taking all four tasks (time 14) breaks the limit and gives 14, and reusing the (2,5) task four times as in unbounded knapsack gives 20.

More Coding Interview Problems questions

Exams that ask this topic