DSA Master › Topic 14

Dynamic Programming

DP is recursion plus caching. Start with the brute-force recursion, memoize it, then turn it into a bottom-up table if you need to. For every problem, answer four questions: what the state is, what the transition is, what the base cases are, and what order to fill the table in. Aim to recognise these, not to memorise solutions.

Concepts

How to recognise it

Common pitfalls

Problems

  1. Climbing Stairs (Easy)
  2. Min Cost Climbing Stairs (Easy)
  3. House Robber (Medium)
  4. House Robber II (Medium)
  5. Coin Change (Medium)
  6. Coin Change II (Medium)
  7. Maximum Subarray (Medium)
  8. Longest Increasing Subsequence (Medium)
  9. Longest Common Subsequence (Medium)
  10. Edit Distance (Medium)
  11. Word Break (Medium)
  12. Partition Equal Subset Sum (Medium)
  13. Target Sum (Medium)
  14. Unique Paths (Medium)
  15. Unique Paths II (Medium)
  16. Minimum Path Sum (Medium)
  17. Best Time to Buy and Sell Stock (Easy)
  18. Best Time to Buy and Sell Stock with Cooldown (Medium)
  19. Burst Balloons (Hard)
  20. Regular Expression Matching (Hard)