Guide · coding-prep
How to Recover From a Wrong Solution Mid Coding Interview
Catching your own wrong answer out loud is a stronger signal than getting it right the first time. State the bug clearly, propose the fix, and rewrite. Don't apologize. The interviewer is grading your recovery, and recovery is half the rubric.
By Sam K., Founder, InterviewChamp.AI · Last updated
TL;DR: When your solution turns out to be wrong, stop typing, name the bug out loud against a real input, and propose the fix in one sentence before you touch the code again. Decide whether it's a one-line fix or a full scrap, announce a scrap with a time estimate, and skip the apology. Handled out loud, a wrong turn shows the debugging skill interviewers grade, and it can score as well as a clean first try.
How do you recover from a wrong solution mid-interview?#
Three moves. Stop typing, say what the bug is, and propose the fix in a single sentence before you write any more code. Don't apologize. Don't restart in silence. And don't keep going as if the code still works.
Self-correction is catching and fixing your own mistake on the record, out loud. It's one of the highest-graded signals on coding-interview rubrics, and it can score as well as a clean first-try solution. Put plainly, the recovery is the thing being graded.
As of the 2026 hiring cycle, interviewers at companies running structured loops often grade debugging behavior. The reason is simple: the day job is mostly fixing code that doesn't work yet, not writing it perfectly on the first pass. I've watched strong new grads talk themselves out of an offer by quietly deleting a wrong solution when they should have narrated the fix. A wrong turn handled well is a free point, not a death sentence.
What you want is to walk out able to say "I caught it, I named it, I fixed it" in your own voice. That holds whether the round was a phone screen on a shared pad or a full onsite.
The 30-second recovery script#
You'll realize your solution is wrong in one of two ways: you spot it, or the interviewer points it out. Either way, run this exact sequence.
Second 1-5, stop and acknowledge. Say "Wait. Let me look at this." out loud, and take your hands off the keyboard. Nobody thinks well while typing, and the interviewer needs to see you switch from writing code to debugging it.
Second 5-15, name the bug. "The issue is that when there are duplicates, the hash map overwrites the earlier index, so I lose the first occurrence." That sentence is specific and falsifiable. The interviewer can now grade your diagnosis instead of guessing at it.
Second 15-25, propose the fix. "I think if I switch the value from a single index to a list of indices, that handles it without changing the time complexity." Now the recovery has somewhere to go. You've shown a destination, not just a problem.
Second 25-30, check the direction before re-coding. "Does that approach make sense, or are you seeing a simpler fix?" One short check. Then code.
The whole thing takes thirty seconds and reads as engineering. Compare it with the usual new-grad move: silently delete the code, re-type it, and hope the interviewer didn't notice. That version is almost always graded down.
The five-step recovery method (the numbered version)#
If you want one sequence to drill until it runs on autopilot, use this one. The same five beats work whether you caught the bug or the interviewer did.
- Stop typing and acknowledge. "Wait, let me look at this." Visibly switch from writing code to reading it. A dry run, stepping the program by hand against an input instead of running it, is how you read it.
- Name the bug specifically. Tie it to an input: "On
[1,1,2]this returns 1 instead of 0 because duplicates overwrite the index." A specific, falsifiable claim beats "something's off" every time. - Propose the fix in one sentence. "Switching the map value to a list of indices handles duplicates without changing the time complexity." One sentence proves you can target the bug, not just spot it.
- Pick fix-in-place or scrap, and announce a scrap. A one-line repair is a fix. A wrong data structure is a scrap. If you scrap, say so and give a time estimate.
- Re-code and re-trace the failing input. Run the exact case that broke it back through the fix, out loud, then hand the lead back: "Anything else you'd want me to check?"
Knowing which input to reach for in step 2 is its own skill, and honestly it starts before you write a line. The guide on how to handle clarifying questions on a coding problem covers how to surface the constraints that tell you where your code is exposed. The checking motion in step 5 gets a full treatment in the guide on how to test your code in an interview.
Finding the input that breaks it
Your best friend in step 2 is an adversarial case: the input picked because it's most likely to break your approach. Duplicates, an empty list, a single element, sorted-descending data. When you suspect something is off but can't say what, run one of those through a dry run before you say anything else.
It also helps to look at the boundary conditions first, meaning how your code behaves at the first, last, or empty position. That's where a wrong comparison operator (== versus <) flips the result. A lot of "my whole solution is wrong" moments turn out to be one bad comparison at the edge.
Fix in place vs scrap and restart: what the interviewer sees#
The recovery that tanks a round is almost never the bug itself. It's picking the wrong recovery and doing it silently.
Two terms first. Fixing in place means a one-line repair you can name in a sentence. Scrapping means your structure or approach can't represent the problem, so you restart on purpose. Here's how each path reads across the moments that come up in real rounds.
| The situation | Silent / wrong recovery | Narrated, deliberate recovery | |---|---|---| | Off-by-one or wrong operator | Delete and re-type quietly; reads as careless | Name it, change one line, re-trace the case; reads as debugging | | Hash map loses a duplicate index | Keep patching around it | One-sentence fix: switch the value to a list of indices | | Data structure can't represent the input | Force it and stall | Announce a scrap with a time estimate, then restart cleanly | | Interviewer catches the bug first | Get defensive: "are you sure mine works?" | "Good catch, let me trace it," then trace it for real | | You've restarted once already | Restart again silently (now a yellow flag) | Step back to clarifying the problem before more code | | Time is running short | Abandon the broken code, freeze up | Narrate a partial fix; partial credit beats silence |
Look at the last row for a second. Running low on time doesn't change the rule. If you can't finish the fix, say what the fix would be and how you'd test it. That still gives the interviewer something to write down.
When to fix vs when to scrap#
Some bugs are local: a missing edge case, an off-by-one, a wrong comparison operator. An off-by-one error is iterating one element too far or one too few (range(len(arr)) versus range(len(arr) - 1)), and it's one of the most common live-interview bugs in Python and Java alike. Fix it in place. State the fix, change one line, move on.
Other bugs are architectural. Your data structure can't represent what the problem needs, or your loop runs the wrong direction. That's a scrap, a deliberate restart because no local edit can save the approach. Spotting which inputs expose this kind of bug is the same skill you use when you handle a coding problem you have never seen: you reason from the constraints to the structure.
Here's the test I'd use in the room. Can you describe the fix in one sentence without restating the algorithm? If yes, fix in place. If you hear yourself saying "well, if I changed the data structure, then I'd also need to change..." you're doing a scrap, so announce it:
"My current approach can't handle case X without significant restructuring. I think a [different structure] handles it cleanly. Let me restart with that, should take about five minutes."
One scrap and restart is normal. A clean, announced recovery from a full restart can still end in a hire, so don't treat it as the end of the round. For more on what interviewers look for, see the Indeed Career Guide on technical interviews.
A second restart is a different story. The table above calls it a yellow flag, and the fix is not to restart faster. Stop, go back to the problem statement, and confirm the inputs and constraints with the interviewer before you write more code.
Why apologizing hurts more than the bug#
The instinct is to say "sorry, I should have seen that." Don't.
An apology does three kinds of damage at once. It signals you think the bug is shameful, which makes the interviewer wonder how you'd act on a real team where bugs show up every day. It eats time you should be spending on the fix. And it shifts the frame from "engineer at work" to "candidate being judged."
Say "good catch, let me fix it," not a long "I'm so sorry, I can't believe I missed that." The mistake and the fix are the same either way; only the first one sounds like an engineer at work. For more on how interview feedback gets written, the Pragmatic Engineer newsletter is worth a read.
So swap the apology for a short, neutral line and get straight to the trace.
How to handle the interviewer catching your bug#
If they catch it before you do, here's the playbook:
- Acknowledge briefly: "You're right, let me check." No "oh no" or "ugh."
- Trace through it on the spot: "If the input is
[5], a single element, my code returns 1 instead of 0. So yes, that edge breaks it." - Diagnose out loud: "The bug is in the inner condition. I'm checking
==when I should be checking<." - Fix: Change the line, re-trace the small example, confirm.
- Thank them once, briefly: "Thanks for that, good check." Then move on.
What sinks candidates here is defensiveness. "Are you sure?" "Hmm, I think mine works..." Even if you're fairly sure they're wrong, run their counter-example. If your code does survive, say "I traced through [5] and it returned 0, am I missing what you meant?" Calm checking beats defensive pushback every time.
It's the same composure you'd hold with a rude interviewer. The test isn't whether you're right. It's whether you stay level.
Phrases to have ready#
Under pressure, the right words don't show up on their own. These lines come straight from the script and playbook above, gathered in one place so you can say them without thinking:
| Moment | What to say |
|---|---|
| You just noticed something is wrong | "Wait. Let me look at this." |
| Naming the bug | "On [1,1,2] this returns 1 instead of 0 because duplicates overwrite the index." |
| Proposing a fix | "If I switch the value to a list of indices, that handles it without changing the time complexity." |
| Checking direction | "Does that approach make sense, or are you seeing a simpler fix?" |
| Announcing a scrap | "My current approach can't handle case X. Let me restart with a different structure, should take about five minutes." |
| The interviewer found it | "You're right, let me check." |
| Your code survives their example | "I traced through it with [1,1,2] and it returned 0, am I missing what you meant?" |
| Handing back the lead | "Anything else you'd want me to check?" |
Memorize the shape, not the exact wording. Your version should sound like you.
What to do after the interview#
Sometimes you only realize the solution was wrong after the call ends. That feels awful, but you still have options.
If you're sending a thank-you note anyway, a short line about it is fine: what the bug was, what the fix would have been, and how you'd test it. Keep it to two or three sentences, with no apology and no full rewrite of the code. Then let it go. The interview itself is what gets graded, and replaying it all evening won't change a thing.
What you can change is the next round. Write down the input that broke your code and the fix, and add that problem to your drill list.
Drill the recovery until the shape is automatic#
Recovery is a learned skill. The drill: pick a LeetCode problem you've solved cleanly, then re-solve it knowing you'll introduce a bug halfway through. Practice catching it on a small example, naming it, and fixing it, all out loud. Don't pre-script the answer. Script the shape of the response. The candidates who win recovery moments have rehearsed that shape so many times that it runs even under stress.
A couple of variations keep the drill from going stale:
- Have a friend plant the bug. Swap a
<for<=or drop an edge case, then find it with a dry run while you talk. - Do a short write-up after each mock. Note where you went wrong, how long it took you to notice, and whether you said the fix before you typed it.
The honest way to make this automatic is reps under realistic pressure with feedback, not a tool feeding you the answer mid-round. As of the 2026 hiring cycle, many interviewers can tell when an answer is recited and the candidate can't defend it, so that kind of shortcut isn't the edge it's sold as. The edge that lasts is being able to debug your own work live, whether the round runs on CoderPad, HackerRank's collaborative pad, or a plain shared doc.
If you want to rehearse the five-step recovery against realistic prompts until it's muscle memory, run a timed mock interview and deliberately fix your own bug before the interviewer can. The plans on the pricing page cover unlimited timed sessions, with Pro at $29 a month, and the free plan (60 minutes a month, no card) is enough to run your first few recoveries before your next real loop. The candidate who recovers out loud is the one who walks in able to say the whole answer, bug, fix, and all, in their own voice.
Key terms#
Self-correction: Catching and fixing your own mistake on the record, out loud. One of the highest-graded signals on a coding-interview rubric, can score as well as a clean first-try solution.
Dry run: Executing your code by hand against a chosen input, tracing the variable values line by line. The fastest way to confirm whether a suspected bug is real when you can't run the code.
Fix in place: A local repair (a missing edge case, a wrong operator, an off-by-one) that you can describe in one sentence without restating the algorithm. State it, change one line, re-trace, move on.
Scrap and restart: A deliberate rewrite because the data structure or approach can't represent the problem and no local edit can save it. One announced scrap inside a round is normal; the key word is announced.
Off-by-one error: Iterating one element too far or one too few in a loop bound or index. One of the most common bugs surfaced and fixed during a live coding interview.
Boundary condition: How your code behaves at the first, last, or empty position (see "Finding the input that breaks it" above).
Adversarial case: The input most likely to break your approach (see "Finding the input that breaks it" above).
About the author: Sam K. is the founder of InterviewChamp.AI and writes about the modern tech interview from the inside: what changed, what works for new grads, and where the old playbook fails.
Originally published on InterviewChamp.AI
Frequently asked questions
- Will catching a wrong solution mid-interview hurt my chances?
- Usually the opposite. Self-correction is one of the most positively-graded signals on tech interview rubrics. Catching your own bug calmly often scores higher than a solution that worked the first time, because it proves you can debug, which is what the job actually requires.
- What should I do the moment I realize my solution is wrong?
- Say it out loud immediately. 'Wait, this fails when the input has duplicates. Let me trace through.' Don't keep typing in hope. The longer you push a known-wrong solution, the worse it looks. Pause, name the bug, propose the fix.
- What if the interviewer caught the bug before I did?
- Thank them briefly, then own the fix. Don't get defensive. 'Good catch, let me trace through what I missed.' Then actually trace it. Interviewers want to see how you take feedback under pressure; defensive responses tank that signal.
- Is it ever okay to scrap the solution and start over?
- Yes, but announce it. 'My approach doesn't actually work for case X. I think a different structure handles this, let me switch to that.' One scrap and restart is fine. Two is a yellow flag. Three usually means the problem wasn't understood in the first place.
- What if I'm not sure whether my solution is actually wrong?
- Trace through a small adversarial example. Pick the case most likely to break your solution (empty input, duplicates, single element, sorted-descending). If it works, you're fine. If it breaks, you've found the bug yourself, which is the best possible outcome.
- How do you recover from a wrong solution in a coding interview without losing the round?
- Run a four-beat recovery: stop typing, name the bug on a specific input, propose the fix in one sentence, then re-code and re-trace the failing case out loud. The round is rarely lost on the wrong turn itself; it's lost by pushing a known-broken solution silently or getting defensive. A calm, narrated self-correction is graded as debugging skill, which is most of what the job is.
- Is it bad to start over in a coding interview?
- One restart inside a 45-minute round is normal and often scores fine, as long as you announce it and explain why your first approach couldn't represent the problem. Two restarts is a yellow flag. Three usually signals the problem was never understood, which is a clarifying-questions miss earlier in the round, not a coding miss.