Coding Interviews: How to Answer, What to Practice, What to Watch For
Answer each problem in five steps: clarify, compare approaches, estimate, code, test. Includes a practice list grouped by pattern and the most common ways to lose points.
On this page · 22 sections
In a senior coding interview, the interviewer assumes you have practiced. They care less about how fast you type and more about three things: whether you work in an orderly way, whether you ask before assuming, and whether you reach a solution both of you accept within the time. This note covers how to answer one problem, then gives a practice list grouped by pattern, then lists the common ways to lose points.
The Short Version
- Don't start coding the moment you see the problem. Clarify, compare two or three approaches, confirm you can finish in time, then write code.
- If the first three steps go well, interviewers forgive small edge-case slips. Skip them, and you have to write bug-free code to compete.
- Practice by pattern, not by problem number. The list below is grouped by pattern, each with the one point you must be able to explain.
- After coding, walk through an example, state the complexity, and say what production code would still need. That step often separates "hire" from "strong hire".
What the interviewer is scoring
In a 45-minute coding round, working code is only one of the things being scored:
| Dimension | What the interviewer wants to confirm | Common way to lose points |
|---|---|---|
| Clarifying | Do you confirm inputs, outputs, and constraints before coding? | Starting class Solution straight from the prompt |
| Approach and trade-offs | Can you offer a few approaches and say why you picked one? | Only one idea, or a flood of approaches that don't work |
| Coding | Can you turn the idea into clear code quickly? | Changing the plan mid-way, confusing names |
| Verification | Do you test your own code and state its complexity? | Saying "done" and waiting for the interviewer to find bugs |
| Communication | Do you say what you're thinking when stuck? | Long silences |
Five steps for one problem
The example is "serialize and deserialize a binary tree".
Step 1: Clarify (about 5 minutes)
Don't write yet. Ask the questions that would change your approach:
- What type are the node values? Can they be null or repeated?
- Roughly how large is the input? Is speed or space more important?
- Is this API internal or public? Does the format need to stay stable?
- Will it be called from multiple threads?
The number of questions matters less than whether each answer would change your design. Then restate the problem in one sentence and ask the interviewer to confirm.
Step 2: Offer approaches and compare them (about 5–7 minutes)
Give two or three approaches with their time and space complexity and when each fits, then say which one you will use and why.
Interviewers sometimes add a constraint on purpose, such as "I care more about space". Take a moment, then give the new trade-off. Don't scramble to throw everything away.
Step 3: Estimate whether you can finish (about 1 minute)
Once you pick an approach, say something like "this will take me about 20 minutes to write". If it is too complex, agree on a simpler version with the interviewer and describe the rest as a follow-up. A finished, simple, correct version beats a half-written clever one.
Step 4: Code (about 20 minutes)
- Write the signature and main flow first, then fill in details.
- Briefly say what each part does as you write it.
- Use readable names and put the necessary edge checks at the entry point.
- If a detail isn't clear yet, leave a well-named helper and come back to it.
Step 5: Test and improve (about 5–8 minutes)
- Walk through a normal example by hand, then empty input, a single element, and duplicates.
- State the time and space complexity.
- When asked "what would you improve?", answer in order: unit tests and comments, a performance benchmark, and for production code, staged rollout, monitoring, and alerts.
Problem types and how to handle them
Different problem types test different things, so you prepare for them differently:
| Type | Examples | What it tests | How to handle it |
|---|---|---|---|
| Solid coding | K-th largest element, search in a rotated array | Turning an idea into correct code that covers every case | List edge cases before coding and check each one after |
| Data structure design | LRU Cache, O(1) insert, delete, and get-random | Combining structures to meet complexity requirements | Confirm each operation's required complexity and preconditions first |
| Problem modeling | Skyline problem, median of a data stream | Mapping an unfamiliar problem onto a known model (heap, balanced tree, sweep line) | Build this up in practice by asking "what is this problem really?" |
| Small system programs | Thread pool, web crawler, log merge | Concurrency, resource management, error handling | Know your language's concurrency tools and common patterns |
| Dynamic programming | Path counting, knapsack, sequence problems | Defining the state and the transition | Write the state and transition before the code |
Showing your reasoning on a hard problem: the skyline example
For a hard problem you have solved before, don't jump to the final answer. Show how you get there. Using the skyline problem (LeetCode 218):
- Find the core: the skyline is the maximum height at each x coordinate, so it is a sweep-line problem.
- Turn input into events: split each building into a start event and an end event, sorted by x.
- Name the operations you need: while sweeping you must insert a height, delete a height, and get the maximum.
- Compare data structures in order:
- A heap: insert O(log n), max O(1), but deleting an arbitrary element is O(n). Not good enough.
- A balanced BST (such as Java's
TreeMap): all three operations are O(log n). That works. - A heap with lazy deletion: a hash map records heights waiting to be removed, cleaned up when you read the max, so delete is O(log n) as well.
Present option one and its weakness, then option two, then option three and why it is better. Even if you only implement option two, the progression itself shows your judgment.
Practice list
This list comes from my own practice plan, grouped by pattern. Above each group is the one point you must explain in an interview. Practice falls into four levels:
- Must memorize (about 20–30 problems): practiced until you can write them without thinking.
- Core (about 100–150): Medium in under 10 minutes and Hard in under 15, correct on the first try.
- Important (about 200–300): no mistakes in the approach when you see the same or a similar problem.
- General: solved once or twice; you have an idea and don't panic.
These belong to the first two levels:
Binary search
State why the search range still contains the answer after every step.
| Problem | Difficulty | Target time (min) |
|---|---|---|
| Binary Search · LeetCode 704 | Easy | 10–15 |
| Search in Rotated Sorted Array · LeetCode 33 | Medium | 20–35 |
| Search in Rotated Sorted Array II · LeetCode 81 | Medium | 20–35 |
Two pointers · arrays
Say what each pointer means and when each one moves.
| Problem | Difficulty | Target time (min) |
|---|---|---|
| Two Sum · LeetCode 1 | Easy | 10–15 |
| Sort Colors · LeetCode 75 | Medium | 20–35 |
| Sort an Array · LeetCode 912 | Medium | 20–35 |
| Maximum Subarray · LeetCode 53 | Medium | 20–35 |
| Longest Substring Without Repeating Characters · LeetCode 3 | Medium | 20–35 |
Two pointers · linked lists
Draw the pointer moves; use a dummy head to avoid edge cases.
| Problem | Difficulty | Target time (min) |
|---|---|---|
| Merge Two Sorted Lists · LeetCode 21 | Easy | 10–15 |
| Add Two Numbers · LeetCode 2 | Medium | 20–35 |
Intervals and sweep line
Split intervals into start and end events, sort them, then sweep.
| Problem | Difficulty | Target time (min) |
|---|---|---|
| Number of Airplanes in the Sky · LintCode 391 | Medium | 20–35 |
| Minimum Number of Arrows to Burst Balloons · LeetCode 452 | Medium | 20–35 |
BFS and graphs
Define nodes and edges first, then decide on levels and a visited set.
| Problem | Difficulty | Target time (min) |
|---|---|---|
| Number of Islands · LeetCode 200 | Medium | 20–35 |
| Clone Graph · LeetCode 133 | Medium | 20–35 |
| Topological Sorting · LintCode 127 | Medium | 20–35 |
| Serialize and Deserialize Binary Tree · LeetCode 297 | Hard | 45–60 |
Binary trees and recursion
Define what the recursive call returns before writing the base case.
| Problem | Difficulty | Target time (min) |
|---|---|---|
| Binary Tree Inorder Traversal · LeetCode 94 | Easy | 10–15 |
| Binary Tree Preorder Traversal · LeetCode 144 | Easy | 10–15 |
| Binary Tree Postorder Traversal · LeetCode 145 | Easy | 10–15 |
| Construct Binary Tree from Preorder and Inorder Traversal · LeetCode 105 | Medium | 20–35 |
| Binary Search Tree Iterator · LeetCode 173 | Medium | 20–35 |
DFS · permutations and combinations
Say what each level chooses, how duplicates are skipped, and when you backtrack.
| Problem | Difficulty | Target time (min) |
|---|---|---|
| Subsets · LeetCode 78 | Medium | 20–35 |
| Subsets II · LeetCode 90 | Medium | 20–35 |
| Combinations · LeetCode 77 | Medium | 20–35 |
| Combination Sum · LeetCode 39 | Medium | 20–35 |
| Combination Sum II · LeetCode 40 | Medium | 20–35 |
| Permutations · LeetCode 46 | Medium | 20–35 |
| Permutations II · LeetCode 47 | Medium | 20–35 |
Data structure design
Confirm the complexity each operation needs, then choose the combination of structures.
| Problem | Difficulty | Target time (min) |
|---|---|---|
| Min Stack · LeetCode 155 | Medium | 20–35 |
| Design HashMap · LeetCode 706 | Easy | 10–15 |
| Implement Trie (Prefix Tree) · LeetCode 208 | Medium | 20–35 |
| LRU Cache · LeetCode 146 | Medium | 20–35 |
| LFU Cache · LeetCode 460 | Hard | 45–60 |
| Merge k Sorted Lists · LeetCode 23 | Hard | 45–60 |
| Range Sum Query - Mutable · LeetCode 307 | Medium | 20–35 |
| Longest Increasing Subsequence · LeetCode 300 | Medium | 20–35 |
Dynamic programming and greedy
Write the state and transition first, then initialization and iteration order.
| Problem | Difficulty | Target time (min) |
|---|---|---|
| Unique Paths · LeetCode 62 | Medium | 20–35 |
| Unique Paths II · LeetCode 63 | Medium | 20–35 |
| Backpack · LintCode 92 | Medium | 20–35 |
| Domino and Tromino Tiling · LeetCode 790 | Medium | 20–35 |
| Best Time to Buy and Sell Stock with Transaction Fee · LeetCode 714 | Medium | 20–35 |
What to watch for
- Ask before you write. Coding straight away suggests you need someone to direct your work.
- Don't overload on approaches. Two or three that work are enough; many that don't suggest unclear judgment.
- Talk when you are stuck. Say what you are considering and what is uncertain; interviewers often give hints.
- State complexity without being asked.
- Test your own code. Finding your own bug looks far better than the interviewer finding it.
- Know your standard library. For Java, the common methods of
Deque,PriorityQueue, andTreeMap; you can't look them up in the room. - Manage the clock. If you're not done by minute 30, explain the rest of the approach and focus on finishing the main flow.
References
- LeetCode: every problem in the list is there.
- Java Concurrency in Practice: a reference for thread-pool and producer-consumer style problems.
- The five-step method draws on an interviewer's-eye-view post by a former Microsoft engineer on the 1point3acres forum, reorganized here in my own words.
To see why companies run these interviews at all, read What Companies Hire For. Behavioral and system design rounds are covered in Behavioral Interviews and System Design.
Related notes
Behavioral Interviews: How to Answer, Common Questions, What to Watch For
Tell real experiences in STAR form from a reusable story bank prepared in advance. Includes common questions by category, the follow-ups interviewers ask, and a checklist for interview day.
What Companies Hire For: Working Back From the Hiring Bar
Work out what a company wants to confirm through interviews, then decide which skills and abilities to prepare.
Working on something similar?
I'm always happy to compare notes on distributed systems, delivery, and applied AI.
[email protected]