🎙 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 8 of 10

What does this print? (code)

What does this print?

nums, target = [3, 4, 5], 8
can = [True] + [False] * target
for x in nums:
    for t in range(target, x - 1, -1):
        can[t] = can[t] or can[t - x]
print(can[8], can[6])
  1. A.True False
  2. B.True True
  3. C.False False
  4. D.False True
Answer & explanation

Correct answer: True False

8 = 3 + 5. 6 would need 3 twice, and each number can be used only once.

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 →