$ ./guess_the_languageProblem Solving — fill the blank
Problem Solving — fill the blank · hard · #275

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 (also accepted: -1)

Iterating downwards stops one item being taken twice in the same pass.
Play Problem Solving ▸