Interview prep · Coding round

How to prepare for a debugging interview

In a debugging interview you get code you didn’t write, with a bug in it. You find the bug and fix it while the interviewer watches how you work. Some companies call it a debugging round or a bug squash. Expect 45 minutes to an hour, most often on your own machine.

By NextBeingUpdated 6-minute read, with 9 bugs to find

The short answer

To prepare for a debugging interview, practice out loud on programs that fail. Read the output first and decide where it points: the line with the bug, the line where the program stopped, or only the test that failed. Then make one guess, test it, and make the smallest fix. Before the round, get a project with tests running on your own machine.

4 of 9programs on this page fail with output that points to the line with the bug. In the other 5, the line it points to is fine. How they were run
32 and 16minutes: what 12 developers, 11 of them professionals, took to find a real bug and then to fix it, on average, in a 2017 experiment. Finding took twice as long. Source 3
72%of 176 developers surveyed for a 2018 study said they debug with print statements, and 81% said they use their editor’s debugger. Of 458 whose editors were tracked for a median of six days, 29% started it. Source 4
Exercise · about five minutes

9 debugging interview practice questions

Each one is a short program that fails, in Python, JavaScript, Rust, C++ or SQL. Press Run and read the output. Say out loud where it points and what you think is wrong, then click the line with the bug. You get two tries.

Bug 1 of 9
word_counts.pyPython
# Coding problem (Python).
# word_counts(s): how many times each word appears, lower-cased.
# Example: word_counts("the cat the") -> {"the": 2, "cat": 1}
OutputThe output points to the line with the bug.

Nothing run yet. Press Run.

Traceback (most recent call last):
  File "word_counts.py", line 12, in <module>
    assert word_counts("the cat the") == {"the": 2, "cat": 1}
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "word_counts.py", line 8, in word_counts
    counts[w] += 1
    ~~~~~~^^^
KeyError: 'the'
After the fix: ok

The fix
8 counts[w] += 1
8 counts[w] = counts.get(w, 0) + 1

Say it like this“It's a KeyError on line 8, on the very first word. There's no count for that word yet, so I'd start each word at zero.”

initials.jsJavaScript
// Coding problem (JavaScript).
// initials(name): the initials in capitals, each followed by a dot.
// Example: initials("ada lovelace") -> "A.L."
OutputThe output points to the line with the bug.

Nothing run yet. Press Run.

