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

1

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.

2

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.

3

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.

4

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.

5

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?
Problems built on a handful of patterns come up again and again: hash maps (two sum), two pointers (three sum), stacks (valid parentheses), binary search, linked lists, intervals, graphs (topological sort), heaps and string problems like the longest palindromic substring.
How many coding problems should I practise before an interview?
Depth beats volume. Being able to solve and explain 40 to 60 problems across the main patterns usually prepares you better than rushing through hundreds without understanding why each solution works.
Should I learn Python or TypeScript for coding interviews?
Use the language you know best, unless the company asks for a specific one. Python is concise for algorithm problems; TypeScript suits front-end and full-stack roles. Every problem here has both.
How do I explain my solution in a coding interview?
Clarify the problem and constraints, state a brute force and its complexity, explain the better approach before you code, talk while you write, then test with an example and an edge case. Each problem page includes a short script.

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 →
No credit card required. 5 free credits to start.

Still applying for jobs? Let Auto Apply do it for you.

Try Auto Apply →