← 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])
- A.True False
- B.True True
- C.False False
- 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 →