š Dynamic Programming Problems
Master memoization, tabulation, LCS, knapsack variations, and optimization problems
Coin Change - Minimum coins to make amount
MediumGiven coin denominations and a target amount, find minimum coins needed.
Input: coins = [1,2,5], amount = 11 ā Output: 3 (5+5+1)
Longest Common Subsequence
MediumFind the length of longest common subsequence of two strings.
Input: "abcde", "ace" ā Output: 3 ("ace")
Word Break - Can string be segmented?
MediumGiven a string and dictionary, determine if string can be segmented into dictionary words.
Input: s = "leetcode", dict = ["leet","code"] ā Output: true
Longest Increasing Subsequence
MediumFind the length of longest strictly increasing subsequence.
Input: [10,9,2,5,3,7,101,18] ā Output: 4 ([2,3,7,101])
Edit Distance (Levenshtein Distance)
HardFind minimum operations (insert, delete, replace) to convert word1 to word2.
Input: "horse", "ros" ā Output: 3
0/1 Knapsack Problem
MediumGiven weights and values of items, find maximum value that fits in knapsack capacity.
House Robber - Maximum non-adjacent sum
MediumRob houses along a street without robbing two adjacent houses.
Input: [2,7,9,3,1] ā Output: 12 (2+9+1)
Dynamic Programming Patterns
- ā 1D DP: Fibonacci, climbing stairs, house robber, coin change
- ā 2D DP: LCS, edit distance, unique paths, knapsack
- ā Interval DP: Matrix chain multiplication, burst balloons
- ā State Machine: Best time to buy/sell stock variants
- ā Memoization vs Tabulation: Top-down vs bottom-up approaches
- ā Space Optimization: Often can reduce from O(n²) to O(n)