Coding patternsBlind 75
Blind 75, solved step by step
The 75 classic coding interview problems, each solved from the simple way to the fast way, with a step-through, code in five languages and the Big O worked out from the code.
Arrays and hashing 8
- 1Contains DuplicateA set remembers what you have seen, so a repeat shows up in one pass.Easy
- 2Valid AnagramTwo words are anagrams when every letter appears the same number of times.Easy
- 3Two SumFor each number, ask a map whether its partner has already gone past.Easy
- 4Group AnagramsGive every anagram the same key, then group the words by that key.Medium
- 5Top K Frequent ElementsCount each number, then pick the k biggest counts without a full sort.Medium
- 6Encode and Decode StringsWrite each string's length before it, so any character can appear inside.Medium
- 7Product of Array Except SelfEverything except i is everything left of i times everything right of i.Medium
- 8Longest Consecutive SequenceOnly start counting from a number that begins a run.Medium
Two pointers 3
Sliding window 4
- 12Best Time to Buy and Sell StockKeep the cheapest price so far and check each day's profit against it.Easy
- 13Longest Substring Without Repeating CharactersGrow the window, and shrink it from the left the moment a letter repeats.Medium
- 14Longest Repeating Character ReplacementA window is fine while its length minus its most common letter is at most k.Medium
- 15Minimum Window SubstringGrow until the window covers every letter, then shrink while it still does.Hard
Stack 1
Binary search 2
Linked list 6
- 19Reverse Linked ListTurn each arrow around as you walk, keeping hold of the next node.Easy
- 20Merge Two Sorted ListsAlways take the smaller head, and a dummy node removes the special cases.Easy
- 21Linked List CycleA fast and a slow pointer meet if and only if there is a loop.Easy
- 22Reorder ListFind the middle, reverse the second half, then weave the two halves.Medium
- 23Remove Nth Node From End of ListStart one pointer n steps ahead, so the other stops right before the target.Medium
- 24Merge K Sorted ListsA min-heap of the k heads always knows which node comes next.Hard
Trees 11
- 25Invert Binary TreeSwap the children of every node. Recursion visits each one once.Easy
- 26Maximum Depth of Binary TreeA tree is one level deeper than its deeper subtree.Easy
- 27Same TreeTwo trees match when their roots match and both pairs of subtrees match.Easy
- 28Subtree of Another TreeAt every node of the big tree, ask Same Tree.Easy
- 29Lowest Common Ancestor of a BSTWalk down from the root until the two values split to different sides.Medium
- 30Binary Tree Level Order TraversalA queue visits the tree one level at a time.Medium
- 31Validate Binary Search TreePass down the range each node must fall in, not just its parent's value.Medium
- 32Kth Smallest Element in a BSTAn in-order walk of a BST visits values from smallest to largest.Medium
- 33Construct Binary Tree from Preorder and Inorder TraversalPreorder names the root; inorder tells you what goes left and right.Medium
- 34Binary Tree Maximum Path SumEach node hands its parent its best one-sided path and checks the path that bends at it.Hard
- 35Serialize and Deserialize Binary TreeWrite the tree in preorder with markers for empty spots, then read it back the same way.Hard
Tries 3
Heap 1
Backtracking 2
Graphs 7
- 42Number of IslandsEach time you find new land, flood all of it, and count one island.Medium
- 43Clone GraphWalk the graph and keep a map from each old node to its copy.Medium
- 44Pacific Atlantic Water FlowFlow uphill from each ocean instead, and keep the cells both oceans reach.Medium
- 45Course ScheduleYou can finish every course when the prerequisites have no cycle.Medium
- 46Graph Valid TreeA tree has exactly n minus 1 edges and every node is connected.Medium
- 47Number of Connected Components in an Undirected GraphUnion-find merges groups as edges arrive, and counts the groups left.Medium
- 48Alien DictionaryNeighboring words give letter orders; a topological sort puts them in line.Hard
1-D dynamic programming 10
- 49Climbing StairsThe ways to reach a step are the ways to reach the two steps below it.Easy
- 50House RobberAt each house, either rob it and skip the last one, or skip it.Medium
- 51House Robber IIThe first and last house touch, so solve House Robber twice without one of them.Medium
- 52Longest Palindromic SubstringEvery palindrome grows out from a center. Try each center.Medium
- 53Palindromic SubstringsExpand from every center and count each palindrome on the way out.Medium
- 54Decode WaysThe ways to decode up to i come from the last one digit or the last two.Medium
- 55Coin ChangeThe fewest coins for an amount is one more than the best amount you can reach it from.Medium
- 56Maximum Product SubarrayTrack the largest and the smallest product, because a negative can swap them.Medium
- 57Word BreakA prefix can be split when a shorter split prefix plus one dictionary word makes it.Medium
- 58Longest Increasing SubsequenceFor each number, the longest run ending there builds on smaller numbers before it.Medium
2-D dynamic programming 2
Greedy 2
Intervals 5
- 63Insert IntervalCopy what ends before, merge what overlaps, copy what starts after.Medium
- 64Merge IntervalsSort by start, then each interval either extends the last one or starts a new one.Medium
- 65Non-overlapping IntervalsKeep the interval that ends first; it leaves the most room for the rest.Medium
- 66Meeting RoomsSort by start; any meeting that starts before the last one ends is a clash.Easy
- 67Meeting Rooms IIA min-heap of end times tells you when a room frees up.Medium
Math and geometry 3
Bit manipulation 5
- 71Number of 1 Bitsn and (n minus 1) clears the lowest 1 bit, so count how often you can do it.Easy
- 72Counting BitsA number has the same bits as half of it, plus its last bit.Easy
- 73Reverse BitsTake bits off the right end of n and push them onto the right end of the answer.Easy
- 74Missing NumberXOR every index and every value; pairs cancel and the missing one is left.Easy
- 75Sum of Two IntegersXOR adds without carries, AND finds the carries; repeat until no carry is left.Medium
No problem matches.
More in Coding patterns
The designbeyondcode digest, every Saturday
New deep dives, interview tips and site news in one short email. Free. Leave with one click.
We never sell or share your email. We only use it to send this newsletter.