initials.js:8
    .map((part) => part[0].toUpperCase() + ".')
                                           ^^^^

SyntaxError: Invalid or unexpected token
After the fix: ok

The fix
8 .map((part) => part[0].toUpperCase() + ".')
8 .map((part) => part[0].toUpperCase() + ".")

Say it like this“It's a syntax error, so nothing ran. Line 8: the string opens with a double quote and closes with a single one.”

sort_desc.rsRust
// Coding problem (Rust).
// sort_desc(v): v sorted from largest to smallest.
// Example: sort_desc(vec![3, 1, 2]) -> vec![3, 2, 1]
OutputThe output points to the line with the bug.

Nothing run yet. Press Run.

error[E0308]: mismatched types
 --> sort_desc.rs:6:22
  |
6 |     v.sort_by(|a, b| b - a);
  |                      ^^^^^ expected `Ordering`, found `i32`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
After the fix: ok

The fix
6 v.sort_by(|a, b| b - a);
6 v.sort_by(|a, b| b.cmp(a));

Say it like this“It doesn't compile. Line 6 has to return an Ordering and it returns a subtraction. I'd compare with cmp.”

longest.jsJavaScript
// Coding problem (JavaScript).
// longest(words): the longest word, or "" when there are none.
// Example: longest(["a", "abc", "ab"]) -> "abc"
OutputThe output points to the line with the bug.

Nothing run yet. Press Run.

longest.js:6
  return words.reduce((best, w) => (w.length > best.length ? w : best));
               ^

TypeError: Reduce of empty array with no initial value
    at Array.reduce (<anonymous>)
    at longest (longest.js:6:16)
    at Object.<anonymous> (longest.js:11:20)
After the fix: ok

The fix
6 return words.reduce((best, w) => (w.length > best.length ? w : best));
6 return words.reduce((best, w) => (w.length > best.length ? w : best), "");

Say it like this“The first test passes, so it works for a normal list. It's the empty list: reduce has nothing to start from. I'd give it an empty string to start with.”

row_totals.pyPython
# Coding problem (Python).
# row_totals(rows): each row's sum, and the grand total.
# Example: row_totals([[1, 2], [3, 4]]) -> ([3, 7], 10)
OutputThe output points to where it stopped. The bug is earlier.

Nothing run yet. Press Run.

Traceback (most recent call last):
  File "row_totals.py", line 15, in <module>
    assert row_totals([[1, 2], [3, 4]]) == ([3, 7], 10)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "row_totals.py", line 9, in row_totals
    t = sum(row)
        ^^^^^^^^
TypeError: 'int' object is not callable
After the fix: ok

The fix
6 sum = 0
6 total = 0
11 sum += t
11 total += t
12 return totals, sum
12 return totals, total

Say it like this“It stops on line 9, but that line looks right. 'int is not callable' means sum is a number there, and line 6 is what makes it one. I'd rename that variable to total.”

pair_sums.jsJavaScript
// Coding problem (JavaScript).
// pairSums(xs): the sum of each pair of neighbours.
// Example: pairSums([1, 2, 3, 4]) -> [3, 5, 7]
OutputThe output only shows which test failed.

Nothing run yet. Press Run.

node:assert:150
  throw new AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
+ actual - expected

  [
    3,
    5,
    7,
+   NaN
  ]

    at Object.<anonymous> (pair_sums.js:14:8)
After the fix: ok

The fix
7 for (let i = 0; i < xs.length; i++) {
7 for (let i = 0; i + 1 < xs.length; i++) {

Say it like this“The test on line 14 got one value too many, a NaN at the end. So the loop runs one step past the last pair. It's an off-by-one: I'd stop the loop one step earlier.”

find_index.pyPython
# Coding problem (Python).
# find_index(xs, target): the index of target in sorted xs, or -1.
# Example: find_index([1, 3, 5, 7], 7) -> 3
OutputThe output only shows which test failed.

Nothing run yet. Press Run.

Traceback (most recent call last):
  File "find_index.py", line 19, in <module>
    assert find_index([1, 3, 5, 7], 7) == 3
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
After the fix: ok

The fix
7 while lo < hi:
7 while lo <= hi:

Say it like this“Searching for 3 works and searching for the last element doesn't, so it's a boundary. When lo and hi meet there's still one element to look at, and the loop stops there.”

sum_all.cppC++
// Coding problem (C++).
// sumAll(v): the sum; each value up to 2e9. Example: {2000000000, 2000000000} -> 4000000000
#include <iostream>
#include <vector>
#include <cassert>
OutputThe output only shows which test failed.

Nothing run yet. Press Run.

Assertion failed: (sumAll({2000000000, 2000000000}) == 4000000000LL), function main, file sum_all.cpp, line 15.
After the fix: ok

The fix
8 int total = 0;
8 long long total = 0;

Say it like this“Small sums pass and the four-billion one fails, so something overflows. The return type is long long, but the adding happens in an int. I'd make total a long long.”

totals.pySQL in Python
# Coding problem (SQL, run with sqlite in Python).
# Each customer's total order amount. Ana: orders 100 and 50 -> 150 (the 100 was paid in two parts).
OutputThe output only shows which test failed.

Nothing run yet. Press Run.

[('Ana', 250), ('Ben', 70)]
Traceback (most recent call last):
  File "totals.py", line 26, in <module>
    assert rows == [("Ana", 150), ("Ben", 70)], rows
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: [('Ana', 250), ('Ben', 70)]
After the fix: [('Ana', 150), ('Ben', 70)]
ok

The fix
19 JOIN payments p ON p.order_id = o.id

Say it like this“Ana shows 250 and it should be 150. That's exactly one extra 100, the order paid in two parts. The payments join repeats it, and the total doesn't need payments at all.”

found within two tries
found on the first try
your median time from Run to the right line
What the output pointed toFound
The output points to the line with the bug.
The output points to where it stopped. The bug is earlier.
The output only shows which test failed.

How do you read a stack trace or a failed run?

Find the line that names the error. A Python traceback puts it last. Node and compilers put it near the top, next to the file and the line. Then look at where it points, which is one of three places.

The line with the bugA syntax error, a compile error, or a crash on the broken line itself. Go to that line. 4 of the 9 programs above fail this way.
The line where it stoppedThe program ran until something was wrong, and the cause is earlier. If the line looks right, ask where the value it complains about came from. 1 of the 9: row_totals.py stops on line 9 because of what line 6 did.
Only the test that failedA test compared the result with what it expected, and they differ. No line of the function is mentioned. Follow the failing input through the code by hand. 4 of the 9, including the off-by-one in pair_sums.js.

What happens in a debugging interview?

You get a codebase with a bug in it and 45 minutes to an hour. Expect finding the bug to take longer than fixing it. In a 2017 experiment, 12 developers, 11 of them professionals, took 32 minutes on average to find a real bug and 16 to fix it (source 3).

Expect a failing test to start from, or a report of what goes wrong. NextBeing read 20 public first-hand accounts of debugging interviews in November 2026: 12 by people who give the round and 8 by candidates. The bug shows up as a failing test in 4 of them, and in a fifth the candidate works until the tests pass. In 3 it comes as a report of what goes wrong. One interviewer hands over code whose tests all pass, and two more describe a round where you read the code and say what is wrong, with no test mentioned. Six of the 8 candidates worked on their own machine. Two accounts give the length as about an hour and a third works out at 45 minutes, the length our coding interview time management plan uses. How we counted

Do you have to find the bug to pass?

Two of the 12 interviewers say outright that you don’t. A third scores whether you follow a guess through to a conclusion, and says a wrong guess is fine if you test it and drop it. One disagrees: if solving the bug doesn’t count, the scoring turns arbitrary. Plan to find it. If time runs out, say what you’ve confirmed, your current guess, and the next thing you’d check. Needing a hint isn’t a fail: one candidate in the accounts got one and passed.

What do you say while you debug?

Five things, in this order. Each of the 9 programs above ends with an example of the first two, and for most the fix too.

  1. Read it“The error says… on line…”
  2. Guess“My guess is… because…”
  3. Check it“The quickest way to check that is…”
  4. Fix it“It’s a small fix. I’ll change…”
  5. Add a test“The test that would have caught this is…”

On the first program above, the third sounds like this: “The quickest way to check that is to print the dictionary just before line 8.”

How do you find your way in a large codebase?

Reproduce the bug first: run the failing test and read what it prints. A long stack trace often has more library frames than yours. Find the frame in a file you were given that is closest to the error: the last one in a Python traceback, the first one in Node. Read the function it names, then the functions that one calls, and leave the rest of the repository alone until the trail leads there.

When the output doesn’t name the line, print the value before and after the call you suspect, and change one thing at a time. When all you have is an error message, search the code for its words. That takes you to the line that printed it.

Can you use print statements, a debugger or AI tools?

Expect prints to be allowed. None of the 20 accounts describes a ban on them. In a 2018 study, 72% of the 176 developers surveyed said they debug with print statements, and 81% said they use their editor’s debugger. The study also tracked 458 developers’ editors for a median of six days, and 29% of them started the debugger (source 4). None of the accounts states a rule on AI tools, so ask your recruiter before the day.

Learn three debugger actions in your own editor before the round: set a breakpoint, step one line, and print a variable. One candidate describes a debugger setup that felt clunky in the round, and ending up with prints.

How do you practice for a debugging interview?

  1. Small programs first. Do the 9 above until you can say where the output points before you look at the code.
  2. Your own code, broken by someone else. Take a solution you wrote last month and ask a friend to change one line. Good changes to ask for: an off-by-one, a missing empty-input case, a value counted twice.
  3. A real project. Clone a small open-source project in your language and run its tests. Pick a bug fix from its history, check out the commit before it, and find the bug from the report.
  4. Your setup. Do step 3 on the machine and editor you’ll use in the round. Two candidates describe the time going to setup instead: an old laptop with an unfamiliar editor, and a project that couldn’t be run reliably.
All 9 programs and their fixes as a table
ProgramLanguageThe error it printsWhat the output points toThe line with the bugThe fix
1. word_counts.pyPythonKeyError: 'the'The line with the bugLine 8: counts[w] += 1line 8: counts[w] = counts.get(w, 0) + 1
2. initials.jsJavaScriptSyntaxError: Invalid or unexpected tokenThe line with the bugLine 8: .map((part) => part[0].toUpperCase() + ".')line 8: .map((part) => part[0].toUpperCase() + ".")
3. sort_desc.rsRusterror[E0308]: mismatched typesThe line with the bugLine 6: v.sort_by(|a, b| b - a);line 6: v.sort_by(|a, b| b.cmp(a));
4. longest.jsJavaScriptTypeError: Reduce of empty array with no initial valueThe line with the bugLine 6: return words.reduce((best, w) => (w.length > best.length ? w : best));line 6: return words.reduce((best, w) => (w.length > best.length ? w : best), "");
5. row_totals.pyPythonTypeError: 'int' object is not callableWhere it stopped; the bug is earlierLine 6: sum = 0line 6: total = 0; line 11: total += t; line 12: return totals, total
6. pair_sums.jsJavaScriptAssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:Only the test that failedLine 7: for (let i = 0; i < xs.length; i++) {line 7: for (let i = 0; i + 1 < xs.length; i++) {
7. find_index.pyPythonAssertionErrorOnly the test that failedLine 7: while lo < hi:line 7: while lo <= hi:
8. sum_all.cppC++Assertion failed: (sumAll({2000000000, 2000000000}) == 4000000000LL), function main, file sum_all.cpp, line 15.Only the test that failedLine 8: int total = 0;line 8: long long total = 0;
9. totals.pySQL in PythonAssertionError: [('Ana', 250), ('Ben', 70)]Only the test that failedLine 19: JOIN payments p ON p.order_id = o.idline 19 removed

In NextBeing’s coding exercises, a failed Run comes back as one message: what broke, the line, and the change that fixes it. Use it in a live interview only where AI help is allowed.

NextBeing for coding rounds

How the exercise was made

The 9 programs come from the set NextBeing uses to test how it reads a failed run. We ran each one on November 28, 2026 with Python 3.12.16, Node.js v22.23.5, rustc 1.100.0 and clang 21.0.0. Then we ran it again with its fix, and kept the fix only when it printed ok. The output is shown as printed, with the folder path removed. For JavaScript, everything from Node’s own stack frames on is cut. The programs are 12 to 27 lines long. The code in a real round is larger, and its stack traces can be longer, with library frames among yours.

The 20 accounts

In November 2026 we searched for debugging interview, debugging round and bug squash, and kept 20 public first-hand accounts from 2019 to 2026: 12 by people who give the round, 8 by candidates. Eleven come from one forum discussion of August 2024, the post and ten commenters under it. The rest are blog posts and forum posts. One was read as a preview only, one was edited by the site that published it, and one describes a troubleshooting interview with no code handed over. Three of the 12 don’t state their role, and we took it from what they write. We count an account only when it states the point outright. Twenty accounts is a small sample, so ask your recruiter how your round is run.

Sources

  1. NextBeing, the 9 programs on this page and their runs, November 28, 2026.
  2. NextBeing, a review of 20 public first-hand accounts of debugging interviews, November 2026.
  3. Böhme and others, “Where is the bug and how is it fixed? An experiment with practitioners”, ESEC/FSE 2017: 11 professional engineers and one researcher, 27 real bugs in two C programs, times as the participants reported them.
  4. Beller and others, “On the dichotomy of debugging behavior among programmers”, ICSE 2018.

Next: coding interview time management, a 45-minute plan, and a whole coding round played out.