# Debugging interviews: finding a bug in code you have never seen

> In a debugging round you are given unfamiliar code with something wrong in it. A method that works under pressure: read first, state what should happen, narrow it down, and check the units.

Source: https://hintvo.com/blog/debugging-interview-find-the-bug | Last updated: November 20, 2026 | Reviewed: 2026-11-20

A debugging round gives you twenty lines you have never seen and asks what is wrong. The people who do well are not faster readers. They follow a method: read before guessing, say what the code should do, find the first place where it does something else, and check the boring causes before the clever ones.

## Read it once, completely

Resist the urge to point at the first suspicious line. Read from top to bottom and say out loud what each part is for. Half the time you find the bug during this pass, and you find it with the context you need to explain it.

## Say what it should do

State the expected behavior in one sentence, and ask the interviewer to confirm it. A bug is a difference between expected and actual. If you do not have the expected side, you are only reviewing style.

## Walk one input through

Pick a small, concrete input and trace it line by line, writing down the value of each variable. The line where your written value stops matching what the code needs is the bug, or sits right next to it.

## Check the boring causes first

- **Units.** Seconds against milliseconds, bytes against kilobytes, cents against whole currency.
- **Boundaries.** The first item, the last item, the empty list, less-than against less-than-or-equal.
- **State that never resets,** or that is shared between calls.
- **The missing limit.** A value that grows forever because nothing caps it.
- **The wrong variable** in a copied line.

## An example of the first one

```ts
allow(userId: string): boolean {
  const now = Date.now();
  const bucket = this.buckets.get(userId) ?? { tokens: this.capacity, updatedAt: now };

  const elapsed = now - bucket.updatedAt;           // milliseconds
  bucket.tokens += elapsed * this.refillPerSec;     // per second
  bucket.updatedAt = now;

  if (bucket.tokens < 1) return false;
  bucket.tokens -= 1;
  this.buckets.set(userId, bucket);
  return true;
}
```

This rate limiter refills a thousand times too fast, because the elapsed time is in milliseconds and the refill rate is per second. It has a second bug of the list above: nothing caps the tokens at the capacity, so an idle user can save up a burst of any size.

## Fix the smallest thing, then say how you would prove it

Change as little as possible: divide by a thousand, add the cap. Then name the test you would write, with the input and the expected result. Interviewers often care more about that sentence than about the fix.

> **Where Hintvo fits:** when the code is on a shared screen, Hintvo reads it from the screen and answers with the bug, the reason and the corrected code. The example above is the kind of answer it gives. Use Hintvo only where AI help is allowed. Check the rules of your company, school or interviewer first, and respect a no. See [the interview copilot](https://hintvo.com/interview-copilot).

## Related

- [AI interview copilot that answers from your CV](https://hintvo.com/interview-copilot.md): How does Hintvo AI help in a job interview, and how do I practice with it?
- [Coding interviews: what to do in the first five minutes](https://hintvo.com/blog/coding-interview-first-five-minutes.md): What should I do in the first five minutes of a coding interview?
- [Pair programming interviews: how to think out loud](https://hintvo.com/blog/pair-programming-interview-think-out-loud.md): How do I do well in a pair programming interview?
