Space-Optimized Knapsack
Collapse 2D to a single row.
Why Optimize Space
A full table costs n times cap memory, which can explode on big inputs. Space optimization shrinks that to a single row you reuse.
Only the Last Row Matters
Notice each cell reads only the previous row, never anything older. So you never actually need to store the whole grid at once.
All lessons in this course
- 0/1 Knapsack: Take or Leave
- Space-Optimized Knapsack
- Unbounded & Coin-Change DP
- Subset Sum & Partition