In this article
Start here: the learning path
- Coding interview question
- A coding interview question is a time-boxed problem, usually solvable in a few dozen lines, in which a candidate designs, codes and tests an algorithm while explaining the reasoning aloud to an interviewer.
- Algorithmic pattern
- An algorithmic pattern is a reusable solution shape, such as a sliding window or a topological sort, that fits a whole family of problems and can be recognised from the wording of the question.
- Brute-force baseline
- A brute-force baseline is the simplest correct solution, usually checking every possibility, which you state first so that every improvement has a cost to be measured against.
- Think-aloud
- Think-aloud is the habit of saying your reasoning, assumptions and checks out loud while you work, so the interviewer can grade your thinking even when the code is unfinished.
The path follows the order in which the ideas depend on each other; each family section below teaches the ideas for its step.
- The method. Learn the six-step routine below until it is automatic; it applies to every later page.
- Costs and hashing. Know the cost of the operations you use, then practise hash maps and prefix sums.
- Pointers, windows and sorting. Practise ranges and order: two pointers, sliding windows, binary search and intervals.
- Stacks, heaps and streams. Practise the structures that keep only what matters.
- Trees, graphs and grids. Practise recursion on trees and search on graphs.
- Recursion, dynamic programming and the rest. Practise choosing between exhaustive search, memoisation and greedy choice.
For the coding round inside machine-learning loops, read the machine learning (ML) coding guide; for the rounds around it, read how interview loops work and the system design guide.
- Longest substring without repeating characters: the sliding window solution
- Lowest common ancestor of a binary tree: how to find it
- Subarray sum equals k: the prefix-sum and hash-map solution
- Merge intervals: the sort-and-sweep solution, step by step
- What is topological sort? Kahn's algorithm and DFS explained
- What is a monotonic stack?
- K closest points to origin: heap, sort and quickselect
- How do you detect a cycle in a directed graph?
- Binary tree vertical order traversal
- Multiply Strings (LeetCode 43)
- Backtracking explained: the choose, check, recurse, undo pattern
- Math, geometry and bit-trick ladder: six coding-round techniques, step by step
- How is SQL tested in ML-engineer interviews?
- How do hash tables and arrays work?
- How do you write streaming computations in code?
- What is a shortest path ladder, and how do you solve one?
- Greedy ladder coding interview walkthrough
- Sorting and binary search ladder up to searching on the answer, step by step
- 3Sum explained: how to solve it with sorting and two pointers
- The grid BFS/DFS ladder: flood fill, distance, spread time and path counts
- Randomised algorithms ladder: shuffle, sample, reject
- How to implement a trie, from insert to ranked autocomplete
- Recursion ladder coding interview walkthrough, from base case to nested lists
- Linked list interview questions on reversal, cycles, merging and copying
- What is a dynamic programming ladder, and how do you climb it?
The six-step routine for any coding problem
The routine has six steps, and a fixed order means you never skip the clarifying question or the test when you are nervous. Clarify the question and the input limits. Work one concrete example by hand. State the brute-force baseline and its cost first, so that the improvement can be measured against it. Improve it by naming the pattern that removes the repeated work. Code it cleanly and test it on the example and on edge cases. State the time and space cost out loud.
The routine matters most under observation. A randomised trial with 48 computer-science students found that performance fell by more than half when an interviewer watched a candidate solve a problem on a whiteboard, compared with solving it privately, and that stress and mental load were significantly higher when watched (Behroozi, Shirolkar, Barik and Parnin, ESEC/FSE 2020). That study did not test any preparation method, so the routine here is this guide's suggestion, not a measured fix. Practising aloud in front of another person rehearses the condition the study measured: being watched while thinking aloud.
Step-by-step description
- Ask about inputs, limits and edge cases first.
- Work one concrete input by hand to see the rule.
- State the simplest correct solution and its cost.
- Name the pattern that removes the repeated work.
- Write clean code, then run the example and edge cases.
- Say time and space cost out loud.
- The routine has six steps: clarify, example, baseline, improve, code and test, state the cost.
- State the brute-force baseline and its cost first, so that the improvement can be measured against it.
Knowing it is half the job. Saying it is the other half.
Interview Clozo is an AI interview copilot for real interview rounds: it hears the question and puts a strong answer on your screen, and you say it in your own words. See the features or how it works.
Start Free Trial →What do the three costs of one problem look like?
The same problem can cost five billion steps or a hundred thousand, depending on the pattern. Take "find two numbers in a list that add to a target" on the worst case, a list in which no pair works. Checking every pair is quadratic: for 100,000 numbers it is 4,999,950,000 pair checks. A hash set that remembers numbers seen so far needs 100,000 steps. Sorting first, then moving two pointers inward, took 1,628,985 comparisons and steps in our measurement.1 The first count is the formula n(n−1)/2; the other two were measured, and the brute-force count was also measured and confirmed at 1,000 and 10,000 numbers.
| Numbers (n) | Check every pair | Hash set, one pass | Sort, then two pointers |
|---|---|---|---|
| 1,000 | 499,500 | 1,000 | 9,626 |
| 10,000 | 49,995,000 | 10,000 | 129,769 |
| 100,000 | 4,999,950,000 (formula) | 100,000 | 1,628,985 |
These costs rest on documented behaviour: lookups in a set or dict are constant time on average, a list membership test is linear, and a sort is n log n in the worst case (Python 3.15.1 documentation, time complexity of operations on built-in types). Those averages assume a good hash function; with many colliding keys they degrade to linear, which is the edge case an interviewer may probe.
The pattern map: six families
The pattern map groups the common problems into six families, and recognising the family from the wording is the first step. Each family below teaches the core idea and names the problems to practise.
Text description of the diagram
- Common coding problems group into six pattern families.
- The families run from hashing and pointers to graphs, dynamic programming and SQL.
Arrays, strings and hashing
A hash map trades memory for time by remembering what the loop has already seen, which turns many nested loops into one pass. Prefix sums extend the idea: store the running total of the elements up to each position, starting from an empty prefix of zero, and the number of subarrays summing to a target ending at the current position is the count of earlier prefixes that differ from the current one by that target. String arithmetic, such as multiplying two numbers given as text, is digit-by-digit work with a carry. Practise: two sum, subarray sum equals k, multiply strings, and small math, geometry and bit-trick problems.
Pointers, windows, sorting and search
Two pointers and sliding windows replace a nested loop with two indices that each move in one direction, usually toward each other or both left to right. A sliding window grows on the right and shrinks on the left while a condition is broken, so each element enters and leaves once. Binary search needs sorted data and halves the range each step; Python's bisect finds the position in logarithmic time, though inserting into a list stays linear (Python 3.15.1 documentation, bisect). Interval problems usually begin by sorting by start. Practise: longest substring without repeating characters, 3sum, palindrome checks, binary search on sorted data, and merge intervals.
Stacks, heaps and streams
A stack remembers unfinished work, and a monotonic stack keeps its contents in order so each element is pushed and popped once. A heap keeps the smallest or largest item at the top: Python's heapq builds one in linear time and removes the top in logarithmic time (Python 3.15.1 documentation, heapq). Keeping a heap of size k answers "k closest points" without sorting everything. Streaming problems keep a small running summary instead of all the data. Practise: next greater element with a monotonic stack, k closest points to the origin, running statistics over a stream, and linked list reversal.
Trees, graphs and grids
Many tree problems are solved by recursion: answer for each subtree, then combine. Graphs are searched breadth-first (BFS) for the fewest steps in an unweighted graph and depth-first (DFS) to explore everything. A topological sort orders tasks that depend on one another and also detects a cycle when some tasks can never be ordered. A grid is a graph whose neighbours are the cells around you. A trie stores words by shared prefix. Practise: lowest common ancestor, binary tree vertical order traversal, detecting a cycle in a directed graph, topological sort, shortest path, grid search with BFS and DFS, and building a trie.
Recursion, dynamic programming and the rest
Backtracking explores choices and undoes each one when it fails. Dynamic programming applies when a problem has overlapping subproblems, so storing each answer once avoids recomputing it. A greedy algorithm takes the best local choice and is correct only when you can argue why that choice is never regretted; dynamic programming also needs the best answer to be built from best answers to smaller pieces.
Randomised algorithms use chance to keep a solution simple, as in sampling from a stream. In an interview the decisive skill is choosing between these approaches: say which property of the problem points to which approach, such as overlapping subproblems for dynamic programming or a provable local choice for greedy, before you write any code. Practise: subsets and permutations with backtracking, a classic dynamic programming problem such as coin change, an interval-scheduling greedy problem, and reservoir sampling.
SQL in coding rounds
Some loops for machine-learning roles include a Structured Query Language (SQL) query problem beside the algorithm problem. It uses the same routine: clarify the columns, work an example by hand, state the simple version, then improve it. The usual themes are joining tables, grouping and counting, finding the top row in each group and comparing a row with the one before it. As with algorithm problems, say the shape of the result you expect before you write the query, and state the cost of a join on large tables. Practise: a top-row-per-group query and a compare-with-previous-row query.
Questions interviewers ask on coding
Interviewers return to the same follow-ups, so prepare for these: what is the time and space complexity of your solution? What is a simpler version you could code first? What input would break it? How would it change if the data did not fit in memory? What would you test? Each answer follows from the routine above, and practising variants of one problem, with a changed input or a changed limit, is how you rehearse a follow-up that forces a different data structure. The behavioural half of the same loop is covered in the behavioral interviews guide, and for the language-model questions asked in the same AI engineer loops, see the AI engineer interview questions list.
Follow-up questions
How to practice coding interview questions?
Practise by pattern, not by title: solve one problem from a family, then solve two variants of it before moving on. Do at least some of the sessions aloud and in front of another person, because being watched while thinking aloud is the condition the study measured, though it did not test practice itself (Behroozi et al., 2020).
How to approach coding interview questions?
Follow the six steps in order: clarify, example, baseline, improve, code and test, state the cost. Say each step as you do it so the interviewer can follow, and write the baseline down even if you expect to replace it.
How to answer coding interview questions?
Answer in the order of the routine and finish with the cost: "This is linear time and linear space; the brute force was quadratic." An answer that is correct but silent about complexity leaves the main follow-up unanswered.
Is Blind-75 enough?
A curated list of 75 problems such as Blind 75 cannot cover every variant, so treat it as a pattern set, not the exam. Keep practising twists: a changed input shape, a different output or a size limit that breaks the first idea.
How many variants per problem?
Two or three variants of each core problem is a reasonable target: one that changes the data structure, one that changes the constraint and one that combines two patterns. The goal is to recognise the pattern, not to remember the problem.
What do AI labs still ask?
No single list is reliable for every lab, and this guide does not claim one, so check the employer's own candidate guidance for its stages. The routine and the patterns above are what carries over. Machine learning roles can also include a coding round on ML primitives, which the ML coding guide covers, and design rounds, covered in the ML system design guide.
- Learn the six-step routine first; it works on every problem.
- A hash set turned five billion pair checks into one hundred thousand steps in our worst-case count.
- Recognise the family from the wording, then apply the pattern.
- Practise aloud and in front of someone to rehearse the watched condition; the study measured the effect, not this remedy.
- Practise variants of a pattern, not a list of titles.
Sources
- Time complexity of operations on built-in types (Python 3.15.1 documentation) — Python Software Foundation, 24 Oct 2026
- heapq: Heap queue algorithm (Python 3.15.1 documentation) — Python Software Foundation, 24 Oct 2026
- bisect: Array bisection algorithm (Python 3.15.1 documentation) — Python Software Foundation, 24 Oct 2026
- Does Stress Impact Technical Interview Performance? (Behroozi, Shirolkar, Barik, Parnin; ESEC/FSE 2020) — ACM, 12 Nov 2020