Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional

Problem: A 0/1 knapsack has capacity 10 and items (weight, value): (5, 10), (4, 40), (6, 30), (3, 50). What is the maximum total value?

  1. A. 90
  2. B. 105
  3. C. 150
  4. D. 130

Correct answer: A. 90

The DP over capacity finds (4, 40) + (3, 50) = 90 with weight 7; no remaining item fits in 3. Fractional knapsack would add half of (6, 30) for 105, reusing (3, 50) three times (unbounded) gives 150, and 130 takes every item while ignoring the capacity.

More Coding Interview Problems questions

Exams that ask this topic