Trace one-row knapsack
Standard · Trace the algorithm · about 6 min
Follow one-row knapsack on weights [2, 3, 4], values [3, 4, 6] and capacity 6. Answer each question before the step plays.
Example 1
Input:
{"weights":[2,3,4],"profits":[3,4,6],"capacity":6}
Output:
9
Constraints
- The trace uses the input shown.
- Each item is packed at most once.
Learn the idea first: Space optimization: rolling rows and variables, a visual lesson.
More Space optimization: rolling rows and variables problems
- Why iterate in reverse Warm-up
- Optimize unique paths Standard
- Knapsack in 1-D Standard
- House robber in two variables Standard
- Edit distance in O(min(m, n)) space Challenge