Skip to content

About

Coding interview problems sorted by the pattern that solves them.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

Coding interview patterns

166 coding interview problems sorted by the pattern that solves them. Learn the pattern first and most of the problems stop being separate problems. Each link has the statement, a step-through of the solution and answers in Python, C++, Java, JavaScript, Rust and Haskell.

Arrays and hashing

Problem Level
Pair with a given sum in an unsorted array Easy
Longest run of consecutive integers Medium
The k most frequent values Medium
Count subarrays with a given sum Medium
Product of every element except itself Medium
Smallest positive integer that is missing Hard

Two pointers

Problem Level
A palindrome, ignoring punctuation and case Easy
Merge two sorted arrays Easy
Move the zeros to the end Easy
Pair with a given sum in a sorted array Easy
Squares of a sorted array, in order Easy
Fewest boats under a weight limit Medium
Keep each value at most twice Medium
Sort three colours in one pass Medium
Two walls holding the most water Medium
All distinct triplets summing to zero Medium
The triple sum closest to a target Medium
Rain water trapped between walls Hard

Sliding window

Problem Level
Best total over k consecutive days Easy
Longest run of tasks within a time budget Easy
Shortest subarray with a sum at least the target Medium
Count runs whose product is below k Medium
Maximum of every window Hard
Most vowels in any k letters Easy
Longest run of distinct characters Medium
Count substrings holding a, b and c Medium
Shortest window holding every kind Medium
Longest run whose spread is at most a limit Medium
Every place an anagram begins Medium
Longest run with at most k distinct letters Medium
Count runs with exactly k distinct values Hard
Shortest window containing every letter Hard
Shortest run with sum at least K, negatives allowed Hard
Distinct values in every window Medium
Longest run of ones after k flips Medium
The best stretch to stay calm Medium
Longest run of one letter after k changes Medium
Longest run of ones after deleting one element Medium

Binary search

Problem Level
Find a value in a sorted array Easy
Integer square root without a library Easy
The top of a mountain array Easy
Where a value belongs in a sorted array Easy
Minimum of a rotated sorted array Medium
Search a matrix sorted in reading order Medium
Smallest ship that clears the backlog in D days Medium
Spread m items to maximise the closest pair Medium
The k-th smallest value in a sorted matrix Medium
The k-th smallest of two sorted arrays Hard
Complete rows of a coin staircase Easy
First and last position of a value Medium
The one value without a partner Medium
Find a value in a rotated sorted array Medium
Search a matrix sorted along rows and columns Medium
The largest equal share for k people Medium
The slowest rate that clears every queue in time Medium
The k-th smallest entry of a multiplication table Hard
Median of two sorted arrays Hard
Count the partners that clear a threshold Medium
Search a rotated array with repeated values Medium
The first day enough adjacent flowers are open Medium
Find a value in a mountain array Hard
Longest time n machines can run on shared batteries Hard
The k-th smallest distance between two values Hard
Research impact from sorted citation counts Medium
Earliest time a fleet completes its trips Medium
Least time for a workshop to repair every car Medium
Split an array to minimise the largest part Hard

Dynamic programming

Problem Level
The cheapest way up a staircase Easy
Can a subset reach the target? Medium
Count the palindromic substrings Medium
Longest common block Medium
Longest common subsequence Medium
Longest increasing subsequence Medium
Ordered ways to reach a total Medium
The cheapest path through a grid Medium
The largest-sum subarray Medium
The unbounded knapsack Medium
Ways to make an amount Medium
Fewest coins to make an amount Medium
Longest palindromic subsequence Medium
Longest palindromic substring Medium
The 0/1 knapsack Medium
The bounded knapsack Medium
The fewest coins from a limited supply Medium
The largest chain of divisors Medium
How many times one string appears in another Hard
The cheapest order to multiply matrices Hard
The fewest cuts into palindromes Hard
Burst balloons for the most coins Hard
One trade: the best profit Easy
Can you reach the last position? Medium
Paths around obstacles Medium
Split an integer for the largest product Medium
Split into two equal halves Medium
Dice rolls with a target sum Medium
Ways to pay with a limited supply Medium
How many longest increasing subsequences Medium
Is a string an interleaving of two others? Medium
Longest increasing subsequence in O(n log n) Medium
The fewest insertions to make a palindrome Hard
Edit distance between two strings Hard
The cheapest way to cut a stick Hard
Cut a rod for the most money Medium
Largest sum with no two chosen positions adjacent Medium
Subsets with a given sum Medium
Can the first player win? Medium
The largest product of a subarray Medium
The largest square of ones Medium
The longest rise-then-fall subsequence Medium
The smallest difference between two groups Medium
Wildcard pattern matching Hard
The largest sum on a circle Medium
The longest alternating subsequence Medium
The shortest common supersequence Medium
Ways to decode a string of digits Medium
The least starting health Hard

Stack

Problem Level
Balanced brackets Easy
Days until a warmer day Medium
Largest rectangle in a bar chart Hard

Heap (priority queue)

Problem Level
The k-th largest value Medium
Cheapest way to join ropes Medium
Most capital from at most k projects Hard

Backtracking

Problem Level
Sum of every subset’s XOR Easy
Signs that reach a target Medium
Counting n-queens placements Hard

Intervals

Problem Level
Total time covered by a set of bookings Easy
Fewest meeting rooms for a day of meetings Medium
Fewest bookings to cancel so none overlap Medium
Most profit from jobs that do not overlap Hard

Graphs

Problem Level
Count the islands in a grid Easy
Does an undirected graph contain a cycle? Easy
Can the graph be split in two? Medium
Distances between every pair of nodes Medium
The connection that closes a loop Medium
Shortest path through a grid Medium
Every route from source to target Medium
Shortest distances from one node Medium
Place as many applicants as possible Medium
Split people who dislike each other Medium
The largest island Medium
Distance to the nearest zero Medium
Moving cables to connect a network Medium
Routes with an exact total weight Medium
The city with the fewest neighbours within reach Medium
The path with the least effort Medium
Time for a signal to reach every node Medium
Maximum flow through a network Hard
Count the friend groups Medium
Does a directed graph contain a cycle? Medium
Minutes until every orange rots Medium
Routes that visit every node once Hard
Swim in rising water Hard
The cheapest node in each group Medium
Shortest distances with negative edges Medium
Connect every point at the least cost Medium
Shortest word transformation Hard
Cheapest fare with at most k stops Medium
Shortest path with walls you may break Hard
Adjacency matrix to adjacency list Easy
Repaint a region of an image Easy
Depth-first order of a graph Easy
Can every course be finished? Medium
The person everyone trusts Easy
Breadth-first order of a graph Easy
An order to take every course Medium
Capture the enclosed regions Medium

About

Coding interview problems sorted by the pattern that solves them.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors