Coding Interview Solutions
A free, growing library of worked solutions to the problems that actually show up in coding interviews β each with a step-by-step walkthrough, clean code in Python, Java, and C++, and the time and space complexity spelled out. Theyβre organized by the algorithm patterns interviewers test most, so you can drill a weakness instead of grinding at random.
304 solutions across 15 patterns Β· no account or paywall required.
The highest-leverage β and most-feared β interview pattern: breaking a problem into overlapping subproblems and reusing their answers.
- Climbing StairsEasy
- Fibonacci NumberEasy
- Min Cost Climbing StairsEasy
- Pascal's TriangleEasy
- Pascal's Triangle IIEasy
- 2 Keys KeyboardMedium
- Best Time to Buy and Sell Stock with CooldownMedium
- Best Time to Buy and Sell Stock with Transaction FeeMedium
- Can I WinMedium
- Coin ChangeMedium
- Coin Change IIMedium
- Decode WaysMedium
- Edit DistanceMedium
- House RobberMedium
- House Robber IIMedium
- House Robber IIIMedium
- Longest Common SubsequenceMedium
- Longest Increasing SubsequenceMedium
- Longest Palindromic SubsequenceMedium
- Maximal SquareMedium
- Maximum Product SubarrayMedium
- Maximum SubarrayMedium
- Minimum Deletions to Make String BalancedMedium
- Minimum Path SumMedium
- Palindromic SubstringsMedium
- Partition Array for Maximum SumMedium
- Partition Equal Subset SumMedium
- Perfect SquaresMedium
- Target SumMedium
- TriangleMedium
- Unique Binary Search TreesMedium
- Unique PathsMedium
- Unique Paths IIMedium
- Word BreakMedium
- Best Time to Buy and Sell Stock IIIHard
- Burst BalloonsHard
- Interleaving StringHard
- Maximum Profit in Job SchedulingHard
- Regular Expression MatchingHard
- Wildcard MatchingHard
Recursion made visual. Traversals, depth, and path problems that teach you to think in terms of a node and its subtrees.
- Balanced Binary TreeEasy
- Binary Tree Inorder TraversalEasy
- Binary Tree Postorder TraversalEasy
- Binary Tree Preorder TraversalEasy
- Convert Sorted Array to Binary Search TreeEasy
- Diameter of Binary TreeEasy
- Invert Binary TreeEasy
- Leaf-Similar TreesEasy
- Lowest Common Ancestor of a Binary Search TreeEasy
- Maximum Depth of Binary TreeEasy
- Minimum Depth of Binary TreeEasy
- Minimum Distance Between BST NodesEasy
- Path SumEasy
- Same TreeEasy
- Search in a Binary Search TreeEasy
- Second Minimum Node In a Binary TreeEasy
- Subtree of Another TreeEasy
- Symmetric TreeEasy
- All Nodes Distance K in Binary TreeMedium
- Binary Tree Level Order TraversalMedium
- Binary Tree Right Side ViewMedium
- Binary Tree Zigzag Level Order TraversalMedium
- Construct Binary Tree from Inorder and Postorder TraversalMedium
- Construct Binary Tree from Preorder and Inorder TraversalMedium
- Delete Node in a BSTMedium
- Flatten Binary Tree to Linked ListMedium
- Kth Smallest Element in a BSTMedium
- Lowest Common Ancestor of a Binary TreeMedium
- Maximum Level Sum of a Binary TreeMedium
- Maximum Width of Binary TreeMedium
- Path Sum IIMedium
- Path Sum IIIMedium
- Recover Binary Search TreeMedium
- Step-By-Step Directions From a Binary Tree Node to AnotherMedium
- Sum of Nodes with Even-Valued GrandparentMedium
- Sum Root to Leaf NumbersMedium
- Binary Tree Maximum Path SumHard
- Sum of Distances in TreeHard
- Vertical Order Traversal of a Binary TreeHard
The warm-up round of almost every interview. In-place manipulation, prefix sums, and string parsing fundamentals.
- Find Numbers with Even Number of DigitsEasy
- Find Pivot IndexEasy
- Find the Index of the First Occurrence in a StringEasy
- First Unique Character in a StringEasy
- Greatest Common Divisor of StringsEasy
- Largest Odd Number in StringEasy
- Longest Common PrefixEasy
- Maximum Number of Words Found in SentencesEasy
- Move ZeroesEasy
- Plus OneEasy
- Running Sum of 1d ArrayEasy
- Valid Mountain ArrayEasy
- Contiguous ArrayMedium
- Find All Duplicates in an ArrayMedium
- Gas StationMedium
- Increasing Triplet SubsequenceMedium
- Insert IntervalMedium
- Integer to RomanMedium
- Largest NumberMedium
- Merge IntervalsMedium
- Multiply StringsMedium
- Next PermutationMedium
- Number of Good Ways to Split a StringMedium
- Reverse Words in a StringMedium
- Set Matrix ZeroesMedium
- Shortest Unsorted Continuous SubarrayMedium
- Subarray Sum Equals KMedium
- Sum of Absolute Differences in a Sorted ArrayMedium
- CandyHard
BFS, DFS, and the realization that most grid problems are graph problems in disguise.
- Find if Path Exists in GraphEasy
- Find the Town JudgeEasy
- Flood FillEasy
- Island PerimeterEasy
- Matrix Diagonal SumEasy
- Reshape the MatrixEasy
- 01 MatrixMedium
- All Paths From Source to TargetMedium
- Cheapest Flights Within K StopsMedium
- Clone GraphMedium
- Course ScheduleMedium
- Evaluate DivisionMedium
- Game of LifeMedium
- Is Graph Bipartite?Medium
- Max Area of IslandMedium
- MinesweeperMedium
- Minimum Height TreesMedium
- Number of IslandsMedium
- Number of ProvincesMedium
- Rotate ImageMedium
- Rotting OrangesMedium
- Snakes and LaddersMedium
- Spiral MatrixMedium
- Surrounded RegionsMedium
- Longest Increasing Path in a MatrixHard
- Redundant Connection IIHard
- Word LadderHard
Pointer gymnastics. Reversal, fast/slow pointers, and cycle detection without losing your place.
- Merge Two Sorted ListsEasy
- Middle of the Linked ListEasy
- Palindrome Linked ListEasy
- Remove Duplicates from Sorted ListEasy
- Remove Linked List ElementsEasy
- Reverse Linked ListEasy
- Add Two NumbersMedium
- Copy List with Random PointerMedium
- Delete the Middle Node of a Linked ListMedium
- Merge In Between Linked ListsMedium
- Odd Even Linked ListMedium
- Partition ListMedium
- Remove Duplicates from Sorted List IIMedium
- Remove Nodes From Linked ListMedium
- Remove Nth Node From End of ListMedium
- Reorder ListMedium
- Reverse Linked List IIMedium
- Rotate ListMedium
- Sort ListMedium
- Swap Nodes in PairsMedium
- Merge K Sorted ListsHard
- Reverse Nodes in K-GroupHard
The single most useful trade in interviews: spend memory to buy speed with a hash map.
- Contains DuplicateEasy
- Customers Who Never OrderEasy
- Find All Numbers Disappeared in an ArrayEasy
- How Many Numbers Are Smaller Than the Current NumberEasy
- Intersection of Two Arrays IIEasy
- Isomorphic StringsEasy
- Majority ElementEasy
- Rising TemperatureEasy
- Roman to IntegerEasy
- Two SumEasy
- Valid AnagramEasy
- Battleships in a BoardMedium
- Best Time to Buy and Sell Stock IIMedium
- Longest Consecutive SequenceMedium
- Majority Element IIMedium
- Product of Array Except SelfMedium
- Rotate ArrayMedium
- Sort Characters By FrequencyMedium
- Valid SudokuMedium
- First Missing PositiveHard
LIFO and FIFO as problem-solving tools β especially the monotonic stack that unlocks "next greater element" problems.
- Next Greater Element IEasy
- Time Needed to Buy TicketsEasy
- Valid ParenthesesEasy
- Asteroid CollisionMedium
- Daily TemperaturesMedium
- Decode StringMedium
- Evaluate Reverse Polish NotationMedium
- Minimum Add to Make Parentheses ValidMedium
- Next Greater Element IIMedium
- Next Greater Node in Linked ListMedium
- Remove All Occurrences of a SubstringMedium
- Remove Duplicate LettersMedium
- Remove K DigitsMedium
- Reveal Cards in Increasing OrderMedium
- Sum of Subarray MinimumsMedium
- Largest Rectangle in HistogramHard
- Longest Valid ParenthesesHard
- Maximal RectangleHard
- Number of AtomsHard
- Parsing a Boolean ExpressionHard
Not just for sorted arrays. The real skill is spotting a monotonic search space and halving it.
- Binary SearchEasy
- Peak Index in a Mountain ArrayEasy
- Search Insert PositionEasy
- Sqrt(x)Easy
- Valid Perfect SquareEasy
- Capacity To Ship Packages Within D DaysMedium
- Find First and Last Position of Element in Sorted ArrayMedium
- Find K Closest ElementsMedium
- Find Minimum in Rotated Sorted ArrayMedium
- Find Peak ElementMedium
- Koko Eating BananasMedium
- Kth Smallest Element in a Sorted MatrixMedium
- Magnetic Force Between Two BallsMedium
- Search a 2D MatrixMedium
- Search a 2D Matrix IIMedium
- Search in Rotated Sorted ArrayMedium
- Search in Rotated Sorted Array IIMedium
- Single Element in a Sorted ArrayMedium
- Median of Two Sorted ArraysHard
- Split Array Largest SumHard
Two indices, one pass, no extra memory. The elegant alternative to a nested loop.
- Is SubsequenceEasy
- Merge Sorted ArrayEasy
- Reverse StringEasy
- Squares of a Sorted ArrayEasy
- Valid PalindromeEasy
- Valid Palindrome IIEasy
- 3SumMedium
- 3Sum ClosestMedium
- Boats to Save PeopleMedium
- Container With Most WaterMedium
- Find the Duplicate NumberMedium
- Longest Palindromic SubstringMedium
- Sort ColorsMedium
- Two Sum II - Input Array Is SortedMedium
- Trapping Rain WaterHard
Systematic brute force: build a candidate, and undo your last choice the moment it can't work.
- Combination Sum IIMedium
- CombinationsMedium
- Generate ParenthesesMedium
- Letter Combinations of a Phone NumberMedium
- Maximum Length of a Concatenated String with Unique CharactersMedium
- Palindrome PartitioningMedium
- Path with Maximum GoldMedium
- PermutationsMedium
- SubsetsMedium
- Subsets IIMedium
- Word SearchMedium
- N-QueensHard
- N-Queens IIHard
- Sudoku SolverHard
- Word Search IIHard
Take the best choice available right now β and be ready to argue why that's optimal.
- Longest PalindromeEasy
- Maximum Number of Coins You Can GetEasy
- Maximum Product of Three NumbersEasy
- Maximum Units on a TruckEasy
- Dota2 SenateMedium
- Jump GameMedium
- Jump Game IIMedium
- Maximum Bags With Full Capacity of RocksMedium
- Minimum Deletions to Make Character Frequencies UniqueMedium
- Non-overlapping IntervalsMedium
- Partition LabelsMedium
- Reduce Array Size to The HalfMedium
- Valid Parenthesis StringMedium
A contiguous range that expands and contracts in a single pass β the fix for most substring problems.
- Best Time to Buy and Sell StockEasy
- Find All Anagrams in a StringMedium
- Longest Repeating Character ReplacementMedium
- Longest Subarray of 1s After Deleting One ElementMedium
- Longest Substring Without Repeating CharactersMedium
- Max Consecutive Ones IIIMedium
- Minimum Size Subarray SumMedium
- Permutation in StringMedium
- Count Subarrays With Fixed BoundsHard
- Minimum Window SubstringHard
- Sliding Window MaximumHard
When you repeatedly need the smallest or largest thing, a heap gives it to you in log time.
- Last Stone WeightEasy
- Furthest Building You Can ReachMedium
- K Closest Points to OriginMedium
- K-th Smallest Prime FractionMedium
- Kth Largest Element in an ArrayMedium
- Remove Stones to Minimize the TotalMedium
- Reorganize StringMedium
- Top K Frequent ElementsMedium
- Top K Frequent WordsMedium
- Total Cost to Hire K WorkersMedium
- Smallest Range Covering Elements from K ListsHard
Working directly in binary: XOR tricks and bit masks that feel like magic until you see why they work.
- Add BinaryEasy
- Counting BitsEasy
- Number of 1 BitsEasy
- Power of TwoEasy
- Reverse BitsEasy
- Single NumberEasy
- Bitwise AND of Numbers RangeMedium
- Count Triplets That Can Form Two Arrays of Equal XORMedium
- Find the Longest Substring Containing Vowels in Even CountsMedium
- Maximum Product of Word LengthsMedium
- Single Number IIMedium
Primes, GCD, modular arithmetic, and overflow-safe tricks β the problems that reward knowing the right formula.
Reading solutions isnβt practicing
SkillFlow picks your next problem from your weakest topic, times you like a real interview, and asks AI follow-up questions afterward. Free, no credit card.
Start practicing free β