Your concept feed
45 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 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 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 Two trees can make different promises.
In a search tree, smaller keys go left and larger keys go right. We’ll use distinct keys here.
One little change A heap promises something else.
A min-heap keeps the smallest value at the top. Its left and right sides need not be sorted.
Now it has a name Choose the promise you need.
Looking for an ordered key? Think search tree. Repeatedly taking the smallest? Think min-heap.
No pressure. Just try it.Does a min-heap promise its left side is smaller than its right?
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
A familiar idea Two oranges start rotten.
In this row, both ends are rotten at minute zero. The middle orange is fresh.
One new wrinkle Both ends spread together.
The middle turns rotten after one minute. We should not finish one source’s entire search before starting the other.
Try a tiny example Put all starts in the queue.
all starts: 0
neighbors: 1
next: 2
Give every rotten orange distance zero. Then process the next layer just as in ordinary BFS.
Notice what matters First arrival wins.
Mark a fresh orange when it enters the queue. Two nearby sources must not count it twice.
Make it reusable One search, many beginnings.
The last reached fresh orange determines the time. If any fresh orange remains unreachable, return −1.
No pressure. Just try it.One fresh orange is isolated by empty cells. What happens?
1 / 6 A small step before this topic
A familiar idea A graph without drawn roads.
Turn cat into dog. Allowed intermediate words are cot and cog. Change one letter per move.
One new wrinkle Let each word be a place.
Two words are neighbors when one legal letter change connects them. The dictionary decides which places exist.
Try a tiny example Every move costs one.
0 changes
1 change
2 changes
BFS visits words one change away, then two, then three. First arrival gives the fewest changes.
Notice what matters Read what the answer counts.
cat → cot → cog → dog uses three changes, but four words. This problem asks for the number of words.
Make it reusable Generate roads only when needed.
change letter
allowed word?
enqueue
Try letter replacements and check dictionary membership. We do not need to compare every pair of words first.
No pressure. Just try it.Does choosing the word most similar to dog prove a shortest route?
1 / 6 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 Can neighbors use different colors?
Give A blue and its neighbor B pink. Then C, beside B, can be blue.
One little change Now connect C back to A.
They are both blue. Changing one forces another clash around this three-node circle.
Now it has a name Some graphs cannot use just two colors.
3-edge cycle
needs more colors
A triangle is the smallest example. More generally, an odd-length cycle prevents a two-coloring.
No pressure. Just try it.If part of the graph is disconnected, should we check it too?
1 / 4 A small step before this topic
Let’s picture it Are these people on the same team?
Ana and Bo belong together. Cy is on a separate team.
One little change Join the teams.
A new connection joins Bo and Cy. Now all three share one group.
Now it has a name Use one name for each group.
Union-find tracks group membership as connections arrive. It can tell us whether two items belong together, not the route between them.
No pressure. Just try it.Does knowing two places share a group tell us their shortest path?
1 / 4 A small step before this topic
A familiar idea The groups need not be towns.
One account lists emails a and b. Another lists b and c. Shared b says these records belong together.
One new wrinkle Remember the first owner of each email.
When b appears again, join its previous account with the current one.
Try a tiny example A third record can join indirectly.
A record containing c and d joins the same group. It never needed to share a directly.
Notice what matters Collect by final representative.
After all merges, put each email into its root’s group and sort the emails for the required output.
Make it reusable Union-find fits the requested answer.
shared email ✓
same name only ×
We need identities grouped together, not a shortest chain of matching accounts. Matching names alone would not prove shared identity.
No pressure. Just try it.Two records say Ana but share no linked email. Merge them?
1 / 6 A small step before this topic
A familiar idea Join A to B, then B to C.
All three towns now belong to the same group. The two roads form a tree.
One new wrinkle Now add A to C.
There was already a path between them. This new road closes a cycle.
Try a tiny example Ask before each union.
If both endpoints already have the same root, the new edge is redundant for connectivity.
Notice what matters Input order gives the requested edge.
different roots: join
same root: answer
For a tree plus one extra edge, the failed union identifies the last edge of that cycle in the input.
No pressure. Just try it.Can we ignore arrows and use this to detect directed cycles?
1 / 5 A small step before this topic
A familiar idea Three squares already form one island.
These three land squares touch. The bottom-right square is water. We may turn one water square into land.
One new wrinkle The water touches A twice.
Its upper and left neighbors are different squares, but they belong to the same island.
Try a tiny example Do not count that island twice.
1 new square
1 distinct island
size 4
The new size is 1 + 3 = 4, not 1 + 3 + 3. Deduplicate the neighboring roots.
Notice what matters Group once. Test small changes.
group first
test each flip
Build every island’s root and size. For each water square, add one plus the sizes of its distinct neighboring groups.
Make it reusable A hard problem becomes local.
Union-find supplies group summaries. The flip only examines four neighbors. Flood-fill labels would supply the same summaries too.
No pressure. Just try it.Would scoring two flips independently always find their best combined result?
1 / 6 A small step before this topic
Let’s picture it Roads take different times.
A→B takes 5. A→C takes 1, and C→B takes 1.
One little change Visit the cheapest waiting place.
C is closest at 1. Going through it improves the time to B from 5 to 2.
Now it has a name That’s Dijkstra’s choice.
smallest distance
settle
relax neighbors
Settle the cheapest known waiting distance. Nonnegative road costs make that finalization safe; a min-heap helps pick the next one.
No pressure. Just try it.What assumption makes this ordinary finalization rule safe?
1 / 4 A small step before this topic
A familiar idea Follow the arrow for free.
In this grid, moving along a cell’s arrow costs 0. Choosing a different direction costs one arrow change.
One new wrinkle A longer route can be cheaper.
3 free moves: 0
1 change: 1
Three free moves cost less than one changed arrow. Ordinary BFS’s move count is the wrong score.
Try a tiny example Keep cheap arrivals at the front.
From cost d, a free move stays at d. A changed arrow moves to d + 1.
Notice what matters A deque has two useful ends.
Push a zero-cost improvement to the front. Push a one-cost improvement to the back.
Make it reusable That’s 0–1 BFS.
better distance?
update
queue end
We retain cheapest-first exploration without a heap because every edge costs exactly zero or one. Revisit a cell if its cost improves.
No pressure. Just try it.If some direction changes cost 7, does this deque rule still work?
1 / 6 A small step before this topic
A familiar idea What makes a walk difficult?
4, 4 → effort 4
1, 6 → effort 6
One route has jumps 4 and 4. Another has jumps 1 and 6. Effort means the biggest single jump.
One new wrinkle Do not add the jumps.
sum: 8, effort: 4
sum: 7, effort: 6
The first route totals 8 but is gentler. The second totals 7 but contains the larger jump.
Try a tiny example Keep the worst jump so far.
max(4, 2) = 4
max(4, 7) = 7
Extending effort 4 with a jump of 2 keeps effort 4. A jump of 7 raises it to 7.
Notice what matters The score cannot fall as we walk.
heap minimum
max on extension
That lets Dijkstra settle the smallest waiting effort. Relax with max(old effort, new jump) instead of addition.
Make it reusable Same structure. Different path score.
cell
neighbor
height difference
A grid cell is still a node. Four neighboring cells supply edges weighted by their height differences.
No pressure. Just try it.Which score should the heap prioritize here?
1 / 6 A small step before this topic
Let’s picture it A road gives a refund.
A→B costs 2. A→C costs 5. C→B refunds 4, so that edge costs −4.
One little change A later route becomes cheaper.
Through C, B costs only 1. Calling B final at 2 would have been too early.
Now it has a name Recheck improvements instead.
check edges
improve
check again
Bellman–Ford repeatedly checks edges. A reachable negative cycle means some distances can keep decreasing instead of having a finite minimum.
No pressure. Just try it.Does a negative edge alone always mean a negative cycle?
1 / 4 A small step before this topic
A familiar idea Now every city asks about every other.
A→B costs 8. A→C costs 2, and C→B costs 3. We want distances between all pairs.
One new wrinkle Allow one new intermediate city.
If C is allowed between A and B, their best cost improves to 2 + 3 = 5.
Try a tiny example Give the table a precise meaning.
from i
to j
allowed through k
After processing city k, each entry is best among routes using only the intermediate cities allowed so far.
Notice what matters Try that one bridge for every pair.
Compare d[i][j] with d[i][k] + d[k][j]. Keep k as the outer loop so every pair gets the same new permission.
Make it reusable Floyd–Warshall is graph DP.
all distances
count nearby
break ties
For the city problem, count distances within the threshold. Among tied smallest counts, choose the larger city number.
No pressure. Just try it.Should this cubic-time method be your default for a huge sparse graph?
1 / 6 A small step before this topic
Let’s picture it Connect three towns with cable.
AB costs 1, BC costs 2, and AC costs 5. We want everyone connected cheaply.
One little change Two cables are enough.
Take AB and BC. All towns connect for 3. Adding AC would make an unnecessary cycle.
Now it has a name That’s a minimum spanning tree.
total cable cost
not every route
Minimize the total connection cost. This differs from minimizing each travel distance from a starting town.
No pressure. Just try it.If the original graph is disconnected, can cables from its edges connect every town?
1 / 4 A small step before this topic
A familiar idea Grow one connected piece of the network.
AB costs 1, AC costs 4, and BC costs 2. Start with only A inside.
One new wrinkle Take the cheapest edge leaving the piece.
AB adds B for 1. The connected piece is now {A, B}.
Try a tiny example Refresh the crossing choices.
C can join through AC for 4 or BC for 2. Choose BC; the network costs 3.
Notice what matters The heap key is an edge cost.
Prim: next edge
Dijkstra: whole route
Prim grows one tree through cheapest crossing edges. Dijkstra instead prioritizes total route costs from a source.
Make it reusable Kruskal reaches the same objective differently.
one growing tree
many merging trees
Kruskal sorts all edges and merges many groups. Prim grows one group. Both minimize total connecting cost, not every travel distance.
No pressure. Just try it.Can Prim’s selected routes replace Dijkstra’s shortest routes?
1 / 6 A small step before this topic
A familiar idea Let water open the grid gradually.
Heights are 0, 3 on top and 1, 2 below. A square is usable once water reaches its height.
One new wrinkle At level 1, only two squares open.
0 open
3 closed
1 open
2 closed
Start and bottom-left connect. The finish at height 2 is still closed.
Try a tiny example At level 2, the finish joins.
The route 0 → 1 → 2 becomes possible. No need to wait for the height-3 square.
Notice what matters Activate, then merge neighbors.
Sort squares by height. Each new square joins its already-open neighbors through union-find.
Make it reusable Stop when the corners share a group.
level rises
groups merge
corners meet
This is the same bottleneck idea as minimum effort, viewed as increasing a threshold until a route exists.
No pressure. Just try it.Must every square be open before we can finish?
1 / 6 A small step before this topic
A familiar idea Which road has no backup?
A, B, C form a triangle. D connects only to B. Removing B–D separates D.
One new wrinkle DFS gives each arrival a time.
Explore A, then B, then C. C can reach earlier A without retracing its parent edge.
Try a tiny example Send the earliest reachable time upward.
C reports 0 back to B. The triangle’s branch has another way back, so B–C is not a bridge.
Notice what matters D cannot report an escape.
If low[D] is greater than B’s arrival time, D’s branch cannot get back without B–D. That edge is a bridge.
Make it reusable One DFS, one summary per branch.
arrival time
lowest escape
parent edge
This low-link summary avoids removing every edge and rerunning reachability. Track edge IDs so parallel roads are handled correctly.
No pressure. Just try it.Two parallel roads connect A and B. Is either one a bridge?
1 / 6 A small step before this topic
A familiar idea Arrows change what a group means.
A reaches B, and B reaches A. B also reaches C, but C cannot return.
One new wrinkle Only mutual reachability makes a group.
A and B share one strongly connected component. C belongs to another.
Try a tiny example First remember finishing order.
explore children
then record node
Run DFS and write each node after its outgoing exploration finishes. These finishing times identify which regions to handle first.
Notice what matters Reverse arrows. Follow reverse finish order.
reverse edges
latest finish first
collect group
A second DFS on reversed edges collects one component at a time. The finishing order prevents drifting into an unprocessed neighboring component.
Make it reusable Shrink each group into one dot.
The remaining graph is acyclic: a cycle between groups would mean they should have been one mutual-reachability group.
No pressure. Just try it.Does ordinary union-find preserve which directed nodes can return to each other?
1 / 6 A small step before this topic
A familiar idea One exit does not make a place safe.
A can go to an exit or enter a loop. The question asks whether every possible walk eventually stops.
One new wrinkle Start with places that must stop.
A terminal node has no outgoing choices. It is safe immediately.
Try a tiny example Work backward from safe places.
all choices safe
node safe
Once every outgoing neighbor of a node is safe, that node is safe too. One safe neighbor is not enough.
Notice what matters Reverse the edges to notify predecessors.
safe child
notify parents
count reaches 0
Remove each proven-safe outgoing choice. A remaining-outdegree count of zero makes the predecessor ready.
Make it reusable Cycles never become ready.
Nodes on a cycle, or able to reach one, retain an unsafe choice. This is topological elimination from the other end.
No pressure. Just try it.A has one road to an exit and one to a cycle. Is A safe?
1 / 6 A small step before this topic
Let’s picture it Neighbors must sit on opposite sides.
For A—B—C, place A left, B right, and C left.
One little change A cycle can create a contradiction.
In triangle A—B—C—A, alternating colors makes C both opposite B and opposite A.
Now it has a name Color every component.
new component
color 0
alternate
Start an uncolored node with either color, then BFS or DFS while enforcing opposite colors on every edge.
No pressure. Just try it.Which cycle length makes two-coloring impossible?
1 / 4 A small step before this topic
Let’s picture it The task is about edges, not vertices.
A→B, B→A, A→C can be walked using every directed edge exactly once: A,B,A,C.
One little change Following an edge may create a dead end.
take unused edge
walk until stuck
Do not finalize a vertex when first seen. Keep walking unused edges until stuck.
Now it has a name Build the answer backward.
dead end → append
reverse finishes
When a vertex has no unused outgoing edge, append it. Reversing these finish points gives the trail.
No pressure. Just try it.Why is an ordinary visited-vertex set wrong here?
1 / 4 A small step before this topic
Let’s picture it Edges have capacities.
Source can send 3 units to A, and A can send only 2 to sink. This route carries at most 2.
One little change Used capacity leaves a reverse option.
forward remaining
reverse undo
Sending one unit creates residual ability to undo that unit. A later path can reroute an earlier choice.
Now it has a name Find augmenting level paths.
BFS levels
send flow
repeat
BFS builds distance levels in the residual graph. DFS sends flow only forward through those levels until blocked.
No pressure. Just try it.Why does the residual graph contain reverse edges?
1 / 4 A small step before this topic
Let’s picture it Each left item wants one right item.
Workers A,B can do jobs X,Y. Each worker and job may appear in at most one chosen pair.
One little change A direct choice may block another worker.
If A takes X, B may have nowhere. An augmenting path can move A to Y and give X to B.
Now it has a name Search for one more assignment.
unmatched edge
matched edge back
free job
From each unmatched left vertex, follow unused edges and matched edges alternately to reach a free right vertex.
No pressure. Just try it.Why may an existing match need to move?
1 / 4 A small step before this topic
Let’s picture it The target can guide exploration.
current
estimated remainder
goal
On a grid, Manhattan distance estimates remaining moves without crossing walls.
One little change Order by spent plus estimated.
g spent
h estimate
f total guess
Dijkstra orders by g, the cost already paid. A* orders by f=g+h to prefer states promising a smaller total.
Now it has a name The estimate needs a promise.
If h never overestimates the true remaining cost, popping the goal under the usual conditions gives an optimal route.
No pressure. Just try it.What happens when h is always zero?
1 / 4 A small step before this topic
Let’s picture it Removing one vertex removes all its edges.
In A—B—C with B—D, removing B separates A, C, and D.
One little change Child summaries reveal backup routes.
For DFS child v, low[v] tells the earliest ancestor its subtree can reach without using the parent edge.
Now it has a name Roots need a separate rule.
non-root ≥
root children >1
A non-root u is fragile when some child has low[v] ≥ disc[u]. A root is fragile only with multiple DFS children.
No pressure. Just try it.Why does the bridge test use > while a non-root articulation test uses ≥?
1 / 4 A small step before this topic
Let’s picture it Deletions are hard for ordinary union-find.
Roads disappear over time. Union-find can join groups quickly but cannot split a stored tree when one road vanishes.
One little change If all questions are known, reverse them.
final graph
reverse
add roads back
The final graph contains roads never deleted. Moving backward turns each deletion into an addition.
Now it has a name Answer before undoing each deletion.
query roots
reverse delete → union
Process operations backward. Connectivity queries use current roots; a forward delete becomes a reverse union.
No pressure. Just try it.What property makes reverse-time processing possible?
1 / 4 Keep a connection for later.
Tap the bookmark on any post to find it here.