In a timed coding interview with five minutes left and untested code, do you write more or trace?
answer
- the clock changes what a line is worth
- unverified code carries unknown risk
- who finds the bug is the signal
- pick the input that hits the boundary
- check what happens after the loop exits
basics
~20 sStop writing new code and trace a small concrete example through what already exists. A partial solution whose boundaries you checked yourself reads far better than an untested complete one that the interviewer has to debug for you.
solid answer
~50 sTrace. In the last five minutes a line of new code is worth less than a line of verification, because the marginal new code arrives untested and adds risk, while a hand-trace converts unknown correctness into known correctness on the part you already have. Pick a small input that exercises the boundary — empty, single element, all-equal, the last element — and walk it through the written code step by step, out loud, fixing what it exposes. The typical find is a missing final step or an index that stops one short, and finding it yourself is a materially different signal from the interviewer finding it. The one exception is a genuinely small mechanical finish — a return statement, a final accumulation — where completing it takes under a minute and makes the whole thing coherent; do that, then trace. Whatever gap remains, name it and say what it would take.
code
pseudocode · 12 lines// compress readings into (value, run_length) pairs
runs = empty list
start = 0
for i in 1..length(readings)-1
if readings[i] != readings[start]
add (readings[start], i - start) to runs
start = i
return runs
// trace [a,a,b,b,b,c]: emits (a,2) at i=2, (b,3) at i=5, then ends.
// the final run (c,1) is never emitted -- and a single-element
// input returns an empty list.go deeper
Know that finishing the code is not the goal on its own, and that walking one small input through what you wrote is expected before you call it done. Practise stopping to trace even when you feel close.
Explain how to trace properly: a deliberately chosen boundary input, the loop state written down row by row, and an explicit check of what happens after the loop exits rather than only inside it.
Demonstrate the judgment call under pressure — that marginal untested code adds risk while verification removes it — and the exception for a one-minute mechanical finish. Show that you scope the remaining gap precisely instead of leaving it silent.
Own what this means for a rubric you set: decide in advance whether a verified partial solution outranks an untested complete one, and make sure your interviewers score it consistently. If they do not, the loop rewards volume of code over engineering judgment, which is the opposite of the intended signal.
## The decision At minute 35 of a 40-minute round you have code that is close but unverified. The instinct is to keep writing, because incomplete code feels like the visible failure. The instinct is usually wrong, and the reason is about what the remaining minutes can actually buy. Five minutes of new code buys, at best, a few more lines that are also unverified. Five minutes of tracing buys a definite claim about the code you already have: it works on this input, and here is the boundary that breaks. Those are not equivalent outcomes, because the person on the other side is not scoring line count. They are trying to answer one question: *if this candidate shipped this, would the bug reach production?* A candidate who finds their own off-by-one has answered it. A candidate who hands over untested code has left it open, and the interviewer will answer it by finding the bug themselves. ## What tracing actually means Tracing is not "reading it over again" and it is not mentally running the algorithm you intended. It is executing the code as written against a specific small input, keeping the state visible: - Choose the input deliberately: an input where the interesting thing happens at the **last** position, or an all-equal input, or the empty and single-element cases. The example the interviewer gave usually walks the happy path, which is precisely where bugs are not. - Track the actual variables in a small table on the side — index, accumulator, whatever the loop maintains — one row per iteration. Written state is what makes a missing update visible; state held in your head reproduces the same assumption that created the bug. - Check what happens after the loop exits, not just inside it. The single most common interview bug is a final element or final run that the loop body handles but the exit path never emits. ## The exception There is one case where finishing wins: the remaining work is small and mechanical, and its absence makes the solution incoherent rather than incomplete — a missing return, a final accumulation, a result never assembled. If that takes under a minute, do it, because tracing an unfinishable fragment tests less. What does not qualify is "one more case to handle" or "the optimization I was going to add": those are new logic, and new logic at minute 37 is where the boundary bugs come from. ## Naming the gap Whatever is unfinished, state it explicitly and concretely: which case is unhandled, what the code currently does on it, and what the fix would be. That costs 20 seconds and changes the interpretation of the whole artifact — an acknowledged gap is a scoped known issue; an unacknowledged one is indistinguishable from not knowing. "I have not handled the empty input; the loop would read index zero and fail, so it needs a guard before the loop" is a strong sentence to end on. ## Practising the endgame The last five minutes are a skill, and they are almost never practised because untimed practice has no endgame — you simply keep going until it works. Two drills fix that: 1. **Hard stop at minute 35.** Whatever state the solution is in, stop writing and spend the last five minutes tracing. Do this even when you are two lines from done. The point is rehearsing the switch from producing to verifying, which is the part that fails under pressure. 2. **Trace someone else's half-finished attempt.** Take a fragment — your own from a previous session, or a peer's — and find the boundary bug in three minutes. This trains the specific habit of picking adversarial inputs rather than confirming ones. ## Why the switch is hard Producing and verifying are different mental modes, and switching under time pressure feels like giving up: you stop making visible progress. That feeling is the reason a protocol beats judgment in the moment. Decide the rule before the round — at five minutes, I stop writing — so that the decision is not being made by the part of you that is stressed and behind.
- When is finishing the code the right call in the last five minutes?When the missing piece is small and mechanical and its absence makes the solution incoherent — a return statement, a final accumulation, a result never assembled. Under a minute of work, then trace. What does not qualify is new logic such as an unhandled case or a planned optimization, because logic added at minute 37 is untested and is where boundary bugs are born.
- You trace, find a boundary bug, and there are two minutes left. Fix it or report it?If the fix is local — a guard, an extra emission after the loop, a corrected bound — apply it and re-trace just that path. If it is structural, do not start a rewrite you cannot finish: state the defect precisely, what the code does today on that input, and the shape of the correct fix. A precisely scoped known bug is far stronger than a half-applied one.
- Which input do you pick when you only have time for one trace?The smallest input where the interesting event happens at a boundary — typically the last element, since loops that emit inside the body and never after it are the most common defect. Empty and single-element inputs are the next best, because they test the entry and exit paths at once. The interviewer's own example is usually the happy path and confirms rather than probes.
saying these in an interview costs you the question
- An untested complete solution beats a verified partial one
- Testing is the interviewer's job, not mine
- There is no time to trace, keep typing
- Tracing means re-reading the code carefully
- Admitting an unclosed gap only loses points