solulubeta
Sign in
Cheat Sheets / Coding
02.03 · Cheat sheet

Recursion & DP

The recursion recipe, base-case values, pick-or-skip and backtracking templates, the 4 memo steps, table loop order and the six DP patterns on one page.

3 min Cheat sheet Pro

Work out any recursion or DP problem in the same order, every time.

The recipe

  1. Promise: what does f(...) return? One sentence.
  2. Base case: the smallest input with an obvious answer.
  3. Smaller step: trust the smaller call and build your answer from it.
  4. Check: every call gets closer to the base case.

Base cases and combining

QuestionGood endImpossibleCombine
Count ways10+
Possible?truefalse||
Minimum0(int) 1e9Math.min
Maximum0(int) -1e9Math.max
List allsave a copyreturncall all

Check guards before reading: i == a.length before a[i].

solulu Pro

Continue this cheat sheet with Pro

Inside: 8 sections.

  • The recipe
  • Base cases and combining
  • Pick or skip
  • Backtracking
  • Memo in 4 steps
  • Memo → table
  • +2 more
Lifetime ₹1,999 ₹999 · Launch offer
Mark this as done when you are finished.

Item 7 of 12 · updated 2026-10-13