Your concept feed

34 ideas

A few small steps. No rush.

Follow the connections in this topic

Let’s picture it

Pick snacks, but not neighbors.

4
5
4

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

Swipe when you’re ready
One little change

Taking less first can win.

4 ✓
5 ×
4 ✓

Take the first 4 and the last 4. Their total is 8, which beats 5.

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

Ask about the row from here.

take: i + 2
skip: i + 1

At position i, compare taking it and moving two places, or skipping it and moving one. One position names this smaller question.

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

After taking position i, where can we continue?

You can also keep scrolling
1 / 4
1D dynamic programming

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

Pick dots, but not parent and child.

5
4
4

The parent is worth 5. Each of its two children is worth 4.

Swipe when you’re ready
One little change

Skipping the parent can help.

skip 5
take 4
take 4

Take both children for 8. Taking the parent would block them and give only 5.

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

Keep two answers per little tree.

take root
skip root

Best if we take its root. Best if we skip its root. The parent uses whichever child choices its own decision allows.

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

If we take a parent, may we take its immediate child in this problem?

You can also keep scrolling
1 / 4
1D dynamic programming

One small step at a time.

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

Count a tiny family of dots.

Parent
Child: 1
Child: 1

One parent has two children. Each child says, “There’s one of me.”

1 / 3
A familiar idea

How far is everyone from each home?

A
B
C

Three homes form A–B–C. From A, distances total 0+1+2 = 3. From B, they total 1+0+1 = 2.

Swipe when you’re ready
One new wrinkle

Move the measuring point one edge.

2 closer
1 farther

Move from A to B. B and C become one step closer. Only A becomes one step farther.

Same idea. One more small step.
Try a tiny example

Update instead of starting over.

3
− 2 + 1
2

The total changes from 3 to 3 − 2 + 1 = 2. A whole side of the tree moves together.

Same idea. One more small step.
Notice what matters

Count both sides using subtree size.

closer: size[v]
farther: n − size[v]

For parent u and child v, size[v] nodes get closer; n − size[v] get farther. answer[v] = answer[u] + n − 2×size[v].

Same idea. One more small step.
Make it reusable

Two passes are enough.

gather upward
reuse downward

First gather subtree sizes and the root’s total. Then pass the updated answer from each parent to its children. That’s rerooting DP.

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

Why does the simple two-side update depend on the input being a tree?

You can also keep scrolling
1 / 6
1D dynamic programming

One small step at a time.

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

Pick dots, but not parent and child.

5
4
4

The parent is worth 5. Each of its two children is worth 4.

1 / 3
Let’s picture it

Make 3 using coins 1 and 2.

1 + 2
2 + 1

We could use 1 then 2, or 2 then 1.

Swipe when you’re ready
One little change

What are we counting?

orders: 2
combination: 1

Those are two orders, but the same combination of coins. The question decides whether to count them separately.

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

Same ingredients, different tasks.

fewest?
orders?
combinations?

Fewest coins, number of orders, and number of combinations are different questions. Decide which answer one cell is storing.

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

If order doesn’t matter, are 1+2 and 2+1 two combinations?

You can also keep scrolling
1 / 4
1D dynamic programming

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

Keep some numbers in order.

3 ×
1 ✓
2 ✓

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

Swipe when you’re ready
One little change

Ask what can end here.

1
2

For the 2, an earlier smaller number such as 1 can extend into a longer increasing sequence.

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

Gaps are allowed.

keep order
allow gaps

A subsequence preserves order without needing neighboring positions. That’s different from one continuous window.

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

Can we reorder 3, 1, 2 into 1, 2, 3 as a subsequence?

You can also keep scrolling
1 / 4
1D dynamic programming

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
A familiar idea

A word ending is a possible jump.

car
ca
rs

Split cars using dictionary words car, ca, and rs. The longest first match is car.

Swipe when you’re ready
One new wrinkle

The longest match gets stuck.

car | s ×
ca | rs ✓

car leaves s, which is not a word. ca leaves rs, which is. We must consider more than one ending.

Same idea. One more small step.
Try a tiny example

Ask whether a suffix can finish.

position i
remaining string
yes or no

Let can[i] mean the string from position i onward can be split. The empty suffix can finish.

Same idea. One more small step.
Notice what matters

A trie offers candidate endings.

trie match
word end
can[next]?

Walk forward through the trie. At each complete word, check whether the suffix after it can finish.

Same idea. One more small step.
Make it reusable

Trie plus one-position DP.

0
2
4

The trie discovers legal jumps. DP combines them into a complete route through string boundaries.

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

Why is the longest dictionary match not automatically best?

You can also keep scrolling
1 / 6
1D dynamic programming

One small step at a time.

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

Car and cat start the same way.

c
a
r / t

Write c, then a, just once. Split where the words become different.

1 / 3
A familiar idea

Keep the same word-boundary idea.

a | a | a | a
aa | aa

For aaaa with words a and aa, many sentences work. Now we need all of them, not just yes or no.

Swipe when you’re ready
One new wrinkle

First mark which suffixes can finish.

suffix possible?
keep or prune

Reuse Word Break’s yes/no DP. It tells us which candidate endings would lead into a dead end.

Same idea. One more small step.
Try a tiny example

Then walk every surviving branch.

choose
explore
undo

Choose a word, append it, explore the rest, then undo. The trie supplies word endings along the way.

Same idea. One more small step.
Notice what matters

Reuse impossibility, not one favorite sentence.

a | a
aa
same suffix

Two different prefixes can reach the same suffix. Both must be retained when the output asks for every sentence.

Same idea. One more small step.
Make it reusable

Trie, DP, and backtracking cooperate.

trie
DP
backtracking

The first generates choices, the second removes dead ends, and the third emits answers. Many valid outputs still take time to write.

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

Can memoization make printing exponentially many sentences take linear time?

You can also keep scrolling
1 / 6
1D dynamic programming

One small step at a time.

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

A word ending is a possible jump.

car
ca
rs

Split cars using dictionary words car, ca, and rs. The longest first match is car.

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