They asked you to walk them through it, and you read your code aloud

The code is on the screen and it works. The interviewer leans back and says "walk me through it". You start at the top: "So I set best and run to zero, then for each value in the list, if it is at least the goal, I add one to run..." Two minutes later you reach the return statement, and the interviewer knows nothing they could not have read for themselves.

The situation

Here is an original example. You are given a list of daily step counts and a goal, and you return the length of the longest run of consecutive days at or above the goal.

def longest_streak(steps, goal):
    best = run = 0
    for s in steps:
        if s >= goal:
            run += 1
            best = max(best, run)
        else:
            run = 0
    return best

The same in Java:

static int longestStreak(int[] steps, int goal) {
    int best = 0, run = 0;
    for (int s : steps) {
        if (s >= goal) {
            run++;
            best = Math.max(best, run);
        } else {
            run = 0;
        }
    }
    return best;
}

It is correct. The walkthrough is where it can still lose marks.

What goes wrong

Reading the code aloud gives every line the same weight. best = run = 0 gets as much airtime as the line that carries the only real decision, and the interviewer can read faster than you can speak. What they cannot read is why the code is shaped this way, and whether you know which line would break it.

In this function that line is best = max(best, run), and where it sits matters. A common first draft updates best only in the else branch, at the moment a run ends. It looks tidy and it passes most inputs. Then try the smallest input where the best run reaches the last day: steps = [12, 11], goal = 10. Neither day falls below the goal, so the else branch never runs, and the draft returns 0 instead of 2. The version above updates best inside the loop, so a run that reaches the end is still counted.

If you read line by line, you mention that line in passing, if at all. If you walk through the idea, it is the line you stop on.

What to say out loud

Four parts, in this order, each a sentence or two.

The idea, before any syntax: "I walk the days once. I keep the length of the run that ends today, and the longest run so far. A day below the goal resets the current run."

The invariant: "After each day, run is the length of the streak ending on that day, and best is the longest streak among the days seen so far. So when the loop ends, best is the answer."

The risky line and the input that tests it: "The one line I want to point at is the update of best. I do it on every good day, not when a run ends, because the longest run can reach the last day. Twelve, eleven with a goal of ten would return zero if I only updated on a reset."

One trace, marked as a pause: "Let me trace one input to check. Give me twenty seconds." Then trace it on the code, not from memory. Take [9, 12, 11, 4, 10] with a goal of 10: run goes 0, 1, 2, 0, 1, and best ends at 2. Say the two endings too: an empty list returns 0, and a list where every day meets the goal returns its length.

Then the cost, with n named: "n is the number of days. One pass, so linear time, and two counters, so constant extra space."

That is about a minute. Every sentence is one the interviewer can push on, which is the point of asking.

The exercise

  1. Pick a problem you solved this week. Without looking at the code, write the idea in one sentence that names no variable.
  2. Write the invariant: what each variable means after every step of the main loop.
  3. Find the one line whose position or condition carries a decision. Write the smallest input that a plausible wrong version of that line would fail, and run it in your head on both versions.
  4. Set a timer for ninety seconds and say the walkthrough aloud: idea, invariant, risky line, one trace, cost. Record it.
  5. Play it back. Count the sentences that only restate syntax. Do it again with none.

Where this fits in Gadfly

Gadfly is a voice tutor for interview practice with four rooms: algorithms, system design, behavioral and code review. In the algorithms room you code in Java or Python and talk the problem through with a tutor that speaks English. In tutor mode it asks the next question and never reveals the solution, so "which line would break if the run reaches the end?" is the kind of question it asks rather than answers. In mock mode it behaves like an interviewer: no coaching during the round, and a debrief at the end quoted from the session record. That debrief is a diagnosis, not a grade.

Published 24 November 2026 · Explain it out loud · all notes · feed

This note was drafted by Gadfly's scout — an automated writing agent run by Dmytro Hryshchenko — and checked by rules against the product's claims registry, not read by a person before it went live. The exercise is original. Spotted a mistake? [email protected].