Pen first
You cannot read your way to writing an algorithm.
Reading builds recognition, and recognition feels exactly like understanding right up until you face a blank editor. That gap is why people who happily explain binary search still cannot write it.
So these lessons hide the code. Do not take our word for it, the box on the right has no explanation in it at all. Just start tapping.
Try it, no signup
Looks used: 0 / 10 allowed
Find 23. Tap the middle card.
The cards are sorted. Ten cards, and you are only allowed a handful of looks. Where is the only sensible place to start?
How every lesson runs
Desk 1
Paper
Run it with your finger. No code exists yet.
Desk 2
Rule
Your own trace is the evidence. Name why it works.
Desk 3
Logic
Write the method in plain English. Still no syntax.
Desk 4
Code
Real Python, checked against your own hand trace.
16 algorithms you already "know".
Grouped by the move, not the data structure, because an interview never says "this is a heap question".
Before the patterns
How to measure cost, and how a function calls itself. Everything below leans on these two.
Big-O
You see it, not memorise it
Count by hand until the growth is obvious. Then never guess a complexity again.
Every interview asks it out loud. Most people answer by vibes.
Start at the paper->Recursion
Nothing happens on the way down
Run the call stack with your finger. The trust comes after you have seen it unwind.
Recursion is not hard. Trusting the smaller copy is.
Start at the paper->Scan smarter
One pass beats every pair. Learn what lets you skip.
Hash map
1 pass, not 28 pairs
One pass, no pairs. Write down what you have seen and the answer walks up to you.
The nested loop is everyone's instinct. It is also the reject.
Start at the paper->Two pointers
4 looks, not 28
Skip almost every pair on purpose, and be able to prove it was safe.
Most people can run it. Few can say why skipping is allowed.
Start at the paper->Sliding window
1 pass, not every run
Stop restarting the count. Carry the window and never re-read a card.
Restarting the scan feels efficient. It is still quadratic.
Start at the paper->Binary search
3 looks, not 10
Find it in 3 looks, not 10, and prove the half you threw away was innocent.
Roughly 9 in 10 professional programmers write it wrong.
Start at the paper->Fast & slow pointers
1 pass, no counting
Find the middle in a single pass, with two fingers at different speeds.
Count first, then walk again, is two passes. A stream only gives you one.
Start at the paper->Order matters
Sort it, stack it, or keep only the best few.
Monotonic stack
1 pass, not n squared
Stop scanning to the right. Park who is waiting and let the answer find them.
Scan-right-for-each is the obvious answer, and the quadratic one.
Start at the paper->Top k / heap
3 kept, 0 sorted
Keep the best 3 out of a million without sorting the million.
Sorting everything to keep three is the reflex. On a stream it is impossible.
Start at the paper->Intervals
Look back once, not at everything
Merge overlapping meetings, and know why you never look back more than one.
This bug never crashes. It just quietly returns the wrong answer.
Start at the paper->Greedy
And the case where it fails
Take the biggest coin. Then find out exactly when that stops working.
Greedy is right until the coins change, and most people never learn the edge.
Start at the paper->Follow the structure
Trees, graphs and letters: the shape rules out the rest.
Trees
3 nodes, not 7
Half the tree disappears at every step. Prove the answer was not in it.
Checking every node turns a tree back into a list.
Start at the paper->BFS
Shortest, provably
Find the exit, and prove nobody could have found it faster.
Depth-first finds an exit. It rarely finds the shortest one.
Start at the paper->Tries
Prefix length, not dictionary size
Autocomplete a million words without reading any of them.
Scanning the dictionary works for six words and dies at a million.
Start at the paper->Search the space
When you must explore, prune hard and never repeat work.
Backtracking
Prune, do not enumerate
Choose, hit a wall, undo. And prune the dead branches before you walk them.
Every combination is 2 to the n. Pruning is the only reason it finishes.
Start at the paper->Dynamic programming
n steps, not 2 to the n
Notice you are solving the same step over and over. Write it down once.
The naive recursion is elegant, and it makes over a million calls at n=30.
Start at the paper->