Skip to content
CodeItRaw
Path

Never solve the same subproblem twice: memoization, tables and state transitions.

Key ideas

  • Never solve the same subproblem twice: keep the answer in a table.
  • Define the state ("best up to i"), then the transition: dp[i] comes from a few earlier values.
  • Often only the last one or two values matter; you do not need the whole table.

Pattern

dp = [0] * (n + 1)
for i in range(1, n + 1):
    dp[i] = max(dp[i - 1], dp[i - 2] + gain(i))

Finish these first:Recursion & Divide and ConquerHashing

Lessons

Each lesson explains one idea from zero and ends with a few tasks. Lessons open in order; the explanation can be read at any time.

  1. 01

    From recursion to a table

    0/2 tasks

  2. 02

    Remembering, and take it or leave it

    0/2 tasks

  3. 03

    "The best that ends here"

    0/2 tasks

  4. 04

    Amounts and grids

    0/3 tasks

Boss

  • 05

    Longest Increasing

    Function

  • The boss opens when every lesson of the topic is finished. Solve it too and the topic is complete, and the topics after it open.