Your concept feed

41 ideas

A few small steps. No rush.

Follow the connections in this topic

Let’s picture it

Keep the best tail for each length.

length 1 → tail 2
length 2 → tail 5

For values 3,5,2, a length-one subsequence ending at 2 is more useful than one ending at 3.

Swipe when you’re ready
One little change

Replace, do not claim one real sequence.

tails summary
not one path

Seeing 2 replaces the smallest tail for length one. The tails array summarizes possibilities that may come from different subsequences.

Same idea. One more small step.
Now it has a name

Binary-search the first large-enough tail.

lower bound
replace or append

A larger new value extends tails. Otherwise replace the first tail at least as large, keeping future extension easiest.

Want to try a tiny question?
No pressure. Just try it.

Does the tails array always equal an actual subsequence?

You can also keep scrolling
1 / 4
Advanced DP patterns

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Keep some numbers in order.

3 ×
1 ✓
2 ✓

From 3, 1, 2, we can keep 1 then 2. We are allowed to skip 3.

1 / 3
Let’s picture it

A day alone does not describe the future.

day i + holding
day i + free

On the same day, holding a share and holding none allow different next actions.

Swipe when you’re ready
One little change

Transactions add another label.

day
holding?
sales left

With at most k sales, remember how many completed transactions remain or have been used.

Same idea. One more small step.
Now it has a name

Update from yesterday’s states.

buy
sell
rest

A buy moves free→holding; a sell moves holding→free and completes one transaction. Rest keeps the state.

Want to try a tiny question?
No pressure. Just try it.

Does buying complete a buy-sell transaction?

You can also keep scrolling
1 / 4
Advanced DP patterns

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

We’ve answered this before.

route A
3 stairs left
route B

Two routes leave us with three stairs left. We may climb one or two at a time.

1 / 3
Let’s picture it

Two players choose from interval ends.

1
5
2

From [1,5,2], taking 2 leaves the opponent [1,5]. Immediate value alone does not decide the winner.

Swipe when you’re ready
One little change

Store score difference, not both totals.

my score − yours
interval L..R

Let dp[L,R] be current player’s best final advantage over the other player from that interval.

Same idea. One more small step.
Now it has a name

A move changes whose advantage it is.

take value
minus opponent answer

Taking left gives value[L] minus the opponent’s best advantage on the remaining interval.

Want to try a tiny question?
No pressure. Just try it.

Why subtract the smaller-game answer?

You can also keep scrolling
1 / 4
Advanced DP patterns

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Which cut should be last?

left part
split
right part

Some problems concern one stretch of items. Try choosing the final split, instead of the first action.

1 / 3
Let’s picture it

Count numbers under a bound.

0..325
avoid 7

How many values from 0 to 325 avoid digit 7? Listing all 326 numbers ignores repeated suffix questions.

Swipe when you’re ready
One little change

A prefix may still be tight.

position
tight?

After choosing a digit smaller than the bound’s digit, later positions may use 0..9. If equal, the bound still limits them.

Same idea. One more small step.
Now it has a name

Leading zeros describe shorter numbers.

042
leading zero
started?

Treat 42 as 042. Add a started flag only when zero before the first real digit must behave differently.

Want to try a tiny question?
No pressure. Just try it.

Which state says whether later digits still follow the bound?

You can also keep scrolling
1 / 4
Advanced DP patterns

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

We’ve answered this before.

route A
3 stairs left
route B

Two routes leave us with three stairs left. We may climb one or two at a time.

1 / 3
Let’s picture it

Fill a board one row at a time.

previous row
open vertical cells
next row

Dominoes cover two neighboring cells. Vertical dominoes begun above occupy cells in the next row.

Swipe when you’re ready
One little change

A bitmask describes the frontier.

column bits
occupied from above

One bit per column records which current-row cells are already filled from above.

Same idea. One more small step.
Now it has a name

Generate legal next masks.

place horizontal
place vertical
next profile

Fill the first empty cell horizontally within this row or vertically into the next row. Completed rows pass only the next mask.

Want to try a tiny question?
No pressure. Just try it.

Why is the entire finished part of the board unnecessary?

You can also keep scrolling
1 / 4
Advanced DP patterns

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Walk across four squares.

Start
·
·
Finish

Start at the top-left. Reach the bottom-right. For now, moves only go right or down.

1 / 3
Let’s picture it

All subsets are too many.

40 items
20 left
20 right

Forty values create about 2⁴⁰ subsets. Splitting into two groups creates two lists of about 2²⁰ sums.

Swipe when you’re ready
One little change

Enumerate each half independently.

left sum
+
right sum

Any full subset sum is one left-half sum plus one right-half sum.

Same idea. One more small step.
Now it has a name

Search for complementary halves.

target − left
search right

Sort right sums. For each left sum, binary-search values near target minus that sum.

Want to try a tiny question?
No pressure. Just try it.

Does this make subset search polynomial?

You can also keep scrolling
1 / 4
Advanced DP patterns

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Which towns are still unvisited?

visited: A,C
visited: B,C

Two travelers stand at C. One has visited A; the other has visited B. Their remaining tasks differ.

1 / 3
Let’s picture it

Each state reads a moving range.

window of old dp
take maximum

Suppose dp[i] needs the maximum dp among the previous k positions. Scanning all k repeats comparisons.

Swipe when you’re ready
One little change

Discard dominated candidates.

older smaller ×
newer larger ✓

Before adding a new dp value, remove smaller values from the back: they expire no later and can never win.

Same idea. One more small step.
Now it has a name

Expire from the front.

front = maximum
expired → pop

The deque stores useful indices in decreasing dp order. Remove the front when it falls outside the previous-k window.

Want to try a tiny question?
No pressure. Just try it.

Why can a smaller older candidate be removed?

You can also keep scrolling
1 / 4
Advanced DP patterns

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Pick snacks, but not neighbors.

4
5
4

The values are 4, 5, 4. Taking the middle snack blocks both neighbors.

1 / 3
Let’s picture it

Chance branches carry weights.

H: 1/2
T: 1/2

A fair coin moves heads or tails with probability one half. Two flips create four equally likely paths.

Swipe when you’re ready
One little change

Equivalent states can merge.

HT: 1/4
TH: 1/4
one head: 1/2

HT and TH both reach one head after two flips. Add their probabilities because the paths are disjoint.

Same idea. One more small step.
Now it has a name

Check total probability.

mass before:1
mass after:1

Every step redistributes probability mass. Across all reachable states it should remain one, aside from floating-point error.

Want to try a tiny question?
No pressure. Just try it.

When two disjoint paths reach one state, how do probabilities combine?

You can also keep scrolling
1 / 4
Advanced DP patterns

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

We’ve answered this before.

route A
3 stairs left
route B

Two routes leave us with three stairs left. We may climb one or two at a time.

1 / 3
You've reached the end of these ideas.Try them without the labels