Fibonacci, Climbing Stairs
Either (memoization is simpler)
Both are O(n) time and space.
Here’s a topic-wise list of non-premium LeetCode DP problems, categorized by pattern. These problems are curated to help you build intuition step by step, from beginner to advanced.
1. 1D Dynamic Programming
Pattern: Solve problems using a 1D array where dp[i] depends on previous values.
2. 2D Dynamic Programming (Grid/Table)
Pattern: Use a 2D table where dp[i][j] depends on previous rows/columns.
3. Knapsack Problems
Pattern: Select items to maximize value without exceeding a weight/capacity constraint.
4. Interval DP
Pattern: Break problems into intervals and combine results.
5. State Compression DP
Pattern: Use bitmasking or states to represent subsets or configurations.
6. Digit DP
Pattern: Process numbers digit by digit with constraints.
7. Game Theory DP
Pattern: Model games where players take turns (e.g., minimax).
8. String DP
Pattern: DP problems involving string manipulation or matching.
9. Miscellaneous DP Problems
Pattern: Unique DP problems that don’t fit neatly into the above categories.
Longest Valid Parentheses
32. Longest Valid Parentheses
10. DP on Trees
Pattern: DP problems involving tree structures.
How to Use This List
Start with 1D DP: Master the basics with problems like Fibonacci, Climbing Stairs, and Coin Change. Move to 2D DP: Tackle grid-based problems like LCS, Edit Distance, and Unique Paths. Knapsack Problems: Practice selecting items under constraints. Interval DP: Learn to break problems into intervals and combine results. State Compression and Digit DP: Explore bitmasking and digit-by-digit processing. Game Theory and String DP: Apply DP to games and string manipulation. Miscellaneous and Tree DP: Challenge yourself with unique and advanced problems. Tips for Practicing
Solve in order: Start with easier problems and gradually move to harder ones. Time yourself: Aim to solve each problem within 30-45 minutes. Review solutions: After solving, compare your approach with the optimal solution. Revisit problems: Solve the same problem again after a few days to reinforce learning. Draw the DP table: Visualizing small cases helps you understand the pattern.