โ† Coding Interview Prep (LeetCode) learning path
Coding Interview Prep (LeetCode) ยท Module 9 of 10

Dynamic programming

DP solves problems by combining answers to smaller overlapping subproblems.

๐Ÿ“– Key ideas

  1. Look for optimal substructure and overlapping subproblems.
  2. Memoisation caches recursive results (top-down).
  3. Tabulation fills a table from small to large (bottom-up).
  4. Classic problems: climbing stairs, house robber, coin change, longest common subsequence, knapsack.
  5. Define the state, the transition and the base case.
๐Ÿ’ก Real-life example: Like remembering multiplication tables: once you know 6 x 7, you reuse it instead of adding 6 seven times again.
MemoisationCache results of recursive calls
TabulationFill a DP table bottom-up
StateWhat a subproblem represents
TransitionFormula linking states