Skip to main content

🧩 Dynamic Programming

DP is just recursion with memoization, recognized. Identify the state (what defines a unique subproblem) and the recurrence (how subproblem answers combine). Everything else is implementation detail.

This category contains 38 problems. Use the patterns below to recognize what's being asked, then jump to the problem list at the bottom.


🧠 Key Patterns​

  • 1D DP β€” House Robber, Climbing Stairs, Decode Ways. State = index.
  • 2D DP β€” LCS, Edit Distance, Interleaving. State = (i, j) on two strings.
  • Knapsack β€” 0/1 vs Unbounded. Capacity + item index as state.
  • Interval DP β€” Matrix Chain, Burst Balloons. State = (l, r). Try every split point.
  • Grid DP β€” Unique Paths, Min Path Sum. State = (i, j) cell.
  • Bitmask DP β€” TSP, assignment. State = (mask, last). Sets up to ~20 elements.
  • State Machine β€” Stock problems. State = (day, holding, transactions_left).

⚠️ Common Pitfalls​

  • Starting from tabulation when memoized recursion is clearer. Write recursion first, then add memo.
  • Wrong base case (empty string, zero capacity).
  • Forgetting space optimization: many 2D DPs only need the previous row.

πŸ“š Study Resources​

πŸ“Ί Videos​

πŸ“– Books​

🌐 Articles & References​


πŸ’» All Dynamic Programming Problems​