Pattern

Debugging a broken function

Given working-looking code and a symptom, find the root cause and fix it without breaking what already passes.

What it is

These questions hand you a function that looks reasonable, already has tests that pass, and fails in a specific, described way — a slightly wrong sort order, a value that only misbehaves in one timezone, a job that runs fine for months and then crashes. There is no algorithm to design; the skill is reading code the way you'd read someone else's pull request, forming a hypothesis from the symptom, and tracing execution until the hypothesis is confirmed or discarded. The categories repeat: language-semantics traps (identity vs. equality, mutable defaults, late-binding closures), numeric edge cases (overflow, floating point), and structural mistakes (mutating a collection while iterating it, shallow-copying nested data).

When it applies

Tells in the problem

The classic mistake

Interviewers commonly report candidates patching the symptom instead of the cause: adding a special case for the one example given, or wrapping the failure in a try/except, without forming a mental model of why the original code breaks. This surfaces immediately when the interviewer varies the example slightly — the patch doesn't generalize because it was never connected to the mechanism. The fix is to state the hypothesis out loud before touching code ("I think this fails because X compares by identity, not equality — let me check by predicting what happens on this modified input"), and only edit once tracing through the code confirms it. A correct fix should also make you able to say, in one sentence, why the given tests didn't already catch it.

Questions to start with

All 14 debugging a broken function questions

Problem statement, examples and hints are free on every page; the worked approach, solution and tests are in the company guides.

Free starter pack

13 must-tier questions with full solutions

Sign in with an email — no purchase — and read them in the full reader.

No password, no spam. One sign-in email; you can read the pack in the full reader.