Lesson

Dynamic Programming

Optimal substructure + overlapping subproblems → tabulated answers.

Medium → HardTime O(n)–O(n²)Space O(n)–O(n²)
Practice problems
Loading visualization…

Loading solution…

How to invent a DP

1) Define what dp[i] means in one sentence. 2) Relate it to smaller states. 3) Fill base cases. 4) Iterate in dependency order.

Studio

Climbing Stairs shows 1D transitions lighting previous two cells.

Families

Linear DP, grid DP, knapsack/subset, string DP (LCS/edit), tree DP, interval DP.

Pitfalls

  • !Vague state
  • !Wrong iteration order
  • !Off-by-one base cases
  • !Over-memoizing without clear key

Practice from this topic

Showing 24 of the related problems in the 1000-question bank.

View all →

Got the lesson?

Mark Dynamic Programming as understood when the ideas stick.