Interview problem set 🐍
The problems that recur across every "most asked" list, grouped by the pattern they teach rather than by number. Each one gives you the tell that identifies it, the reasoning in the order you would actually derive it, the complexity, a working Python solution, and the mistake that most often costs the offer.
- problems
- 81
- patterns
- 14
- easy
- 19
- medium
- 51
- hard
- 11
Arrays & hashing
Trade memory for time. If a nested loop is re-answering the same lookup, a dict or set collapses it to one pass.
- 1Two SumFind a pair summing to a target, and the array is unsorted with indices required.Easy
- 36Valid SudokuConstraint checking across three overlapping groupings of the same cells.Medium
- 49Group AnagramsGroup items that share a property — so you need a canonical key for that property.Medium
- 53Maximum SubarrayBest contiguous run under a sum, with negatives present.Medium
- 128Longest Consecutive SequenceConsecutive run in an unsorted array, with sorting explicitly ruled out by an O(n) requirement.Medium
- 152Maximum Product SubarrayLike maximum subarray, but multiplication means a negative can become the best.Medium
- 217Contains DuplicateAsks only whether any value repeats — no positions, no counts.Easy
- 238Product of Array Except SelfEvery position needs an aggregate of everything else, and division is forbidden.Medium
- 242Valid AnagramTwo strings, same characters, order irrelevant.Easy
- 271Encode and Decode StringsSerialise a list of arbitrary strings so it can be split back unambiguously.Medium
- 347Top K Frequent Elements'k most frequent' — counting plus a partial ordering, not a full sort.Medium
Two pointers
Sorted or monotone input, and you need a pair, a partition, or an in-place rearrangement.
- 11Container With Most WaterMaximise an area defined by a pair of positions and the smaller of two heights.Medium
- 153SumTriples summing to zero, with duplicates in the input and no duplicate triples in the output.Medium
- 42Trapping Rain WaterWater held above each position, bounded by the tallest bar on each side.Hard
- 125Valid PalindromeCompare a sequence against its reverse, in place, ignoring some characters.Easy
- 167Two Sum II — Input Array Is SortedSorted input and a target pair, with O(1) space demanded.Medium
Sliding window
A contiguous range with a constraint — longest, shortest, or at most k of something.
- 3Longest Substring Without Repeating CharactersLongest contiguous stretch subject to a no-duplicates constraint.Medium
- 76Minimum Window SubstringShortest window containing every character of a target, counts included.Hard
- 121Best Time to Buy and Sell StockBest single buy-then-sell pair, where the buy must precede the sell.Easy
- 239Sliding Window MaximumMaximum of every fixed-size window, with a linear-time requirement.Hard
- 424Longest Repeating Character ReplacementLongest window that becomes uniform after at most k changes.Medium
- 567Permutation in StringDoes a fixed-length anagram of one string appear inside another?Medium
Stack & monotonic stack
Matching pairs, or 'next greater / previous smaller' where a nested scan looks unavoidable.
- 20Valid ParenthesesMatching nested pairs, where the most recent opener must close first.Easy
- 84Largest Rectangle in HistogramMaximal area bounded by the shortest bar in a contiguous range.Hard
- 155Min StackStack operations plus getMin, all required to be O(1).Medium
- 739Daily Temperatures'How many days until a warmer one' — a next-greater-element question.Medium
Binary search
Sorted data, or a monotone feasibility predicate you can search over instead of the array.
- 4Median of Two Sorted ArraysTwo sorted arrays with an explicit O(log(min(n, m))) requirement.Hard
- 33Search in Rotated Sorted ArraySearch a rotated sorted array in logarithmic time.Medium
- 153Find Minimum in Rotated Sorted ArraySorted array that has been rotated, and the requirement says O(log n).Medium
- 875Koko Eating Bananas'Minimum rate such that the job finishes in time' — a monotone feasibility question.Medium
Linked lists
Pointer surgery. Dummy heads remove edge cases; fast and slow pointers find cycles and midpoints.
- 19Remove Nth Node From End of ListPositional removal counted from the tail, in one pass.Medium
- 21Merge Two Sorted ListsTwo sorted sequences to interleave into one sorted result.Easy
- 23Merge k Sorted Listsk sorted sequences to merge, with total length n.Hard
- 141Linked List CycleDetect a loop using constant extra space.Easy
- 143Reorder ListInterleave the list with its own reverse, in place.Medium
- 146LRU CacheGet and put both O(1), with eviction ordered by recency.Medium
- 206Reverse Linked ListReverse pointer direction in place, with O(1) extra space.Easy
Trees & BST
Recursion that returns something useful from each subtree, or an in-order walk that must be sorted.
- 98Validate Binary Search TreeA BST property that is global, not just parent-to-child.Medium
- 100Same TreeStructural equality of two trees, compared position by position.Easy
- 102Binary Tree Level Order TraversalOutput grouped by depth, which recursion does not give you for free.Medium
- 104Maximum Depth of Binary TreeA value that each subtree can compute and hand upward.Easy
- 105Construct Binary Tree from Preorder and Inorder TraversalRebuild a tree from two traversals, which together determine it uniquely.Medium
- 110Balanced Binary TreeA property that fails fast — once unbalanced, the answer is fixed.Easy
- 124Binary Tree Maximum Path SumA path that may bend at a node, so the value returned upward differs from the value recorded.Hard
- 226Invert Binary TreeA structural transformation that applies identically to every subtree.Easy
- 230Kth Smallest Element in a BSTOrder statistics on a BST, where in-order is already sorted.Medium
- 235Lowest Common Ancestor of a BSTTwo nodes in a BST, where ordering tells you which way to walk.Medium
- 297Serialize and Deserialize Binary TreeRound-trip a tree through a string, so the encoding must be unambiguous.Hard
- 543Diameter of Binary TreeA global best that is computed at every node but returned differently upward.Easy
Tries
Prefix queries over a set of strings, where lookup should cost the word length rather than the dictionary size.
- 208Implement Trie (Prefix Tree)Prefix queries over a dictionary, where lookup should cost word length not dictionary size.Medium
- 211Design Add and Search Words Data StructureTrie lookup where '.' matches any single character.Medium
- 212Word Search IIFind many words in a grid — searching each one separately is far too slow.Hard
Heaps & top-k
You need the k best, a running median, or repeated access to the current minimum.
Backtracking
Enumerate every valid configuration — subsets, permutations, placements — pruning as early as possible.
- 39Combination SumAll combinations reaching a target, with unlimited reuse of each candidate.Medium
- 46PermutationsEvery ordering, so position matters and each element is used exactly once.Medium
- 78SubsetsEnumerate every combination — the canonical choose/explore/un-choose template.Medium
- 79Word SearchA path through a grid matching a sequence, where cells cannot be reused within a path.Medium
Graphs
Grids and dependencies. BFS for fewest steps, DFS for structure, topological sort for ordering.
- 127Word LadderFewest transformations between two words — unit edge weights, so BFS is optimal.Hard
- 133Clone GraphDeep-copy a structure containing cycles, so naive recursion would loop forever.Medium
- 200Number of IslandsCount connected regions in a grid — a grid is just an implicit graph.Medium
- 207Course SchedulePrerequisites — a directed graph where the question is really 'is it acyclic?'Medium
- 323Number of Connected Components in an Undirected GraphConnectivity counting over a stream of edges — the classic union-find setup.Medium
- 417Pacific Atlantic Water FlowCells that can reach two destinations — easier solved backwards from each destination.Medium
- 994Rotting OrangesSimultaneous spread from several sources, measured in steps — multi-source BFS.Medium
Dynamic programming
Overlapping subproblems with optimal substructure. Name the state before you write any code.
- 62Unique PathsCount routes through a grid with restricted moves — a 2-D counting recurrence.Medium
- 70Climbing StairsCount the ways to reach a target using a fixed set of steps.Easy
- 72Edit DistanceMinimum operations to transform one string into another.Medium
- 139Word BreakCan a string be split into dictionary words — a decision over every split point.Medium
- 198House RobberMaximise a sum with an adjacency restriction — a decision at each position.Medium
- 300Longest Increasing SubsequenceLongest ordered subsequence — the O(n log n) version is the expected answer.Medium
- 322Coin ChangeFewest items summing to a target, with unlimited reuse of each denomination.Medium
- 416Partition Equal Subset SumSplit into two equal halves — a subset-sum question in disguise.Medium
- 1143Longest Common SubsequenceTwo sequences compared for shared order — the archetypal 2-D DP.Medium
Greedy & intervals
A local choice that is provably safe, or intervals that become tractable once sorted.
Bit manipulation & math
XOR cancellation, low-bit tricks, and problems where the arithmetic is the algorithm.
- 136Single NumberEverything appears twice except one, with O(1) space demanded.Easy
- 191Number of 1 BitsCount set bits, ideally in time proportional to the number of ones.Easy
- 268Missing NumberOne value absent from a complete range — arithmetic or XOR both work.Easy
- 338Counting BitsSet-bit counts for a whole range — each answer reuses a smaller one.Easy