What goes in the blank?
# 0/1 knapsack, one row reused
for w in range(cap, weight - 1, ____):
dp[w] = max(dp[w], dp[w - weight] + value)
Answer: -1
Iterating downwards stops one item being taken twice in the same pass.
Play Problem Solving ▸
# 0/1 knapsack, one row reused
for w in range(cap, weight - 1, ____):
dp[w] = max(dp[w], dp[w - weight] + value)
Answer: -1