← Live coding · Lesson 4 of 5

Finding and fixing bugs out loud

Treat bugs as normal: trace through, explain what went wrong, fix it and run it again, calmly.

What they’re listening for

  • • Do you debug step by step, or change things at random?
  • • Can you explain what went wrong?
  • • Do you stay calm, maybe even a little lighthearted?

Stiff vs. natural

Moment: Your test with back-to-back meetings (9 to 10 and 10 to 11) returns two meetings instead of one.

Sounds stiff

“Oh no. Sorry, this is wrong. Sorry. I don't know why. Let me just… change some things.”

Sounds natural

“Oh, interesting. I expected one meeting, 9 to 11, and I got two. So it breaks when one ends exactly when the next one starts. Yep, I wrote less-than instead of less-than-or-equal. Classic off-by-one. Every single time. Let me fix that and run it again… there we go.”

  • Say what you expected and what you got.
  • The light joke shows you're calm, and everyone has written this bug.
  • Run the test again to confirm the fix.

Tracing a bug with an example

  1. Interviewer

    “What happens if one meeting is completely inside another? Say 9 to 12 and 10 to 11.”

  2. You

    “Good one, let me trace it. After sorting, 9 to 12 goes in first. Then 10 to 11 starts at 10, which is before 12, so we merge, and set the end to… 11. Oh. That's wrong. It should still end at 12.”

    def merge_meetings(meetings):
        merged = []
        for start, end in sorted(meetings):
            if merged and start <= merged[-1][1]:
                merged[-1][1] = end
            else:
                merged.append([start, end])
        return merged

    Trace with real values, out loud. The bug often shows itself.

  3. You

    “So the end should be whichever one is later. I'll use max there.”

    def merge_meetings(meetings):
        merged = []
        for start, end in sorted(meetings):
            if merged and start <= merged[-1][1]:
                merged[-1][1] = max(merged[-1][1], end)
            else:
                merged.append([start, end])
        return merged

    Explain the fix in one sentence before you type it.

  4. You

    “Running it again… 9 to 12. Nice, thanks for that one.”

  5. Interviewer

    “Sure. Good catch.”

Debugging out loud

  • “Let me trace through it with the example.”Starting to debug, step by step.
  • “I expected…, but I got…”Describing the bug clearly.
  • “Oh, I see it.”The moment you find it.
  • “So the fix is…”Explaining before typing.
  • “Let me run that again to be sure.”Checking the fix.
  • “Classic off-by-one.”A light joke about a very common bug.

Humor and life talk

Works well

  • • A short, light comment about a common bug (“Classic.”)
  • • Laughing at your own typo, once, then fixing it

Skip it

  • • Calling yourself stupid or apologizing again and again
  • • Blaming the language, the editor or the interviewer's example
  • • Joking instead of fixing it

Example: “Ah, I forgot to return the list. The function did all that work and told nobody.”

Now say it out loud

Rehearse with the AI interviewer and get feedback on your answers.