2D DP Problems
2D DP Problems
Section titled “2D DP Problems”Two-dimensional DP problems have two state variables — typically representing indices into two arrays/dimensions. The DP table is a 2D matrix dp[i][j].
📋 Problems
Section titled “📋 Problems”| # | Problem | Pattern | Difficulty |
|---|---|---|---|
| 1 | Unique Paths | Grid traversal | Medium |
| 2 | 0/1 Knapsack | Take/skip items | Medium |
| 3 | Longest Common Subsequence | String alignment | Medium |
| 4 | Edit Distance | String transformation | Hard |
⚡ Quick Recurrence Reference
Section titled “⚡ Quick Recurrence Reference”Unique Paths: dp[i][j] = dp[i-1][j] + dp[i][j-1] (sum of paths)Knapsack: dp[i][w] = max(dp[i-1][w], dp[i-1][w-wt] + val) (skip or take)LCS: match? dp[i-1][j-1]+1 : max(dp[i-1][j], dp[i][j-1]) (match or skip)Edit Distance: match? dp[i-1][j-1] : 1+min(delete, insert, replace) (3 ops)Start with Unique Paths →