The Blind 75 and more
The Blind 75, plus 26 more that companies ask often, grouped by pattern.
Tick them off as you go. Your progress stays on this device.
- EasyGo to lesson →
You keep asking “have I seen this before?”, so keep a set.
- Time
- O(n)
- Space
- O(n)
- EasyGo to lesson →
Only the letter counts matter, so count and compare.
- Time
- O(n)
- Space
- O(1)
- EasyGo to lesson →
Each number tells you exactly which partner it needs, so look the partner up.
- Time
- O(n)
- Space
- O(n)
- MediumGo to lesson →
Words that belong together share a key: their sorted letters or letter counts.
- Time
- O(n·k)
- Space
- O(n·k)
- MediumGo to lesson →
Count with a map, then bucket values by their count.
- Time
- O(n)
- Space
- O(n)
Also works with Heaps.
- MediumGo to lesson →
Write each length first, so you never need a separator that could clash.
- Time
- O(n)
- Space
- O(n)
- MediumGo to lesson →
Everything to my left times everything to my right: two running products.
- Time
- O(n)
- Space
- O(1)
- MediumGo to lesson →
A set lets you count only from the true start of each run.
- Time
- O(n)
- Space
- O(n)
- EasyGo to lesson →
Compare the outside pair, then work inward.
- Time
- O(n)
- Space
- O(1)
- MediumGo to lesson →
- MediumGo to lesson →
Start with the widest pair. Only moving the shorter line can ever help.
- Time
- O(n)
- Space
- O(1)
Also works with Greedy.
Watch it run
- EasyGo to lesson →
Hold the cheapest day so far on the left and let the right edge scan.
- Time
- O(n)
- Space
- O(1)
Also works with Greedy or 1-D DP.
- MediumGo to lesson →
An unbroken stretch with a rule: grow on the right, shrink on the left when it breaks.
- Time
- O(n)
- Space
- O(k)
- MediumGo to lesson →
A stretch is fine while its length minus the count of its most common letter is at most k.
- Time
- O(n)
- Space
- O(1)
- HardGo to lesson →
- EasyGo to lesson →
Lots of range questions on fixed data: pay O(n) once, then answer each in O(1).
- Time
- O(1) per query
- Space
- O(n)
- MediumGo to lesson →
Negative numbers break a sliding window, but a total minus an earlier total still gives any run.
- Time
- O(n)
- Space
- O(n)
Also works with Arrays & Hashing.
Watch it run - MediumGo to lesson →
Equal counts become a zero sum. The longest run starts just after a total first appeared.
- Time
- O(n)
- Space
- O(n)
- MediumGo to lesson →
Two totals with the same remainder mod k differ by a multiple of k.
- Time
- O(n)
- Space
- O(min(n, k))
- MediumGo to lesson →
The same remainder at two cuts means the run between them divides by k.
- Time
- O(n)
- Space
- O(k)
- EasyGo to lesson →
- MediumGo to lesson →
Brackets nest, and the innermost one has to be expanded first.
- Time
- O(output)
- Space
- O(output)
- MediumGo to lesson →
* and / come before + and -, so keep each term until you know its sign.
- Time
- O(n)
- Space
- O(n)
- MediumGo to lesson →
Each day waits until a warmer one arrives. The newest waiting day is answered first.
- Time
- O(n)
- Space
- O(n)
- HardGo to lesson →
A bar’s rectangle stops at the first shorter bar on each side.
- Time
- O(n)
- Space
- O(n)
- HardGo to lesson →
Water sits in a dip until a taller bar on the right closes it.
- Time
- O(n)
- Space
- O(n)
Also works with Two Pointers.
Watch it run - HardGo to lesson →
A new value makes every smaller one before it useless, so drop them from the back.
- Time
- O(n)
- Space
- O(k)
Also works with Sliding Window or Heaps.
- EasyGo to lesson →
The array is sorted, so the middle value tells you which half the target is in.
- Time
- O(log n)
- Space
- O(1)
- MediumGo to lesson →
Row by row, the grid is one sorted list, so index mid maps to row mid / cols, column mid % cols.
- Time
- O(log(m·n))
- Space
- O(1)
- MediumGo to lesson →
Don’t stop at the first match. Keep halving to find the edge of the run of copies.
- Time
- O(log n)
- Space
- O(1)
- MediumGo to lesson →
If the value after mid is bigger, a peak must lie to its right, because the climb has to stop somewhere.
- Time
- O(log n)
- Space
- O(1)
- MediumGo to lesson →
Comparing the middle to the right end tells you which half holds the drop.
- Time
- O(log n)
- Space
- O(1)
- MediumGo to lesson →
One half is always in order. Check whether the target sits inside it.
- Time
- O(log n)
- Space
- O(1)
- MediumGo to lesson →
If a speed is fast enough, every faster speed is too. That yes/no flips once.
- Time
- O(n log m)
- Space
- O(1)
- HardGo to lesson →
Checking a cap is easy: fill each piece until it would overflow. A bigger cap never needs more pieces.
- Time
- O(n log s)
- Space
- O(1)
Also works with Greedy.
- HardGo to lesson →
Taking i from the first array fixes how many come from the second. Check the four values at the cut.
- Time
- O(log min(m, n))
- Space
- O(1)
- EasyGo to lesson →
- EasyGo to lesson →
Compare the two heads and relink the smaller one.
- Time
- O(n + m)
- Space
- O(1)
- EasyGo to lesson →
A fast walker and a slow walker only meet if there’s a loop.
- Time
- O(n)
- Space
- O(1)
Also works with Two Pointers.
Watch it run - MediumGo to lesson →
Find the middle, reverse the back half, then weave the two.
- Time
- O(n)
- Space
- O(1)
Also works with Two Pointers.
- MediumGo to lesson →
Two walkers n apart: when the front one hits the end, the back one is in place.
- Time
- O(n)
- Space
- O(1)
Also works with Two Pointers.
- HardGo to lesson →
Merge in pairs, halving the number of lists each round.
- Time
- O(n log k)
- Space
- O(1)
Also works with Heaps.
- MediumGo to lesson →
Each value can carry the minimum of everything under it, so a pop never loses the answer.
- Time
- O(1)
- Space
- O(n)
Also works with Stack.
- MediumGo to lesson →
You need a fast lookup and an order of use at once: a map plus a doubly linked list.
- Time
- O(1)
- Space
- O(capacity)
Also works with Linked List.
Watch it run - MediumGo to lesson →
Each key's timestamps arrive in order, so its list is already sorted for a binary search.
- Time
- O(log n)
- Space
- O(n)
Also works with Binary Search.
- MediumGo to lesson →
A random pick needs an array, and a fast remove needs a map from value to its position.
- Time
- O(1)
- Space
- O(n)
Also works with Arrays & Hashing.
- EasyGo to lesson →
Handle one node and let recursion do the rest.
- Time
- O(n)
- Space
- O(h)
- EasyGo to lesson →
- EasyGo to lesson →
Walk both at once. One mismatch ends it.
- Time
- O(n)
- Space
- O(h)
- EasyGo to lesson →
Run the same-tree check from every node.
- Time
- O(n·m)
- Space
- O(h)
- MediumGo to lesson →
Walk down until the two values fall on different sides, or you land on one of them.
- Time
- O(h)
- Space
- O(1)
- MediumGo to lesson →
- MediumGo to lesson →
Pass an allowed range down as you go.
- Time
- O(n)
- Space
- O(h)
- MediumGo to lesson →
An in-order walk visits values in sorted order.
- Time
- O(h + k)
- Space
- O(h)
Also works with Heaps.
- MediumGo to lesson →
Preorder names the root. Inorder splits left from right.
- Time
- O(n)
- Space
- O(n)
- HardGo to lesson →
Each node passes up its best straight arm and scores its best bend.
- Time
- O(n)
- Space
- O(h)
- HardGo to lesson →
Walk it and write down the gaps too.
- Time
- O(n)
- Space
- O(n)
- MediumGo to lesson →
- MediumGo to lesson →
Walk a tree of letters, and branch everywhere on a dot.
- Time
- O(26^L) worst
- Space
- O(total letters)
Also works with Backtracking.
- HardGo to lesson →
A tree of all the words lets you search them at once and drop dead paths.
- Time
- O(m·n·3^L)
- Space
- O(total letters)
Also works with Backtracking.
- HardGo to lesson →
Keep the small half and big half apart, with each top on hand.
- Time
- O(log n) per add
- Space
- O(n)
- MediumGo to lesson →
- MediumGo to lesson →
- MediumGo to lesson →
Each new land cell starts a flood that claims its whole group.
- Time
- O(m·n)
- Space
- O(m·n)
Also works with Advanced Graphs.
Watch it run - MediumGo to lesson →
A map from old node to new node stops you copying anything twice.
- Time
- O(V + E)
- Space
- O(V)
- MediumGo to lesson →
Work backwards: flood uphill from each sea and keep the overlap.
- Time
- O(m·n)
- Space
- O(m·n)
- MediumGo to lesson →
Tasks and rules form arrows. A loop makes it impossible.
- Time
- O(V + E)
- Space
- O(V + E)
Also works with Advanced Graphs.
Watch it run - MediumGo to lesson →
Take whatever waits for nothing, then free up what came after it. The queue fills in a valid order.
- Time
- O(V + E)
- Space
- O(V + E)
Also works with Advanced Graphs.
Watch it run - MediumGo to lesson →
Many starting points spread at the same speed, so start them all together and count the layers.
- Time
- O(m·n)
- Space
- O(m·n)
- HardGo to lesson →
Fewest moves, every move costs the same: that’s BFS. Group words under patterns like h*t to find neighbours fast.
- Time
- O(n·L²)
- Space
- O(n·L²)
- HardGo to lesson →
You count rides, not stops, so the buses are the nodes. Two buses link when they share a stop.
- Time
- O(s)
- Space
- O(s)
- MediumGo to lesson →
Flood from each unvisited node, or join groups as you read the links.
- Time
- O(V + E)
- Space
- O(V + E)
Also works with Graphs.
Watch it run - MediumGo to lesson →
Exactly n − 1 links, and one flood reaches everyone.
- Time
- O(V + E)
- Space
- O(V + E)
Also works with Graphs or Trees.
- HardGo to lesson →
Each neighbouring word pair gives one before-and-after rule, from its first different letter. Order the rules with a topological sort.
- Time
- O(c)
- Space
- O(1)
Also works with Graphs.
- EasyGo to lesson →
Ways to reach a stair: the ways to the two below it, added.
- Time
- O(n)
- Space
- O(1)
- MediumGo to lesson →
- MediumGo to lesson →
Solve the row twice: once without the first item, once without the last.
- Time
- O(n)
- Space
- O(1)
- MediumGo to lesson →
Expand from every centre: a long palindrome holds a shorter one.
- Time
- O(n²)
- Space
- O(1)
Also works with Two Pointers.
- MediumGo to lesson →
Every centre grows its own set of palindromes.
- Time
- O(n²)
- Space
- O(1)
Also works with Two Pointers.
- MediumGo to lesson →
Each position builds on the one-digit and two-digit reads before it.
- Time
- O(n)
- Space
- O(1)
- MediumGo to lesson →
- MediumGo to lesson →
A negative swaps best and worst, so track both.
- Time
- O(n)
- Space
- O(1)
- MediumGo to lesson →
A cut works if the part before it already breaks and the part after it is a word.
- Time
- O(n³)
- Space
- O(n)
Also works with Backtracking.
- MediumGo to lesson →
Each value extends the best chain ending at a smaller value. That is O(n²); keeping the smallest tail for each length, found by binary search, gets it to O(n log n).
- Time
- O(n log n)
- Space
- O(n)
Also works with Binary Search.
- MediumGo to lesson →
Ways into a cell: the ways from above plus the ways from the left.
- Time
- O(m·n)
- Space
- O(n)
Also works with Math & Geometry.
Watch it run - MediumGo to lesson →
Two strings, two indices: fill a table of answers for every pair of prefixes.
- Time
- O(m·n)
- Space
- O(m·n)
- MediumGo to lesson →
If the running total goes negative, drop it and restart.
- Time
- O(n)
- Space
- O(1)
Also works with 1-D DP or Sliding Window.
Watch it run - MediumGo to lesson →
- EasyGo to lesson →
Sort by start. Any overlap means a clash.
- Time
- O(n log n)
- Space
- O(1)
- MediumGo to lesson →
Sort by start. Each range either extends the last one or starts a new one.
- Time
- O(n log n)
- Space
- O(n)
- MediumGo to lesson →
Copy what’s before, merge what overlaps, copy the rest.
- Time
- O(n)
- Space
- O(n)
- MediumGo to lesson →
Keep whichever ends first. It leaves the most room.
- Time
- O(n log n)
- Space
- O(1)
Also works with Greedy.
- MediumGo to lesson →
Sort starts and ends apart and track how many run at once.
- Time
- O(n log n)
- Space
- O(n)
Also works with Heaps or Greedy.
- MediumGo to lesson →
- MediumGo to lesson →
Flip across the diagonal, then reverse each row.
- Time
- O(n²)
- Space
- O(1)
- MediumGo to lesson →
Use the first row and column as your notepad.
- Time
- O(m·n)
- Space
- O(1)
- EasyGo to lesson →
- EasyGo to lesson →
bits(i) = bits(i >> 1) + (i & 1).
- Time
- O(n)
- Space
- O(n)
Also works with 1-D DP.
- EasyGo to lesson →
Shift bits off one end and onto the other.
- Time
- O(1)
- Space
- O(1)
- EasyGo to lesson →
XOR everything, or compare against the expected sum.
- Time
- O(n)
- Space
- O(1)
Also works with Arrays & Hashing or Math & Geometry.
- MediumGo to lesson →
XOR gives the sum without carries, AND gives the carries. Repeat.
- Time
- O(1)
- Space
- O(1)