Study 30 coded interview examples with approach, target complexity, and prep strategy for arrays, trees, DP, SQL, and more.
Coded Interview Examples: 30 Most Asked (2026)
A coded interview example is the fastest way to understand what interviewers actually expect — before you're sitting in the hot seat trying to figure it out live. This page covers 30 real problems, grouped by the pattern they test, with the approach and complexity target for each. No filler, no motivational speeches. Just the problems, the reasoning, and a concrete prep plan.
What is a coded interview?
A coded interview is a 30–45 minute session where you solve one or two algorithmic problems in a shared editor, whiteboard, or online coding environment. The interviewer watches you think, not just code. They're evaluating your communication, your reasoning about tradeoffs, and whether you handle edge cases — not only whether the final output compiles.
The most common languages candidates use are Python, Java, C++, and JavaScript. Pick the one you're most fluent in. Nobody gets bonus points for choosing a harder language.
The best way to understand the format is to work through real coded interview examples. That's what the rest of this page is for.
How interviewers evaluate you
Before getting into the problems, it helps to know what the person across the screen is actually looking for. Every example below is structured around these four dimensions.
- Communication. Talk through your approach before you write a single line. The Jane Street engineering team says it explicitly: communication is their first piece of advice to candidates. Silence is the worst signal you can send.
- Correctness. Clear, working code — not a rough sketch with hand-waved edge cases. Clean variable names and readable structure matter more than clever one-liners.
- Complexity reasoning. Know why O(n) beats O(n²) and be able to explain it out loud. One experienced interviewer who used a single question roughly 500 times found that candidates who articulated the complexity tradeoff between their naive and optimized solutions aligned with final-loop hire decisions about 95% of the time.
- Clarifying questions. Surface ambiguity before you start coding. "Are there duplicates in the input?" or "What's the expected scale?" aren't stalling — they're exactly what the interviewer wants to hear.
Process matters as much as the answer.
30 coded interview examples by category
The 30 examples below are grouped by the data structure or algorithm pattern they test. For each, you'll see the problem type, a sample prompt, the recommended approach, and the complexity target.
Arrays and strings
1. Two Sum
- Prompt: Given an array of integers and a target, return the indices of two numbers that add up to the target.
- Approach: Start with the brute-force nested loop (O(n²)). Then optimize with a hash map — for each element, check if its complement exists in the map. One pass.
- Target complexity: O(n) time, O(n) space.
2. Valid Anagram
- Prompt: Given two strings, determine if one is an anagram of the other.
- Approach: The simplest first pass is to sort both strings and compare. Then improve with a character-count hash map — increment for the first string, decrement for the second, check that all counts are zero. This two-step progression (sort first, then hash map) is exactly how it plays out in a mock interview recording of LeetCode 242.
- Target complexity: O(n) time with the hash-map approach.
3. Sliding Window Maximum
- Prompt: Given an array and a window size k, return the maximum value in each window as it slides across the array.
- Approach: Naive: check every window (O(n·k)). Optimized: use a deque to maintain a decreasing order of useful elements.
- Target complexity: O(n) time.
4. Longest Substring Without Repeating Characters
- Prompt: Find the length of the longest substring with all unique characters.
- Approach: Sliding window with a set tracking characters in the current window. Move the right pointer to expand, left pointer to shrink when a duplicate appears.
- Target complexity: O(n) time.
5. Product of Array Except Self
- Prompt: Return an array where each element is the product of all other elements, without using division.
- Approach: Two-pass: build a prefix product array left-to-right, then multiply in the suffix product right-to-left.
- Target complexity: O(n) time, O(1) extra space (if the output array doesn't count).
6. String Compression
- Prompt: Compress a string by replacing consecutive repeated characters with the character followed by the count. Return the original string if the compressed version isn't shorter.
- Approach: Single pass with a pointer tracking the current run. Build the result as you go.
- Target complexity: O(n) time.
Hash maps and sets
7. Group Anagrams
- Prompt: Given a list of strings, group the anagrams together.
- Approach: Use sorted strings as hash-map keys. All anagrams produce the same sorted key.
- Target complexity: O(n · k log k) where k is the max string length.
8. Top K Frequent Elements
- Prompt: Given an array, return the k most frequent elements.
- Approach: Count frequencies with a hash map, then use a min-heap of size k or bucket sort.
- Target complexity: O(n) with bucket sort, O(n log k) with a heap.
9. Loyal Customer Log
- Prompt: Given a log of customer page visits across multiple days, find customers who visited at least a threshold number of unique pages on each day.
- Approach: This is a real interview question used about 500 times by one interviewer. The key is clarifying questions first — do duplicates count? What defines "unique"? Then model it as `Map<CustomerId, Set<PageId>>` per day. Naive nested iteration is O(n²); the hash-map approach brings it to O(n).
- Target complexity: O(n) time, O(n) space.
10. Subarray Sum Equals K
- Prompt: Count the number of contiguous subarrays that sum to a given target k.
- Approach: Prefix sums stored in a hash map. For each prefix sum, check if (current sum − k) exists in the map.
- Target complexity: O(n) time.
Linked lists
11. Reverse a Linked List
- Prompt: Reverse a singly linked list in place.
- Approach: Iterative: maintain three pointers (prev, current, next). Swap links one node at a time.
- Target complexity: O(n) time, O(1) space.
12. Detect a Cycle
- Prompt: Determine if a linked list contains a cycle.
- Approach: Floyd's slow/fast pointer. If they meet, there's a cycle.
- Target complexity: O(n) time, O(1) space.
13. Merge Two Sorted Lists
- Prompt: Merge two sorted linked lists into one sorted list.
- Approach: Two-pointer merge. Compare heads, advance the smaller one.
- Target complexity: O(n + m) time.
14. Find the Middle Node
- Prompt: Return the middle node of a linked list.
- Approach: Slow/fast pointer — when fast reaches the end, slow is at the middle.
- Target complexity: O(n) time, O(1) space.
For all linked-list problems: draw the pointer state on paper (or describe it out loud) before you start writing code. Interviewers notice when you reason visually.
Trees and graphs
15. Binary Tree Level Order Traversal (BFS)
- Prompt: Return the values of a binary tree level by level.
- Approach: BFS with a queue. Process one level per iteration.
- Target complexity: O(n) time.
16. Validate BST
- Prompt: Determine if a binary tree is a valid binary search tree.
- Approach: In-order traversal — values should be strictly increasing. Or pass min/max bounds recursively.
- Target complexity: O(n) time.
17. Number of Islands (DFS)
- Prompt: Given a 2D grid of '1's (land) and '0's (water), count the number of islands.
- Approach: DFS from each unvisited '1', marking visited cells. Each DFS call discovers one island.
- Target complexity: O(rows × cols) time.
18. Clone Graph
- Prompt: Deep-copy a connected undirected graph.
- Approach: BFS or DFS with a hash map from original node to cloned node.
- Target complexity: O(V + E) time.
19. Lowest Common Ancestor
- Prompt: Find the lowest common ancestor of two nodes in a binary tree.
- Approach: Recursive: if the current node is either target, return it. Recurse left and right. If both sides return non-null, the current node is the LCA.
- Target complexity: O(n) time.
20. Course Schedule (Topological Sort)
- Prompt: Given a list of course prerequisites, determine if all courses can be completed.
- Approach: Model as a directed graph. Detect cycles using topological sort (Kahn's algorithm with in-degree tracking, or DFS with a visited state).
- Target complexity: O(V + E) time.
A note on BFS vs. DFS: use BFS when the problem asks for level-by-level or shortest-path results. Use DFS when you need to explore full paths or depth-first connectivity. The Jane Street mock interview shows a candidate modeling a unit-conversion problem as a graph with bi-directional edges — a good example of reframing a problem into a graph traversal.
Dynamic programming
21. Climbing Stairs
- Prompt: You can climb 1 or 2 steps at a time. How many distinct ways can you reach the top of n stairs?
- Approach: State the recurrence relation out loud first: dp[i] = dp[i-1] + dp[i-2]. Then implement bottom-up.
- Target complexity: O(n) time, O(1) space with two variables.
22. Coin Change
- Prompt: Given coin denominations and a target amount, find the fewest coins needed.
- Approach: Bottom-up DP. dp[amount] = min(dp[amount], dp[amount - coin] + 1) for each coin.
- Target complexity: O(amount × coins) time.
23. Longest Common Subsequence
- Prompt: Find the length of the longest subsequence common to two strings.
- Approach: 2D DP table. If characters match, dp[i][j] = dp[i-1][j-1] + 1. Otherwise, take the max of the cell above or to the left.
- Target complexity: O(m × n) time.
24. House Robber
- Prompt: Given an array of house values, find the maximum amount you can rob without robbing two adjacent houses.
- Approach: dp[i] = max(dp[i-1], dp[i-2] + nums[i]). State the recurrence before coding.
- Target complexity: O(n) time, O(1) space.
For every DP problem: state the recurrence relation aloud before writing code. That's the signal interviewers are listening for.
Sorting and searching
25. Binary Search
- Prompt: Find the index of a target value in a sorted array, or return -1.
- Approach: Classic binary search. Watch your boundary conditions — off-by-one errors are the most common mistake.
- Target complexity: O(log n) time.
26. Merge Sort Implementation
- Prompt: Implement merge sort from scratch.
- Approach: Divide the array in half recursively, then merge the sorted halves.
- Target complexity: O(n log n) time, O(n) space.
27. Search in Rotated Sorted Array
- Prompt: Search for a target in a sorted array that has been rotated at some pivot.
- Approach: Modified binary search. Determine which half is sorted, then decide which half to search.
- Target complexity: O(log n) time.
For problems on sorted data, consider whether a two-pointer approach works before reaching for a hash map. Sorting + two pointers is sometimes more space-efficient.
SQL
28. Employees Earning More Than Managers
- Prompt: Write a query to find employees who earn more than their manager.
- Approach: Self-join the employee table on manager_id = employee_id. Compare salaries.
- Target complexity: Straightforward join — focus on correctness and readability.
29. Duplicate Emails
- Prompt: Find all email addresses that appear more than once.
- Approach: GROUP BY email, HAVING COUNT(*) > 1.
- Target complexity: Single-pass aggregation.
30. Department Top Three Salaries
- Prompt: For each department, find the employees with the three highest salaries.
- Approach: Window function: DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC). Filter where rank <= 3.
- Target complexity: Know the difference between RANK, DENSE_RANK, and ROW_NUMBER — interviewers will ask.
SQL rounds follow the same clarifying-question discipline as algorithmic rounds. Ask about NULLs, duplicates, and expected output format before you write.
How to use these examples in practice
Working through a list of problems is not the same as being ready for a live interview. Here's how to turn these examples into actual preparation.
Pick one category per study session. Don't bounce between arrays, trees, and DP in the same sitting. Depth on one pattern builds intuition faster than shallow passes across many.
Start with the naive solution every time. State its complexity out loud, then optimize. Jumping straight to the clever answer skips the reasoning step interviewers are evaluating. One interviewer describes this explicitly as a named step in his evaluation process.
Practice out loud, not silently. Communication is evaluated. If you can't explain your approach while writing code, you'll struggle in the real thing. The Jane Street team's top piece of advice is exactly this.
Time yourself. Real interviews run 30–45 minutes. If you're spending an hour on a single problem in practice, you're not simulating the actual constraint.
Do mock interviews under realistic conditions. The Jane Street video says it directly: "practice as close to a real interview as possible." If you don't have a study partner, Verve AI's mock interview tool lets you practice with structured feedback on your communication, code quality, and time management — not just whether the answer is correct. And when the real interview comes, Verve AI's Interview Copilot listens to the conversation in real time and suggests approaches while you talk, invisible to the interviewer. You can try it free at vervecopilot.com.
How long does it take to prepare?
Minimum viable prep is about 30 hours. To be well-prepared, plan for closer to 100. Those numbers come from the Tech Interview Handbook, and they match what most engineers report.
Most candidates underestimate the time. Starting with worked examples like the ones above cuts ramp time because you're learning patterns, not memorizing individual answers. Once you recognize that a problem is a sliding-window problem or a prefix-sum problem, you already know the shape of the solution before you write a line of code.
Frequently asked questions
What language should I use in a coded interview? Python, Java, C++, or JavaScript are all widely accepted. Pick the one you're most fluent in. The interviewer cares about your reasoning, not your language choice.
Do I have to get the optimal solution? No. Interviewers want to see your reasoning. State the naive approach, explain its complexity, then improve it. Getting from O(n²) to O(n) while explaining why is more impressive than jumping to O(n) with no context.
What if I get stuck? Ask a clarifying question or talk through what you know so far. Silence is worse than an imperfect thought. Interviewers are trained to give hints — but only if you're communicating.
How many problems should I practice? Quality over quantity. Working through 30–50 problems deeply — understanding the pattern, not just the solution — beats skimming 200. The 30 examples on this page are a strong starting set.
Taylor Nguyen
Interview Guidance

