Coding interview examples: real questions by category

Coding interviews draw from four buckets: algorithms and data structures, practical building tasks, SQL, and behavioral questions. Below are 20+ examples of what actually gets asked — each with what it tests and how to approach it, so you practice the reasoning, not just the solution.

1. Arrays & strings

The warm-up territory of nearly every screen. These test whether you reach for the right data structure — usually a hash map or two pointers — instead of brute force.

Two Sum

Tests: Hash maps, trading space for time

Given an array of integers and a target, return the indices of the two numbers that add up to the target.

The brute-force pair loop is O(n²). Walk the array once instead, storing each value's index in a hash map and checking whether target − current is already in it — O(n) time, O(n) space. Saying that trade-off out loud is most of the answer.

JavaScript
function twoSum(nums, target) {
  const seen = new Map()
  for (let i = 0; i < nums.length; i++) {
    const need = target - nums[i]
    if (seen.has(need)) return [seen.get(need), i]
    seen.set(nums[i], i)
  }
  return []
}

Valid Anagram

Tests: Frequency counting

Given two strings, determine whether they contain the same characters in a different order.

Count character frequencies in one string, decrement while walking the other, and check every count lands on zero. Sorting both strings also works but costs O(n log n) — mention both and pick the counter.

Best Time to Buy and Sell Stock

Tests: Single-pass tracking of running state

Given daily prices, find the maximum profit from one buy and one later sell.

Track the minimum price seen so far and the best profit if you sold today. One pass, two variables — no nested loops needed.

Longest Substring Without Repeating Characters

Tests: Sliding windows

Find the length of the longest substring with no repeated characters.

Grow a window over the string, tracking seen characters; when you hit a repeat, shrink the window from the left past its previous position. Each character enters and leaves the window once — O(n).

Merge Intervals

Tests: Sorting as preprocessing

Given a list of intervals, merge all overlapping intervals.

Sort by start, then sweep once: extend the current merged interval while starts overlap its end, otherwise push it and start a new one. The insight interviewers want is that sorting makes overlap a purely local check.

2. Linked lists, trees & graphs

Pointer manipulation and traversal. Interviewers watch whether you can keep references straight and choose BFS vs DFS deliberately.

Reverse a Linked List

Tests: Pointer manipulation

Reverse a singly linked list and return the new head.

Walk the list with prev and current pointers, flipping each node's next as you go. The classic mistake is losing the rest of the list — save next before you overwrite it.

Python
def reverse_list(head):
    prev = None
    current = head
    while current:
        nxt = current.next
        current.next = prev
        prev = current
        current = nxt
    return prev

Invert a Binary Tree

Tests: Recursion basics

Swap the left and right children of every node in a binary tree.

Recurse: swap the children of the current node, then invert each subtree. Three lines — the interview value is explaining the base case and call stack clearly.

Binary Tree Level-Order Traversal

Tests: BFS with a queue

Return the values of a binary tree level by level.

Use a queue; snapshot its length at the start of each round so you know where one level ends and the next begins. This queue-per-level pattern reappears in dozens of tree problems.

Number of Islands

Tests: Grid traversal, flood fill

Count the islands in a 2D grid of land and water cells, where an island is connected land.

Scan the grid; every time you hit unvisited land, increment the count and flood-fill (DFS or BFS) to sink the whole island. Discuss marking cells visited in place versus a separate set.

Lowest Common Ancestor

Tests: Tree reasoning, recursion with meaning

Find the deepest node that is an ancestor of both given nodes in a binary tree.

Recurse into both subtrees: if each side finds one target, the current node is the answer; otherwise pass up whichever side found something. Explaining why the returned value means what it means is the real test.

3. Dynamic programming

DP questions test whether you can spot overlapping subproblems and build from a base case — interviewers care far more about the recurrence than memorized code.

Climbing Stairs

Tests: Recognizing a recurrence

You climb a staircase of n steps, taking 1 or 2 steps at a time. How many distinct ways can you reach the top?

Ways(n) = Ways(n−1) + Ways(n−2) — it's Fibonacci in disguise. Start with naive recursion, point out the exponential blow-up, then collapse it to two rolling variables for O(n) time, O(1) space.

Coin Change

Tests: Bottom-up DP over amounts

Given coin denominations and a target amount, return the fewest coins needed to make it, or −1.

Build an array of best answers for every amount from 0 up: for each amount, try every coin and take the minimum. Also say why greedy fails — with coins {1, 3, 4}, greedy gives 6 = 4+1+1 instead of 3+3.

House Robber

Tests: Take-or-skip decisions

Given a row of houses with values, maximize your haul without robbing two adjacent houses.

