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.

Challenges
43
Easy
12
Medium
21
Hard
10
Start the list

Arrays and hashing

Trade a little memory for one pass.

StatusChallengeLevelSave
1.Two SumFind the two positions whose numbers add up to a target.Easy
2.Contains DuplicateCheck whether any number appears twice.Easy
3.Valid AnagramCheck whether one word is a rearrangement of another.Easy
4.Top K FrequentReturn the k values that appear most often.Medium
5.Product Except SelfFor each position, multiply every other number, without dividing.Medium

Two pointers

Two positions that move toward each other or one after the other.

StatusChallengeLevelSave
6.Valid PalindromeCheck whether text reads the same both ways, ignoring case and punctuation.Easy
7.Three SumFind every distinct triple of numbers that adds up to zero.Medium
8.Container With Most WaterPick two walls that hold the most water between them.Medium
9.Trapping Rain WaterWork out how much rain water a skyline of bars holds.Hard

Sliding window

Grow and shrink a range instead of starting again.

StatusChallengeLevelSave
10.Best Time to TradePick one day to buy and a later day to sell for the biggest profit.Easy
11.Longest Substring Without RepeatsFind the longest stretch of text with no repeated character.Medium
12.Minimum Window SubstringFind the shortest stretch of text that contains every letter of another string.Hard
13.Sliding Window MaximumReport the largest number in every window of k as it slides along.Hard

Stacks

Keep what is still open, and settle it when its match arrives.

StatusChallengeLevelSave
14.Valid ParenthesesCheck that every bracket is closed by the right kind, in the right order.Easy
15.Days Until WarmerFor each day, count the days until a warmer one.Medium
16.Evaluate Reverse Polish NotationWork out an arithmetic expression written in postfix order.Medium
17.Largest Rectangle in a HistogramFind the biggest rectangle that fits under a bar chart.Hard

Binary search

Halve the range each step, even when the array is not plainly sorted.

StatusChallengeLevelSave
18.Binary SearchFind a number's position in a sorted array in log time.Easy
19.Search in a Rotated ArrayBinary-search a sorted array that has been rotated.Medium
20.Median of Two Sorted ArraysFind the median of two sorted arrays taken together.Hard

Linked lists

Relink nodes in place, often with two pointers and a placeholder in front.

StatusChallengeLevelSave
21.Reverse a Linked ListTurn a linked list around so its last node comes first.Easy
22.Merge Two Sorted ListsJoin two sorted linked lists into one sorted list.Easy
23.Remove the Nth Node From the EndUnlink the node n places from the end of a linked list.Medium
24.Add Two Numbers in ListsAdd two numbers stored digit by digit in linked lists.Medium
25.Reverse in Groups of kReverse a linked list k nodes at a time, leaving a short last group as it is.Hard

Trees

Depth first with recursion, or level by level with a queue.

StatusChallengeLevelSave
26.Depth of a TreeCount the levels of a binary tree, from the root to its deepest leaf.Easy
27.Invert a TreeMirror a binary tree, swapping every node's left and right children.Easy
28.Tree Level by LevelList a binary tree's values one level at a time, left to right.Medium
29.Valid Search TreeCheck whether a binary tree keeps the search tree order everywhere.Medium
30.Best Path Sum in a TreeFind the path through a binary tree whose values add up to the most.Hard

Intervals and greedy choices

Sort first, or take the best move at each step.

StatusChallengeLevelSave
31.Merge IntervalsMerge every pair of overlapping intervals.Medium
32.Jump GameDecide whether you can jump from the first square to the last.Medium
33.Maximum SubarrayFind the largest sum of a run of consecutive numbers.Medium

Graphs and backtracking

Explore every option, and undo a step when it leads nowhere.

StatusChallengeLevelSave
34.Number of IslandsCount the separate islands of land on a grid map.Medium
35.Generate ParenthesesList every balanced string of n pairs of parentheses.Medium
36.Word LadderFind the shortest chain of one-letter changes from one word to another.Hard
37.N QueensCount the ways to place n queens on an n × n board with none attacking another.Hard

Dynamic programming

Build the answer from the answers to smaller problems.

StatusChallengeLevelSave
38.Climbing StairsCount the ways to climb n stairs taking one or two at a time.Easy
39.House RobberTake the most from a row of houses without taking two neighbours.Medium
40.Coin ChangeMake an amount with as few coins as possible.Medium
41.Longest Increasing SubsequenceFind the longest strictly rising sequence you can pick out of an array.Medium
42.Unique PathsCount the paths across a grid moving only right or down.Medium
43.Edit DistanceCount the fewest single-letter edits that turn one word into another.Hard