Skip to content

Interview question · Coding & Computer-Use Agents

Search-and-replace blocks, unified diffs or whole-file rewrites: choose an edit format.

Choose by measurement on your model and your repositories, with a default you can defend: search-and-replace for edits to existing files, whole files for new or tiny ones, and a strict applier either way.

mediumEssentialNewUpdated Nov 2026

TL;DR: Default to search-and-replace blocks for changes to existing files: compact, independent of line numbers, and easy to apply strictly (the quoted text must match exactly once). Use whole-file writes for new files and very small ones. Use unified diffs only if your model produces them reliably, applied by context rather than trusted line numbers. Then measure on your own tasks: apply rate, correctness after applying, output tokens and latency, per model, because the best format differs between models.

How to approach it

Compare the formats on cost and failure modes, give a default with reasons, and say how you would confirm it with data and keep it confirmed as models change.

A strong answer

The comparison.

Search-and-replaceUnified diffWhole file
Output tokensChanged region plus some contextChanged lines plus contextThe whole file
Fails whenQuoted text not exact or not uniqueLine numbers or context slightly offModel drops or alters unrelated lines
ApplyingExact unique matchPatch tool, ideally by contextOverwrite
ReviewEasyEasyHard: must diff afterwards

Default and reasons. Search-and-replace for existing files: models quote text more reliably than they count lines, the applier can be strict, and errors are explainable ("found twice; include more surrounding lines"). Whole files for new files, where there is nothing to disturb. Diffs where measurements show the model handles them well.

Measure on your work.

def score(runs):
    applied = [r for r in runs if r["applied"]]
    correct = [r for r in applied if r["tests_pass"]]
    return {"apply_rate": round(len(applied) / len(runs), 2),
            "correct_rate": round(len(correct) / len(runs), 2),
            "avg_out_tokens": round(sum(r["out_tokens"] for r in runs) / len(runs))}

search_replace = ([{"applied": True, "tests_pass": True, "out_tokens": 420}] * 88 +
                  [{"applied": True, "tests_pass": False, "out_tokens": 400}] * 6 +
                  [{"applied": False, "tests_pass": False, "out_tokens": 380}] * 6)
whole_file = ([{"applied": True, "tests_pass": True, "out_tokens": 2900}] * 85 +
              [{"applied": True, "tests_pass": False, "out_tokens": 3100}] * 15)
sr, wf = score(search_replace), score(whole_file)
print(sr["apply_rate"], sr["correct_rate"], sr["avg_out_tokens"])  # => 0.94 0.88 416
print(wf["apply_rate"], wf["correct_rate"], wf["avg_out_tokens"])  # => 1.0 0.85 2930

Illustrative numbers with a common shape: whole files always apply but are wrong more often (unintended changes elsewhere) and cost seven times the output tokens; search-and-replace fails to apply sometimes, but those failures are visible and fixable on the next turn.

Make failures cheap. Precise error messages for not found, ambiguous and whitespace mismatches; one retry with the file's current text; then fall back to a whole-file write for small files.

Keep it measured. Re-run the comparison when you change models; formats that suit one model can suit another poorly.

What interviewers probe next

"Can you accept fuzzy matches when the exact one fails?" Only with a guard: a single candidate above a high similarity, shown in the observation so the model can confirm. Silent fuzzy application is how the wrong function gets edited.

"What about structured edit tools (rename symbol, insert after function)?" Excellent where available: they are exact by construction. Language-server refactorings for renames beat text edits.

"Does the format affect review?" Yes: humans review diffs; whole-file outputs need diffing first, and large unintended changes hide in them.

What if?

What if · interview follow-ups

Hold your answer as the constraints change

You chose search-and-replace blocks with a strict applier.

  1. Start here

    What if 10% of blocks fail because the model quotes code it remembers rather than the current file?

How it's scored

Weak: Picks a format by habit without discussing failures.

Hire: Compares formats by cost and failure modes and defaults to search-and-replace with a strict applier.

Strong Hire: Adds measurement per model (apply rate, correctness, tokens), explains whole-file correctness risks, makes failures cheap with current text in errors, uses structured refactorings where they fit, guards any fuzzy matching, and re-measures on model changes.

Common mistakes

  • Silent fuzzy application.
  • Whole-file rewrites for large files.
  • Trusting diff line numbers.
  • Choosing once and never re-measuring.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 6, and the site remembers where you stopped in each one.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in raises your free answers from 5 to 6 per topic, adds an applied lesson in every topic and easy practice tests, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

Nobody has commented. Post a correction or another way to answer.