In AI-permitted coding interviews, the AI rarely produces a fully correct first draft. The bugs are usually subtle: an off-by-one, a wrong default, a missing edge case, a sign error, a function that handles one input shape but not the variant the problem actually requires. The candidate’s job is to catch these bugs faster than the AI can compound them.
This is a different debugging skill than catching your own bugs. The AI’s bugs have characteristic shapes; experienced AI-pair-programmers learn to predict them. This guide is the playbook.
The seven patterns of AI mistakes
Over thousands of pair-programming sessions, AI tools tend to make the same kinds of mistakes. Knowing the patterns lets you scan AI output efficiently rather than reading line by line.
- Off-by-one in loop bounds and slice indices. The AI almost always picks one of
n-1,n, orn+1; for tricky boundaries it sometimes picks the wrong one. Always check loop termination conditions and array slices on a small example. - Wrong default values. The AI defaults to “what makes the example case work” rather than “what is correct in general.” A function that returns
0for an empty list might be wrong if your problem actually wantsNoneor an exception. - Hidden assumptions about input shape. The AI assumes the input is what it expects, even when the problem says otherwise. If the problem says “the input may contain duplicates” and the AI’s solution uses set operations, the duplicate handling is silently lost.
- Confidence on imports and library APIs. The AI is often confidently wrong about which functions exist in which libraries, especially for less-common methods.
collections.OrderedDict.move_to_endexists;collections.OrderedDict.move_to_frontdoes not, but the AI might invent it. - Mixing up sign conventions and direction. In problems with directionality (graph edges, intervals, time-ordering), the AI sometimes flips the convention partway through. The first half of the function uses one direction; the second half uses the other.
- Plausible but unrelated solutions. Especially on multi-step problems, the AI sometimes solves a slightly different problem than the one asked. The code looks reasonable, runs, and is wrong because it answers the wrong question.
- Cargo-culted complexity. The AI sometimes adds unnecessary memoization, caching, or thread-safety to solutions where they are not warranted. The code is not wrong but is harder to verify and contains more surface area for hidden bugs.
The debugging workflow
Once you have the patterns in mind, the debugging workflow under interview pressure is a fixed sequence:
- Run the AI’s output on the example input. If it produces the wrong answer, the bug is obvious. If it produces the right answer, do not stop — proceed to step 2.
- Construct a minimal counterexample. Before trusting the code, try to think of an input that might break it. Look at edge cases (empty input, single-element input, duplicates, very large input, all-same input). Run the code on each.
- Trace the logic on a small input. Pick a 3-element example and walk through the code line by line, tracking variable values. This catches off-by-one and sign errors that automated runs miss because they do not test the boundaries.
- Read the imports and library calls. Verify each function the AI used actually exists with the signature it used. If you are unsure, ask the AI explicitly: “Does
list.first()exist in Python?” - Re-read the original problem. Did the AI solve the right problem? Specifically, did it handle every constraint mentioned in the problem statement? AI tools sometimes silently drop a constraint.
The whole sequence takes one to two minutes for a typical 30-line function. Senior candidates do it visibly — narrating each step — so the interviewer can see the verification rigor.
Specific examples
Off-by-one example: The candidate asks for “binary search to find the first index where arr[i] >= target.” The AI produces:
def lower_bound(arr, target):
lo, hi = 0, len(arr) - 1
while lo < hi:
mid = (lo + hi) // 2
if arr[mid] < target:
lo = mid + 1
else:
hi = mid
return lo
This looks fine but has an off-by-one when target is greater than every element. hi = len(arr) - 1 should be hi = len(arr) for the standard lower-bound pattern. The candidate who runs this on [1, 2, 3] with target=5 gets 2 instead of 3 — and the candidate who traces the logic catches the bug in 30 seconds.
Hidden assumption example: The problem is “given a list of integers that may contain duplicates, return the second largest unique value.” The AI writes:
def second_largest(nums):
nums.sort(reverse=True)
return nums[1]
This is wrong on duplicates: [5, 5, 3] returns 5 when it should return 3. The AI silently dropped the “unique” constraint. A candidate who re-reads the problem catches this; a candidate who does not, ships a wrong answer.
Plausible but unrelated example: The problem asks for “the longest substring of a string in which every character occurs an even number of times.” The AI, anchoring on “longest substring” patterns it has seen, writes a sliding-window solution for “longest substring without repeating characters” — solving a completely different problem. The candidate who has the original problem in mind catches this; the candidate who does not, ships a wrong answer.
How to demonstrate the skill
The interviewer wants to see verification visibly. Phrases that signal you are doing the work:
- “Let me trace through this with a small input before we move on.”
- “What happens if the list is empty? Let me check.”
- “I want to make sure this
OrderedDict.move_to_endfunction exists. Let me verify.” - “Wait — the problem said the input could have duplicates. Let me re-check whether this handles that.”
- “This is more complex than the problem needs. Let me ask the AI for a simpler version.”
None of these phrases is performative if you actually do the verification. Doing it without narrating means the interviewer cannot see the skill; doing it while narrating signals competence.
How to practice
The fastest way to build the skill is deliberate practice in the wrong direction: ask an AI tool to write code, then look for the bugs before running. Do this for an hour a day for two weeks. By the end you will have an intuition for where the AI is most likely wrong, and the verification step will be automatic.
For specific kinds of problems (graph traversal, dynamic programming, binary search) the AI has characteristic mistake patterns. Practicing on each kind of problem builds pattern recognition that is hard to learn any other way.
Frequently Asked Questions
What if I do not catch a bug and the interviewer points it out?
Acknowledge it directly: “Good catch — I missed that. Let me trace through and fix it.” Move on. Hiding the miss makes it worse.
Is it OK to ask the AI to find its own bug?
Sometimes yes; the AI can often find what it just wrote was wrong if you describe a failing test case. But the interviewer is grading your debugging skill, so do the diagnosis yourself before asking the AI to fix it.
How do I tell when to trust the AI vs verify?
Always verify. Even when the AI produces something that looks obviously correct, the cost of verification is low and the cost of accepting a hidden bug is high. With practice, verification takes seconds.
What if the bug is in a library function I do not know well?
Read the docs. The AI is often wrong about library APIs; the docs are the ground truth. Most modern editors with AI assistants also let you click through to the actual library source.
Are there problems where the AI rarely makes mistakes?
Common, well-trafficked problems — Two Sum, FizzBuzz, basic tree traversals — the AI almost always solves correctly. The interview signal in those cases is more about communication and edge-case discussion than bug-catching. The bug-catching signal dominates for harder or more variant-prone problems.