Skip to content
DevFlash

Live coding

Live coding: solve a problem while explaining your reasoning

A guide to turning a problem statement into a solution during a supervised session.

  • 5 min read
  • 5 sections
  • Updated November 2, 2026

This guide is under editorial review.

In 1 minute

  • Confirm the environment, duration and allowed resources before the session.
  • Agree on a cycle of understanding, proposing, implementing and checking, communicating pauses and findings.
  • Test relevant cases and use hints to revise understanding without impulsively defending or discarding code.

Live coding is a session where you solve a problem while explaining decisions and answering questions from the person observing. The code matters, but the path must be understandable: which rule you understood, what you chose to test and why you changed direction. You do not need to narrate every keystroke; make consequential decisions visible.

This guide follows building a solution from a statement. When the activity centers on collaborating in an existing codebase, the focus shifts to pair programming interviews. Prepare to ask questions, implement a first version, respond to hints and finish with an honest account of what you verified and what remains.

How a live coding session works

Before the session, confirm the editor, language, duration and allowed resources. Ask whether you can run tests and consult documentation. If screen sharing is required, check audio and font size so the observer can follow. These checks reduce unrelated interruptions. Do not assume the environment matches a personal project or a previous assessment.

  1. Agree on a rhythm

    At the start, establish a simple rhythm: understand, propose, implement and verify.

  2. Communicate pauses

    Say when you need a short thinking pause, then return with what you found.

  3. Clarify uncertainty

    A supervised session allows clarifications that may be unavailable in an online coding test. Use that opportunity to resolve ambiguity without asking the interviewer to decide every line.

Four steps linked by a thought line: a question bubble, a sketch, a code window and check marks.
Agree on a rhythm of understanding, proposing, implementing and verifying so others can follow your reasoning.

Questions that turn a statement into a contract

Restate the problem and propose an example. If the task asks for the largest gap between times, ask whether values arrive sorted, whether duplicates are allowed and what to return with fewer than two values. Each answer changes implementation or tests. Avoid a memorized question list that has no effect on the current task.

  • Input: type, unit, ordering and expected size.
  • Output: format, missing results and rules for ties or duplicates.
  • Constraints: allowed mutation, available resources and relevant processing limits.
  • Examples: an ordinary case and another that distinguishes two possible interpretations.

After the answers, summarize the contract and confirm the example output. State unresolved assumptions before relying on them. 'I will assume sorted times and finite values' is verifiable. 'I will handle everything' does not define behavior. Keep decisions visible so misunderstandings can be corrected before they become embedded in the implementation.

A first solution with reasoning aloud

For this example, agree that times are finite numbers in ascending order, allowing equality, and that fewer than two values return zero. The largest adjacent gap requires comparing consecutive pairs. Explain the idea before writing the loop. The code neither sorts nor validates because those guarantees belong to the chosen contract. A changed contract requires reconsideration.

function largestGap(times: readonly number[]): number {
let previous: number | undefined;
let largest = 0;
for (const time of times) {
if (previous !== undefined) {
largest = Math.max(largest, time - previous);
}
previous = time;
}
return largest;
}
console.assert(largestGap([10, 15, 30]) === 15);
console.assert(largestGap([10, 10]) === 0);
console.assert(largestGap([]) === 0);

During implementation, communicate phase changes. Say when the calculation is complete and you are checking boundaries. Do not read every line aloud if that disrupts concentration. Explain structure through purpose: the previous time avoids comparing every pair, and the largest seen gap summarizes completed work. The loop visits each value once and keeps a small fixed set of variables.

If an alternative occurs to you, compare it with the actual requirement before switching. Sorting already sorted input adds work without resolving an existing uncertainty. Accepting unsorted input would require a different decision. Connecting contract and cost is more useful than reciting a complexity label without explaining what the program traverses.

Tests, corrections and interviewer hints

Choose cases that challenge your hypothesis: a single time, equal values and the largest gap at either end. Predict results before running. When behavior differs, identify the first point where it departs from expectations. The live debugging guide explores this investigation process when diagnosing a failure is the main activity.

Do

  • When given a hint, explain how it changes your understanding and test the consequence.
  • If the hint is ambiguous, ask whether it concerns the contract, correctness or cost. That distinction helps address the actual issue.

Avoid

  • Defending code merely because you invested time in it.
  • Discarding everything without checking what remains valid.

Closing with evidence and next steps

Before time ends, summarize implemented behavior, executed cases and relevant assumptions. If something is incomplete, describe the next step and the risk it leaves. Do not call missing core behavior a finishing touch. Distinguish observed results from behavior you expect but have not verified. The interviewer should be able to assess the current state without guessing.

Then review confusing names and unnecessary conditions without starting a major rewrite. Practicing interview code review helps with this final reading. Afterwards, record a contract question, a missed case and a decision you explained clearly. Use those notes to choose the next practice session rather than repeating exercises without reviewing your process.

Frequently asked questions

What is live coding in an interview?

It means solving a programming problem while someone observes and asks questions. Tools and duration vary. You demonstrate a solution and communicate the decisions connecting the statement to the code you produce.

How can I practice live coding alone?

Choose a problem, use a timer and explain decisions aloud. Record the contract, tests and remaining work. During review, check whether you explained direction changes and predicted results rather than only narrating syntax.

What should I do if I get stuck during live coding?

Return to a small example, state what you do not understand and test one hypothesis at a time. Ask for clarification or a specific hint. Preserve working parts instead of changing several rules without a clear reason.

Do I have to finish the exercise to do well?

Criteria depend on the process, so completion alone does not guarantee an outcome. Work toward the requirement; if time runs out, show evidence of working behavior, explain limits and describe a concrete continuation.

Practice with real tests

Solve front-end exercises in the browser, with the same tests a reviewer would run.

See the exercises