Interview essentials
For interview practice. Each section is one pattern, easiest first, so the later problems reuse what the earlier ones taught. Try each for about 25 minutes before you open a hint.
Arrays and hashing
Trade a little memory for one pass.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 1.Two SumFind the two positions whose numbers add up to a target. | ArraysHash maps | Easy | 100% | ||
| 2.Contains DuplicateCheck whether any number appears twice. | ArraysHash maps | Easy | – | ||
| 3.Valid AnagramCheck whether one word is a rearrangement of another. | StringsHash mapsSorting | Easy | – | ||
| 4.Top K FrequentReturn the k values that appear most often. | ArraysHash mapsSorting | Medium | – | ||
| 5.Product Except SelfFor each position, multiply every other number, without dividing. | Arrays | Medium | – |
Two pointers
Two positions that move toward each other or one after the other.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 6.Valid PalindromeCheck whether text reads the same both ways, ignoring case and punctuation. | StringsTwo pointers | Easy | – | ||
| 7.Three SumFind every distinct triple of numbers that adds up to zero. | ArraysTwo pointersSorting | Medium | – | ||
| 8.Container With Most WaterPick two walls that hold the most water between them. | ArraysTwo pointersGreedy | Medium | – | ||
| 9.Trapping Rain WaterWork out how much rain water a skyline of bars holds. | ArraysTwo pointersStacks | Hard | – |
Sliding window
Grow and shrink a range instead of starting again.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 10.Best Time to TradePick one day to buy and a later day to sell for the biggest profit. | ArraysGreedy | Easy | – | ||
| 11.Longest Substring Without RepeatsFind the longest stretch of text with no repeated character. | StringsSliding windowHash maps | Medium | – | ||
| 12.Minimum Window SubstringFind the shortest stretch of text that contains every letter of another string. | StringsSliding windowHash maps | Hard | – | ||
| 13.Sliding Window MaximumReport the largest number in every window of k as it slides along. | ArraysSliding window | Hard | – |
Stacks
Keep what is still open, and settle it when its match arrives.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 14.Valid ParenthesesCheck that every bracket is closed by the right kind, in the right order. | StringsStacks | Easy | – | ||
| 15.Days Until WarmerFor each day, count the days until a warmer one. | ArraysStacks | Medium | – | ||
| 16.Evaluate Reverse Polish NotationWork out an arithmetic expression written in postfix order. | StacksMath | Medium | 100% | ||
| 17.Largest Rectangle in a HistogramFind the biggest rectangle that fits under a bar chart. | ArraysStacks | Hard | – |
Binary search
Halve the range each step, even when the array is not plainly sorted.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 18.Binary SearchFind a number's position in a sorted array in log time. | ArraysBinary search | Easy | – | ||
| 19.Search in a Rotated ArrayBinary-search a sorted array that has been rotated. | ArraysBinary search | Medium | – | ||
| 20.Median of Two Sorted ArraysFind the median of two sorted arrays taken together. | ArraysBinary search | Hard | – |
Linked lists
Relink nodes in place, often with two pointers and a placeholder in front.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 21.Reverse a Linked ListTurn a linked list around so its last node comes first. | Linked lists | Easy | – | ||
| 22.Merge Two Sorted ListsJoin two sorted linked lists into one sorted list. | Linked listsTwo pointers | Easy | – | ||
| 23.Remove the Nth Node From the EndUnlink the node n places from the end of a linked list. | Linked listsTwo pointers | Medium | – | ||
| 24.Add Two Numbers in ListsAdd two numbers stored digit by digit in linked lists. | Linked listsMath | Medium | – | ||
| 25.Reverse in Groups of kReverse a linked list k nodes at a time, leaving a short last group as it is. | Linked lists | Hard | – |
Trees
Depth first with recursion, or level by level with a queue.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 26.Depth of a TreeCount the levels of a binary tree, from the root to its deepest leaf. | TreesRecursion | Easy | – | ||
| 27.Invert a TreeMirror a binary tree, swapping every node's left and right children. | TreesRecursion | Easy | – | ||
| 28.Tree Level by LevelList a binary tree's values one level at a time, left to right. | TreesGraphs | Medium | – | ||
| 29.Valid Search TreeCheck whether a binary tree keeps the search tree order everywhere. | TreesRecursion | Medium | – | ||
| 30.Best Path Sum in a TreeFind the path through a binary tree whose values add up to the most. | TreesRecursionDynamic programming | Hard | – |
Intervals and greedy choices
Sort first, or take the best move at each step.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 31.Merge IntervalsMerge every pair of overlapping intervals. | ArraysSorting | Medium | – | ||
| 32.Jump GameDecide whether you can jump from the first square to the last. | ArraysGreedyDynamic programming | Medium | – | ||
| 33.Maximum SubarrayFind the largest sum of a run of consecutive numbers. | ArraysDynamic programmingGreedy | Medium | – |
Graphs and backtracking
Explore every option, and undo a step when it leads nowhere.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 34.Number of IslandsCount the separate islands of land on a grid map. | GraphsMatrices | Medium | – | ||
| 35.Generate ParenthesesList every balanced string of n pairs of parentheses. | RecursionStrings | Medium | – | ||
| 36.Word LadderFind the shortest chain of one-letter changes from one word to another. | GraphsStringsHash maps | Hard | – | ||
| 37.N QueensCount the ways to place n queens on an n × n board with none attacking another. | Recursion | Hard | – |
Dynamic programming
Build the answer from the answers to smaller problems.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 38.Climbing StairsCount the ways to climb n stairs taking one or two at a time. | Dynamic programmingMathRecursion | Easy | – | ||
| 39.House RobberTake the most from a row of houses without taking two neighbours. | Dynamic programming | Medium | – | ||
| 40.Coin ChangeMake an amount with as few coins as possible. | Dynamic programming | Medium | – | ||
| 41.Longest Increasing SubsequenceFind the longest strictly rising sequence you can pick out of an array. | Dynamic programmingBinary search | Medium | – | ||
| 42.Unique PathsCount the paths across a grid moving only right or down. | Dynamic programmingMathMatrices | Medium | – | ||
| 43.Edit DistanceCount the fewest single-letter edits that turn one word into another. | StringsDynamic programming | Hard | – |