🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: 0/1 Knapsack and Subset Sum: all 10 questions

Quiz: 0/1 Knapsack and Subset Sum · Question 5 of 10

What does this print? (code)

What does this print?

dp = [0] * 7
for c in range(2, 7):
    dp[c] = max(dp[c], 5 + dp[c - 2])
print(dp[6])
  1. A.5
  2. B.10
  3. C.0
  4. D.15
Answer & explanation

Correct answer: 15

The loop goes low to high, so the single item (weight 2, value 5) is reused three times. That is unbounded knapsack behaviour.

Can you get the rest right without peeking?

Take the timed Quiz: 0/1 Knapsack and Subset Sum quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →