Your concept feed
41 ideas
Follow the connections in this topic
A small step before this topic
Let’s picture it Let’s start with three stops.
Home. Then the park. Then the café. Just a few things in a row.
One little change Point to the middle one.
The park is second. In Python, its position is 1, because counting starts at 0.
Now it has a name That’s a list.
A list keeps things in order. An index is just a position in that list.
No pressure. Just try it.Which place is at position 0?
1 / 4 A small step before this topic
Let’s picture it Now visit each stop.
You don’t need three different instructions. “Visit the next place” works each time.
One little change One, then the next.
Finish home. Move to the park. Then do the same at the café.
Now it has a name That repeat is a loop.
One small action, repeated for each item. Three stops mean three visits.
No pressure. Just try it.Add one more stop. How many visits now?
1 / 4 A small step before this topic
Let’s picture it What if it rains?
Let’s choose the café on rainy days, and the park on sunny days.
One little change Today is sunny.
The rule stays the same. The weather changed, so we choose the other place.
Now it has a name That’s an if / else.
Raining?
Yes: café
No: park
A condition is a yes-or-no question. Its answer chooses which step happens next.
No pressure. Just try it.It’s raining. Where does our rule send us?
1 / 4 A small step before this topic
Let’s picture it Name a tiny job.
Our job is “add one.” Give it 3, and it gives back 4.
One little change Try a new input.
Give the same job 8. It gives back 9. We can reuse the instructions.
Now it has a name That job is a function.
Input goes in. An answer comes back. In Python, return sends the answer back.
No pressure. Just try it.What does add-one return for 5?
1 / 4 A small step before this topic
Let’s picture it Picture a pile of plates.
Blue goes down first. Pink goes on top.
One little change Take the top one.
Pink comes off first, even though blue arrived first.
Now it has a name That’s a stack.
Last in, first out. Paused function calls work this way too: finish the newest call, then return.
No pressure. Just try it.Add green on top. Which plate comes off next?
1 / 4 A small step before this topic
Let’s picture it Now picture a line of people.
Ana arrives first. Bo waits behind her.
One little change Ana goes first.
Bo moves to the front. New arrivals join the back.
Now it has a name That’s a queue.
First in, first out. Unlike plates, we serve the oldest waiting item first.
No pressure. Just try it.Who goes before Cy?
1 / 4 A small step before this topic
Let’s picture it Have we visited the park?
Keep a little checklist of places we’ve seen.
One little change Write park again.
We still only need one check beside park. We’re remembering whether, not how many times.
Now it has a name That’s a set.
A set keeps distinct items. “Is park in here?” becomes a quick membership check.
No pressure. Just try it.Add park twice. How many copies in a set?
1 / 4 A small step before this topic
Let’s picture it Let’s remember a little more.
The park is five minutes away. Write that beside its name.
One little change Look it up later.
Ask for “park.” The notebook gives you 5. No need to measure the walk again.
Now it has a name That’s a dictionary.
A key finds a value. Here, the place name is the key and the time is the value.
No pressure. Just try it.We now write park: 6. What does park return?
1 / 4 A small step before this topic
Let’s picture it Draw our little walk.
A dot for each place. A line where we can walk directly.
One little change Two short walks can join.
Home to park, then park to café. We can reach the café without a direct road.
Now it has a name Dots and links have names.
A dot is a node. A link is an edge. Together, they make a graph.
No pressure. Just try it.Must two places share a direct road to be reachable?
1 / 4 A small step before this topic
Let’s picture it Where did we put the book?
Try “second shelf, first box.” We need two positions, not just one.
One little change Pick a row, then a column.
Python calls the second row 1. The first column is 0. So the book is at [1][0].
Now it has a name That’s a two-dimensional table.
Two labels find one cell. A third label could tell us which cupboard contains the table.
No pressure. Just try it.Two cupboards have the same shelves. What extra label helps?
1 / 4 A small step before this topic
Let’s picture it Same door. One small difference.
You have a key. Your friend doesn’t. The door is the same, but your next move isn’t.
One little change Remember the key.
If we only write down “at the door,” we lose something important.
Now it has a name That little note is a state.
A state remembers what we need to continue. Here: where we are, and whether we have the key.
No pressure. Just try it.Is “at the door” enough to decide if we can enter?
1 / 4 A small step before this topic
Let’s picture it How many little jobs?
Visit three places. Say hello once at each. That’s three hellos.
One little change Now try every pair.
Three people each greet all three people, including themselves for this toy count. That’s nine greetings.
Now it has a name Count how the work grows.
One pass grows with n. Trying every pair grows with n × n. Code length doesn’t tell us that.
No pressure. Just try it.With 4 items, how many ordered pairs, including self-pairs?
1 / 4 A small step before this topic
Let’s picture it Find 8 in a sorted row.
Start with 2, 4, 6, 8, 10. Look at the middle: 6.
One little change Keep the side that can work.
8 is bigger than 6. Everything on the left is too small, so we can leave it behind.
Now it has a name Keep one promise.
If 8 is present, it stays in the part we keep. That repeating promise is called an invariant.
No pressure. Just try it.Would this left-or-right shortcut work on an unsorted row?
1 / 4 A small step before this topic
Let’s picture it Keep a small part of a row.
Our budget is 5. The values 2 and 3 fit together.
One little change One more makes it too much.
Add 4: the sum is 9. Remove from the left until it fits again.
Now it has a name That moving part is a window.
left edge
kept values
right edge
With nonnegative values, adding cannot lower the sum. That predictable change tells us which boundary to move.
No pressure. Just try it.Could adding a negative number make a too-large sum fit?
1 / 4 A small step before this topic
A familiar idea Who is still waiting for warmth?
Temperatures are 73, 71, 74. The first two days have not yet seen a warmer day.
One new wrinkle 74 answers two questions.
73: wait 2
71: wait 1
74: waiting
It is warmer than 71, and also warmer than 73. Their waits end together.
Try a tiny example Keep only unanswered days.
Store their positions in a stack. Temperatures go downward from the bottom toward the top.
Notice what matters Resolve the top while you can.
waiting index
today’s index
subtract
When a warmer day arrives, pop each cooler waiting day and record the distance between their positions.
Make it reusable That’s a monotonic stack.
Each day enters once and leaves at most once. The nested while loop still does only linear total popping.
No pressure. Just try it.Does a day at 73 resolve an earlier day at 73?
1 / 6 A small step before this topic
Let’s picture it Open a box.
There’s a smaller box inside. We already know how to open a box.
One little change Do the same small job again.
Open the smaller box. Keep going until there isn’t another box inside.
Now it has a name That’s the idea of recursion.
A function asks itself to handle a smaller case. The empty box is our stopping point: the base case.
No pressure. Just try it.What if every box contains another box forever?
1 / 4 A small step before this topic
Let’s picture it A question can make two more.
Climb one or two stairs at a time. Four stairs can lead to a smaller question with three or two left.
One little change Look, the same question returns.
ways(3) also asks for ways(2). We’ve reached that smaller question twice.
Now it has a name Notice the repeated work.
Draw the calls to spot repeated questions. Later, we’ll save their answers instead of solving them again.
No pressure. Just try it.Do two calls with the same input always need separate work here?
1 / 4 A small step before this topic
Let’s picture it Search for the first yes.
In [no,no,no,yes,yes], the answer is the first yes, not merely any yes.
One little change Keep a half-open range.
Maintain [left,right) containing the boundary. Test middle; yes keeps the left half, no discards through middle.
Now it has a name Stop when no uncertainty remains.
When left equals right, the range is empty and that position is the first true answer.
No pressure. Just try it.If middle is true, may we discard middle too?
1 / 4 A small step before this topic
Let’s picture it Count a tiny family of dots.
One parent has two children. Each child says, “There’s one of me.”
One little change Let the answers travel up.
The parent adds the two answers, then counts itself: 1 + 1 + 1.
Now it has a name That works for bigger trees too.
my answer
left answer
right answer
Ask each child about its little tree. Combine the answers. You don’t need to hold the whole tree in your head.
No pressure. Just try it.Do we also count the parent itself?
1 / 4 A small step before this topic
Let’s picture it Come back to our little map.
Home, park, café. Each place is a dot; each allowed walk is a link.
One little change A dot can also mean a situation.
“At park with a key” may allow a move that “at park without a key” cannot.
Now it has a name Choose dots that tell the whole story.
situation
legal move
new situation
A graph organizes possible moves. Sometimes places are enough. Sometimes a place plus a small extra fact is needed.
No pressure. Just try it.Must graph nodes always represent physical places?
1 / 4 A small step before this topic
Let’s picture it Try the nearest places first.
From home, find everything one road away before looking two roads away.
One little change Put new places at the back.
A queue keeps the earlier discoveries in front. That lets us finish one layer before the next.
Now it has a name That’s breadth-first search: BFS.
With equal-cost roads, the first layer reaching a place uses the fewest roads. Unequal costs need more care.
No pressure. Just try it.One road costs 100 minutes; two others cost 1 each. Fewest roads means fastest?
1 / 4 A small step before this topic
Let’s picture it Follow one path for a while.
Instead of finishing a whole layer, keep walking down one branch. This is depth-first search, or DFS.
One little change Remember where you’ve been.
For reachability, a seen set helps avoid walking around the same cycle forever.
Now it has a name But ask what “seen” means.
this attempt
undo mark
next attempt
For routes that cannot repeat a place, a place used in one attempt may be free in another. Clear path-only marks when returning.
No pressure. Just try it.Does “used in this path” always mean “forbidden in every path”?
1 / 4 A small step before this topic
Let’s picture it Socks before shoes.
Some jobs must wait for other jobs. Draw an arrow from the earlier job to the later one.
One little change Start with a ready job.
Do a job with nothing unfinished before it. Remove it from the waiting list and look for the next ready job.
Now it has a name That makes a dependency order.
A waits for B
B waits for A
Its name is topological order. A cycle means some jobs keep waiting on one another, so no such order exists.
No pressure. Just try it.A waits for B, and B waits for A. Can either start under these rules?
1 / 4 A small step before this topic
Let’s picture it Try a snack combination.
Pick apple first. See what can go with it. We’re exploring, not committing forever.
One little change Put it back and try again.
After exploring the apple choices, undo that pick. Now start with banana.
Now it has a name That’s backtracking.
Choose, explore, undo. Undoing keeps the next attempt from accidentally inheriting the last attempt’s choices.
No pressure. Just try it.Before a sibling attempt, what happens to path-only choices?
1 / 4 A small step before this topic
Let’s picture it 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.
One little change Save these three little routes.
The routes are 1+1+1, 1+2, and 2+1. Count them once; both arrivals can reuse the answer.
Now it has a name That sharing is the heart of DP.
same question
reuse answer
Dynamic programming saves answers to smaller questions. Share only when the remaining question really is the same.
No pressure. Just try it.One route has a key left and the other doesn’t. Always the same remaining question?
1 / 4 A small step before this topic
Let’s picture it Two ways to fill a notebook.
One way: when a question appears, solve it if needed, then write down the answer.
One little change Or prepare the small answers first.
Fill answers in an order where each needed earlier answer is already available.
Now it has a name Same idea, different order.
Saving answers on demand is memoization. Filling them in a planned order is tabulation.
No pressure. Just try it.When filling a table, should an answer be ready before another cell uses it?
1 / 4 A small step before this topic
Let’s picture it Pick snacks, but not neighbors.
The values are 4, 5, 4. Taking the middle snack blocks both neighbors.
One little change Taking less first can win.
Take the first 4 and the last 4. Their total is 8, which beats 5.
Now it has a name Ask about the row from here.
At position i, compare taking it and moving two places, or skipping it and moving one. One position names this smaller question.
No pressure. Just try it.After taking position i, where can we continue?
1 / 4 A small step before this topic
Let’s picture it Keep some numbers in order.
From 3, 1, 2, we can keep 1 then 2. We are allowed to skip 3.
One little change Ask what can end here.
For the 2, an earlier smaller number such as 1 can extend into a longer increasing sequence.
Now it has a name Gaps are allowed.
A subsequence preserves order without needing neighboring positions. That’s different from one continuous window.
No pressure. Just try it.Can we reorder 3, 1, 2 into 1, 2, 3 as a subsequence?
1 / 4 A small step before this topic
Let’s picture it Walk across four squares.
Start at the top-left. Reach the bottom-right. For now, moves only go right or down.
One little change Two tiny routes.
Right, then down. Or down, then right. Both reach the same finish.
Now it has a name A square can share its answer.
Row and column name the remaining journey. With only right/down moves, we can fill answers without moving in circles.
No pressure. Just try it.If moves can go in circles, is this simple fill order automatically safe?
1 / 4 A small step before this topic
Let’s picture it Keep letters in the same order.
Compare abc with ac. We can keep a, skip b, then keep c. The shared sequence is ac.
One little change Put a bookmark in each word.
After keeping a, we compare b with c. Skipping b moves only the first bookmark. Now c matches c.
Now it has a name Two bookmarks name one question.
position in word 1
position in word 2
Ask for the longest shared sequence remaining. Equal letters can join it; otherwise, try skipping from either string and keep the better answer.
No pressure. Just try it.May we rearrange letters to make the shared sequence longer?
1 / 4 A small step before this topic
Let’s picture it Which cut should be last?
Some problems concern one stretch of items. Try choosing the final split, instead of the first action.
One little change Solve the two sides.
If that split makes the sides independent, combine their best answers and the split’s cost.
Now it has a name Name a stretch by its ends.
left boundary
right boundary
Interval DP uses a left and right boundary. Try possible split points. First check that the two sides really are independent.
No pressure. Just try it.Can we combine two independently solved sides if hidden choices still link them?
1 / 4 A small step before this topic
A familiar idea Give three places their own switches.
Rightmost is A, middle is B, leftmost is C. A lit bit means that place has been visited.
One new wrinkle Visit A, then C.
Turn on A’s bit: 001. Then C’s bit: 101. The same places in another order produce the same mask.
Try a tiny example Use OR to turn a bit on.
mask
single bit
OR combines
1 << v makes a single lit bit at position v. mask | (1 << v) includes that place without switching other bits off.
Notice what matters Use AND to ask whether it is on.
membership: &
include: |
all: 111
mask & (1 << v) is nonzero exactly when v is included. All three places visited gives 111.
Make it reusable Small notation. Still many possible sets.
Three bits allow eight masks. n bits allow 2ⁿ. A compact representation does not make every subset search cheap.
No pressure. Just try it.Does 101 remember whether A or C was visited first?
1 / 6 A small step before this topic
Let’s picture it Which towns are still unvisited?
Two travelers stand at C. One has visited A; the other has visited B. Their remaining tasks differ.
One little change Keep a tiny checklist.
For A, B, C, the bits 1, 0, 1 mean A and C have been visited.
Now it has a name The chosen set can be state.
Subset DP remembers which items are included, often alongside a current position. n yes/no choices give 2ⁿ possible subsets.
No pressure. Just try it.Does a compact bitmask make the number of possible subsets small?
1 / 4 A small step before 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.
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.
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.
No pressure. Just try it.Does the tails array always equal an actual subsequence?
1 / 4 A small step before this topic
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.
One little change Transactions add another label.
With at most k sales, remember how many completed transactions remain or have been used.
Now it has a name Update from yesterday’s states.
A buy moves free→holding; a sell moves holding→free and completes one transaction. Rest keeps the state.
No pressure. Just try it.Does buying complete a buy-sell transaction?
1 / 4 A small step before this topic
Let’s picture it Two players choose from interval ends.
From [1,5,2], taking 2 leaves the opponent [1,5]. Immediate value alone does not decide the winner.
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.
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.
No pressure. Just try it.Why subtract the smaller-game answer?
1 / 4 A small step before this topic
Let’s picture it Count numbers under a bound.
How many values from 0 to 325 avoid digit 7? Listing all 326 numbers ignores repeated suffix questions.
One little change A prefix may still be tight.
After choosing a digit smaller than the bound’s digit, later positions may use 0..9. If equal, the bound still limits them.
Now it has a name Leading zeros describe shorter numbers.
Treat 42 as 042. Add a started flag only when zero before the first real digit must behave differently.
No pressure. Just try it.Which state says whether later digits still follow the bound?
1 / 4 A small step before this topic
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.
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.
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.
No pressure. Just try it.Why is the entire finished part of the board unnecessary?
1 / 4 A small step before this topic
Let’s picture it All subsets are too many.
Forty values create about 2⁴⁰ subsets. Splitting into two groups creates two lists of about 2²⁰ sums.
One little change Enumerate each half independently.
Any full subset sum is one left-half sum plus one right-half sum.
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.
No pressure. Just try it.Does this make subset search polynomial?
1 / 4 A small step before this topic
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.
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.
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.
No pressure. Just try it.Why can a smaller older candidate be removed?
1 / 4 A small step before this topic
Let’s picture it Chance branches carry weights.
A fair coin moves heads or tails with probability one half. Two flips create four equally likely paths.
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.
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.
No pressure. Just try it.When two disjoint paths reach one state, how do probabilities combine?
1 / 4 Keep a connection for later.
Tap the bookmark on any post to find it here.