Jump to section
Classic coding interview problems, each explained the way an interviewer wants to hear it: the brute force first, then the optimal approach, with tested solutions in Python and TypeScript, the time and space complexity, a script for talking it through out loud, and the follow-up questions that usually come next.
Problems by Pattern
Every solution is also on GitHub with its tests: mockif/coding-interview-solutions.
Most coding rounds draw on a small set of patterns. Learn the pattern behind each problem rather than memorising the code, and new problems start to look familiar.
Two Sum
Hash map. Find the pair that adds up to a target in one pass
Three Sum
Two pointers. All unique triplets that sum to zero, after sorting
Valid Parentheses
Stack. Check that every bracket closes in the right order
Binary Search
Binary search. Halve a sorted array until you find the target
Reverse a Linked List
Linked list. Iterative and recursive reversal with pointer diagrams
Merge Intervals
Sorting. Sort by start, then merge overlaps in one pass
Longest Palindromic Substring
Expand around centre. Grow from every centre to find the longest palindrome
LRU Cache
Design. O(1) get and put with a hash map and a linked list
Topological Sort (Kahn's Algorithm)
Graph. Order tasks by dependency with Kahn's BFS or DFS
Heapify and Max Heap
Heap. Build a max heap in O(n) with sift-down
Valid Anagram
Hash map. Count letters with a hash map instead of sorting
Group Anagrams
Hash map. Group words by a shared sorted-letter key
Maximum Subarray (Kadane's Algorithm)
Dynamic programming. Extend the run or restart it, in one pass
Climbing Stairs
Dynamic programming. A first dynamic programming problem, from recursion to O(1) space
Number of Islands
Graph. Count connected regions in a grid with BFS or DFS
Longest Substring Without Repeating Characters
Sliding window. The longest run with no repeats, using a sliding window
Product of Array Except Self
Prefix products. Prefix and suffix products, without division
Coin Change
Dynamic programming. Fewest coins for an amount, and why greedy fails
Kth Largest Element
Heap. A size-k min-heap, or quickselect in O(n) average
Course Schedule
Graph. Can every course be finished? Cycle detection with DFS
How to Use These Problems to Prepare
Solve it before you read the solution
Give yourself 20 to 25 minutes. Getting stuck and then reading the approach teaches far more than reading it first.
Say the brute force out loud
Interviewers want to hear that you can find a working answer before you optimise it. Name it, give its complexity, then improve it.
Write it in your interview language
Every page has Python and TypeScript. Use the one you will interview in, and practise typing it without an autocomplete.
Test it by hand
Walk through one normal case and one edge case before you say you are done. Empty input, one element and duplicates catch most bugs.
Rehearse it under interview conditions
Solving alone is studying. Explaining while someone listens and asks follow-ups is the skill the interview measures.
Ready to put this into practice?
Try these questions in a mock interview →Still applying for jobs? Let Auto Apply do it
Practise in a Mock Coding Round
Once you can solve these problems on your own, practise the part that is hard to rehearse alone: explaining your approach while you code. MockIF runs a mock coding interview with a voice AI interviewer in a real in-browser editor, in Python or TypeScript. It runs your code against tests, asks why you chose your approach, adds follow-ups, and scores your explanation at the end.
Each coding session costs 2 credits. It is free to start with 5 credits, then monthly or 3-monthly plans, or one-off credit packs (see pricing). For the language-specific details, see Python coding interview practice and the TypeScript coding interview guide.
Frequently Asked Questions
What are the most common coding interview problems?
How many coding problems should I practise before an interview?
Should I learn Python or TypeScript for coding interviews?
How do I explain my solution in a coding interview?
Stop Preparing in Your Head. Start Practicing Out Loud.
Drop your resume, add a job description, and get a mock interview like the real thing.
Start Free Mock Interview →Still applying for jobs? Let Auto Apply do it for you.