Your concept feed
33 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 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 A window meets a negative number.
Find stretches totaling 2 in [2, −1, 1]. Adding −1 shrinks the sum, so the usual window direction is no longer reliable.
One new wrinkle Keep a running total instead.
Before anything: 0. After each number: 2, 1, 2. These totals describe the boundaries between items.
Try a tiny example Subtract two boundaries.
earlier: 0
current: 2
difference: 2
A current total of 2 minus an earlier total of 0 gives a stretch totaling 2.
Notice what matters Ask for the missing earlier total.
At total s, look for earlier total s − k. Count how often it appeared, then record s.
Make it reusable Prefix sums meet a dictionary.
The two valid stretches are [2] and [2, −1, 1]. We found both without trying every starting point again.
No pressure. Just try it.Why count earlier totals instead of keeping only a set?
1 / 6 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 Try every pair first.
In a sorted row [1,2,4,7], seek a pair totaling 9. Checking every pair repeats work.
One little change Look at both ends.
1 + 7 is too small. Moving the right pointer left only makes the sum smaller, so move the left pointer right.
Now it has a name Discard with a reason.
too small → left
too large → right
equal ✓
Now 2 + 7 = 9. Each move removes an entire family of impossible pairs, so both pointers move only forward overall.
No pressure. Just try it.When the sum is too small, which pointer can safely move?
1 / 4 A small step before this topic
A familiar idea Width and height both matter.
Lines of heights [1,8,6,2,5,4,8,3,7] form containers. Two chosen lines hold width times the shorter height.
One new wrinkle Start with maximum width.
The outer lines give width 8 and height 1. The shorter left wall limits the water.
Try a tiny example Move only the limiting wall.
shorter moves
taller stays
Moving the taller wall inward loses width while height stays capped by 1. Move the shorter wall and hope for a taller limit.
Notice what matters Keep the best seen.
The best pair uses heights 8 and 7 with width 7, giving 49. The proof discards pairs, not just guesses.
No pressure. Just try it.Why keep the taller wall when shrinking the width?
1 / 5 A small step before this topic
Let’s picture it Order can expose structure.
Unsorted values [4,1,3,1] hide equal neighbors and make smallest-first processing awkward.
One little change Sort once, scan simply.
After sorting: [1,1,3,4]. Duplicates touch, boundaries become visible, and two pointers become possible.
Now it has a name Account for the price.
sort cost
simpler scan
reuse order
Comparison sorting usually costs O(n log n). It is worthwhile only when the simpler scan or repeated queries repay that cost.
No pressure. Just try it.Does sorting preserve original positions automatically?
1 / 4 A small step before this topic
Let’s picture it Split until the promise is tiny.
A list of one item is already sorted. Split [4,1,3,2] into smaller lists until reaching that base case.
One little change Merge two sorted answers.
From [1,4] and [2,3], repeatedly take the smaller front item. Neither front can be beaten by anything behind it.
Now it has a name The levels have equal total work.
Each merge level touches n items, and there are logarithmically many levels.
No pressure. Just try it.Why is the smaller front safe to output next?
1 / 4 A small step before this topic
Let’s picture it Choose a pivot value.
For [4,1,3,2], choose 3. We want smaller values before it and larger values after it.
One little change Grow a finished left region.
Scan the range. Whenever a value is at most the pivot, swap it beside the completed smaller region.
Now it has a name Only recurse where order is unknown.
After partitioning, the pivot is in its final position. Sort the two sides; never sort the pivot again.
No pressure. Just try it.Does a fixed bad pivot keep O(n log n) time?
1 / 4 A small step before this topic
Let’s picture it We need one rank, not full order.
To find the second largest in [3,2,1,5,6,4], fully sorting every relationship is extra work.
One little change Partition gives a final rank.
Place a pivot so smaller values lie left and larger values lie right. Its index is final even though each side remains unsorted.
Now it has a name Follow only the useful side.
If the target rank lies right of the pivot, discard the entire left side and pivot.
No pressure. Just try it.After the pivot lands on the target rank, must its sides be sorted?
1 / 4 A small step before this topic
Let’s picture it Comparisons are not the only information.
Values [2,0,2,1] come from the tiny known range 0..2. Count each value directly.
One little change Counts rebuild sorted order.
Emit zero once, one once, and two twice. No pairwise comparisons are needed.
Now it has a name Large keys need digits or another plan.
count range
stable digit passes
Radix sort groups by one digit at a time using a stable inner sort. Tiny range and fixed-width digits are different guarantees.
No pressure. Just try it.Is counting sort efficient when keys range from 0 to one trillion?
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 A sorted row was rotated.
[4,5,6,7,0,1,2] has one break. We seek 0 without scanning every value.
One little change One half is still sorted.
At middle 7, the left half 4..7 is ordered. Since 0 is not inside its value range, discard that half.
Now it has a name Use order before choosing a side.
which half sorted?
target inside?
At every step, identify a sorted half, then ask whether the target lies inside its bounds.
No pressure. Just try it.Can duplicate values hide which half is sorted?
1 / 4 A small step before this topic
Let’s picture it Intervals hide overlap when shuffled.
[8,10], [1,3], [2,6] are hard to combine in input order.
One little change Sort by starting point.
Now [1,3] and [2,6] touch in the scan. Because 2 ≤ 3, extend the current end to 6.
Now it has a name A gap closes one group.
[8,10] starts after 6, so emit [1,6] and begin a new current interval.
No pressure. Just try it.What single value summarizes the merged group while scanning?
1 / 4 A small step before this topic
Let’s picture it Meetings change a running count.
Meeting [1,4) adds one active room at 1 and removes one at 4.
One little change Sort all changes by position.
For [1,4) and [2,3), events are +1, +1, −1, −1. The largest running total is two.
Now it has a name Tie order encodes endpoint meaning.
For half-open meetings, an ending at time 3 frees a room before another meeting beginning at 3 uses one.
No pressure. Just try it.Why must equal-position events have a defined order?
1 / 4 A small step before this topic
Let’s picture it Update a whole range cheaply.
Add 3 to positions 1 through 3. Instead of touching three cells, record +3 where the effect begins.
One little change Cancel just after the range.
Record −3 at position 4. A running sum carries the update across positions 1,2,3 and removes it afterward.
Now it has a name Many updates combine before one scan.
two marks per update
one final scan
Each range contributes two boundary changes. One prefix sum reconstructs every final value.
No pressure. Just try it.Does a difference array answer arbitrary online point queries immediately?
1 / 4 A small step before this topic
Let’s picture it A running stretch may become harmful.
For [4,−7,5], carrying 4−7 into the last value gives 2. Restarting at 5 is better.
One little change One state ends exactly here.
start here
extend previous
At each position, compare starting fresh with extending the best stretch that ended one position earlier.
Now it has a name Keep a separate global best.
The best ending here may fall, while the best seen anywhere must never be forgotten.
No pressure. Just try it.For an all-negative list, may the answer be zero?
1 / 4 A small step before this topic
Let’s picture it Only three values exist.
Arrange [2,0,2,1,1,0] so every 0 precedes every 1, which precedes every 2.
One little change Name four regions.
Keep completed zeros, completed ones, unknown values, and completed twos. Three pointers mark their boundaries.
Now it has a name Inspect only the unknown front.
0 → left
1 → next
2 → right
A 0 moves left, a 1 stays, and a 2 swaps right. After swapping right, inspect the incoming value before advancing.
No pressure. Just try it.After swapping a 2 with the unknown right edge, may the scan always advance?
1 / 4 A small step before this topic
Let’s picture it Only a small value range can answer.
With n items, the first missing positive lies between 1 and n+1. Values outside 1..n cannot fill those n positions.
One little change Give each useful value a home.
1 → index 0
2 → index 1
3 → index 2
Value x belongs at index x−1. Swap values toward their homes while the current useful value is misplaced.
Now it has a name Scan for the first mismatch.
After placement, the first index i not holding i+1 reveals the missing positive.
No pressure. Just try it.Why stop swapping when the destination already holds the same value?
1 / 4 A small step before this topic
Let’s picture it Different keys can share one bucket.
With three buckets, keys hashing to 1 must coexist. A hash is not a unique identity.
One little change Store and compare real keys.
hash → bucket
equality → key
Separate chaining keeps a small list per bucket. Hash chooses the list; equality finds the exact entry.
Now it has a name Resize before chains grow too long.
load grows
new table
rehash
When load factor rises, allocate more buckets and rehash every key because bucket positions depend on capacity.
No pressure. Just try it.May a hash match replace an equality check?
1 / 4 A small step before this topic
Let’s picture it A maximum expires as the window moves.
For [1,3,−1,−3,5] with width 3, the first window maximum is 3. Later, 3 leaves.
One little change Keep useful candidates in a deque.
front = max
decreasing values
Remove smaller values from the back before adding a new index. They expire no later and cannot become maximum.
Now it has a name Remove expired indices from the front.
Indices reveal whether the current maximum lies before the new window’s left boundary.
No pressure. Just try it.Why store indices instead of only values?
1 / 4 Keep a connection for later.
Tap the bookmark on any post to find it here.