04.13 · Lesson
Increasing Subsequences and Cuts
Shape A: the choice depends on your last pick
Longest increasing subsequence: pick numbers in order, each bigger than the last one you picked.
It’s take or skip, but you may take a[i] only if it is bigger than your last pick. So the call must remember that last pick.
- Promise:
f(i, prev)= longest increasing subsequence froma[i..], when the last pick isa[prev](prev = −1means none yet). - Base case:
i == n→ 0. - Choices: skip →
f(i + 1, prev). Take (ifprev == -1 || a[i] > a[prev]) →1 + f(i + 1, i). - Memo:
int[n][n + 1], used asmemo[i][prev + 1](shift by one, because −1 can’t be an index). Time O(n²).
solulu Pro
Continue this lesson with Pro
Inside: 3 sections · 2 videos · quiz.
- Shape A: the choice depends on your last pick
- Shape B: cut the input into pieces
- Spot them
Lifetime ₹1,999 ₹999 · Launch offer
Item 39 of 44 · updated 2026-10-13