š Dynamic Programming Problems
Master memoization, tabulation, LCS, knapsack variations, and optimization problems
Given coin denominations and a target amount, find minimum coins needed.
Input: coins = [1,2,5], amount = 11 ā Output: 3 (5+5+1)
Find the length of longest common subsequence of two strings.
Input: "abcde", "ace" ā Output: 3 ("ace")
Given a string and dictionary, determine if string can be segmented into dictionary words.
Input: s = "leetcode", dict = ["leet","code"] ā Output: true
Find the length of longest strictly increasing subsequence.
Input: [10,9,2,5,3,7,101,18] ā Output: 4 ([2,3,7,101])
Find minimum operations (insert, delete, replace) to convert word1 to word2.
Input: "horse", "ros" ā Output: 3
Given weights and values of items, find maximum value that fits in knapsack capacity.
Rob 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)