At each house, the best result is max(skip it, take it plus the best from two back). Two rolling variables again — the pattern behind a large family of “can't pick adjacent items” problems.

4. Practical & domain-specific

More companies now test real-world building skills instead of pure algorithms — small features, realistic constraints, and code you'd actually ship.

Implement debounce

Tests: Closures, timers — frontend staple

Write a debounce function that delays invoking a callback until it hasn't been called for n milliseconds.

Return a wrapper that resets a timer on every call, so only the last call in a burst fires. Follow-ups are predictable: how throttle differs, and preserving this and arguments.

JavaScript
function debounce(fn, delay) {
  let timer = null
  return function (...args) {
    clearTimeout(timer)
    timer = setTimeout(() => fn.apply(this, args), delay)
  }
}

Design a registration endpoint

Tests: API design, validation, error handling — backend staple

Design a RESTful endpoint that accepts, validates, and stores user registration data.

Walk through it in layers: route and verb (POST /users), input validation, duplicate-email handling, password hashing, and what each failure returns (400 vs 409). Interviewers listen for the error paths, not the happy path.

Fetch, filter, and render a product list

Tests: Async JavaScript and DOM work

Fetch products from an API, filter out items that are out of stock, and render the rest into the page.

An async function with fetch, a response.ok check, an Array.filter, and a render step. The differentiators are loading and error states — mention them before the interviewer asks.

5. SQL & data

Backend and data roles almost always include a query round. Self-joins and per-group ranking cover a surprising share of what gets asked.

Employees earning more than their manager

Tests: Self-joins

Given an employees table with a manager_id column, find employees who earn more than their direct manager.

Join the table to itself — one alias for the employee, one for the manager — and compare salaries. Aliases are the whole trick.

SQL
SELECT e.name
FROM employees e
JOIN employees m ON e.manager_id = m.id
WHERE e.salary > m.salary;

Top 3 products per category

Tests: Window functions

Find the three highest-selling products in each category for the current month.

RANK() (or ROW_NUMBER()) partitioned by category, ordered by sales, then filter to rank ≤ 3 in an outer query. Knowing why you can't put a window function straight into WHERE is the follow-up.

6. Behavioral

Coding loops nearly always include experience questions. Prepare three or four stories you can reshape rather than an answer per question.

Explain a complex concept to a non-technical stakeholder

Tests: Communication range

“Tell me about a time you had to explain something deeply technical to someone outside engineering.”

Pick a real moment, name the audience, and show the translation: the analogy you used and what changed because they understood. Practicing out loud matters more here than anywhere.

Walk me through a project you're proud of

Tests: Ownership and technical judgment

“Describe a project you're most proud of and your specific contribution to it.”

Structure it with STAR — situation, task, action, result — and keep “I” separate from “we.” Interviewers probe whichever detail sounds vague, so only claim what you can go deep on.

A disagreement about a technical decision

Tests: Collaboration under friction

“Tell me about a time you disagreed with a teammate about an approach. What happened?”

Show that you argued from evidence, committed to the outcome, and stayed on good terms. A story where you turned out wrong — and handled it well — often lands better than one where you won.

Reading examples isn't practicing

Every example above gets harder the moment someone is watching you solve it. That's the skill to train: run a mock interview in a live shared pad with a friend or mentor asking the follow-ups. Start with the mock coding interview guide, and if your real screen runs on CoderPad or HackerRank, warm up with the CoderPad and HackerRank guides.

Frequently asked questions

Common questions about practicing coding interview examples.

Most coding interviews draw from four buckets: data structures and algorithms (arrays, trees, graphs, dynamic programming), practical domain tasks like building a small feature or endpoint, SQL for backend and data roles, and behavioral questions about your experience. Most loops mix several buckets across rounds.
Depth beats volume. Working 20–30 well-chosen problems until you can explain each approach out loud outperforms silently grinding hundreds. Cover every category your target role tests, then rehearse under realistic conditions in a live mock interview.
It builds the algorithm muscle but skips the interview muscle — explaining your approach while someone watches, absorbing follow-up questions, and recovering when a hint changes your plan. That's why candidates who only grind solo often stall in live rounds. Pair solo drilling with mock interviews with a real person.
Recreate the actual format: a shared coding pad, a 45-minute timer, and a friend or mentor playing interviewer who asks follow-ups. Codex Interview gives you the live pad with code execution in five languages plus session playback, so you can review exactly how you performed afterwards.
The one you're most fluent in — nearly every company lets you choose. Python's brevity keeps you focused on the algorithm; if your target team works in a specific stack, practice in that language so its idioms are automatic under pressure.
Codex Interview logo

Now solve them with someone watching.

Practice these examples in a live coding pad with a real person.