0%
AI-Assisted Coding Interviews: Prompting, Reviewing AI Output, Testing, and Handling the Twist
How AI-Assisted Rounds Work
Prompting the Assistant
Thinking Out Loud
Time Management
Silent Behaviour Changes
A silent behaviour change is a change that alters what code does without anyone intending it and without anything failing. The code still runs, the visible tests still pass and the diff often looks like an improvement. Somewhere, for some input, the output is now different, or an error is now raised where it was not, or a value that used to be left alone is now modified.
Assistants produce silent changes most often when asked to refactor, simplify, tidy, optimise or modernise code. Those requests ask for a different shape with the same behaviour. The assistant is good at producing a different shape and less reliable at preserving every detail of the behaviour, especially details that only matter on unusual inputs.
Why they are silent
Silent changes are silent for three reasons.
First, they usually affect only certain inputs: ties, empty collections, missing fields, negative numbers, mixed case strings. Typical inputs give the same output before and after, so a quick check on a typical example confirms the refactor.
Second, the visible tests often cover only typical inputs. In interview codebases, tests are usually written to show the main behaviour, not every edge. A refactor that preserves the main behaviour passes them all.
Third, the diff looks like it should be equivalent. A loop becomes a one line expression, an if chain becomes a dictionary lookup, a manual sort becomes a built in call. Readers tend to assume that a cleaner version of the same idea does the same thing. The equivalence is often almost true, and almost is where the change hides.
Why they matter in a round
In a round, silent changes matter for two reasons. They are bugs that the interviewer's hidden checks are likely to probe, because the edges they affect are exactly the edges a careful engineer would test. And accepting one is a clear sign that a candidate trusts a refactor without checking it, which is the opposite of the verification the round is looking for.
The flip side is that catching a silent change is one of the strongest signals available. It shows that you read a diff for behaviour, not just shape, and that you know where behaviour hides.
Refactor requests in a round
You might ask an assistant to refactor code during a round for good reasons: to make a function easier to extend before the twist, to remove duplication after a fix or to make code clearer before the debrief. These are all reasonable. The point of this lesson is not to avoid refactors but to review them as behaviour changes until proven otherwise.
A useful mindset is that every refactor makes a claim: this code does exactly what the old code did. Your job is to test that claim, quickly and on the inputs where it is most likely to be false.
A first example in Python
The new version is shorter and reads well. On typical input, it gives the same answer. But if two users share a name, the old version returns the first one and the new version returns the last one, because a later entry in the dictionary comprehension overwrites an earlier one. It also builds a dictionary of every user on every call, which changes the cost from stopping at the first match to always scanning everything. Neither change shows up on tests with unique names.
A first example in TypeScript
This is a very common modernisation. The difference is the empty string: in the old version, a nickname of the empty string is returned as is; in the new version, it is falsy, so the full name is returned instead. Whether that is a bug depends on the rule, but it is a behaviour change either way. The nullish coalescing operator, which only falls back on null and undefined, would have preserved the old behaviour exactly.
A first example in Java
The assistant was asked to simplify and removed the try and catch block as unnecessary noise. Now invalid input throws instead of falling back to the default port. On every valid input, the two versions agree. On the one input the catch existed for, the behaviour is completely different.
A drill for spotting silent changes
Take five functions from a codebase you know, each with at least one edge case handled explicitly. Ask an assistant to refactor each for readability. For each refactor, before running anything, write down which inputs might now behave differently. Then check those inputs on both versions. Most people find at least one silent change in five refactors, and after a few rounds of this drill, they start to see them before running anything.
Silent changes from fixes, not just refactors
Silent changes are not limited to refactors. A fix for one bug can change behaviour somewhere else. An assistant asked to fix a crash on empty input may add a guard that returns early, and the early return skips a log line or a counter update that used to run on every call. An assistant asked to make a comparison case insensitive may lowercase the stored value as well as the compared one, so the original casing is lost for every later reader. The request was narrow, and the change was wider than the request.
When reviewing a fix, ask two questions. Does it fix the reported problem? And what else does it change? The second question is the one that finds silent changes, and it is easy to skip once the first answer is yes.
Silent changes from modernisation
Modernisation requests are a special case worth naming. Replace this loop with a comprehension. Use the newer string formatting. Switch to optional chaining. Use streams instead of a for loop. Each of these swaps a familiar construct for a newer one that is nearly, but not always exactly, equivalent. Optional chaining short circuits on null and undefined, not on other falsy values. A comprehension does not stop at the first match unless written to. A stream with a parallel step does not keep order unless told to. The newer construct is usually better, and the difference is usually small, which is exactly what makes it silent.
Silent changes the interviewer did not plant
Not every silent change in a round is part of the exercise. Sometimes the assistant simply produces one. The interviewer may not even know it is there until you point it out. That is fine. The skill being graded is not whether you find a specific planted bug but whether you review changes for behaviour. Pointing out a change the interviewer did not anticipate, with a clear reason and a quick check, is as strong a signal as finding one they did.
How much to check
Not every refactor deserves a full investigation. Renaming a local variable, extracting a helper with the same body or reordering independent statements carries little risk. Changes that alter control flow, swap data structures, replace a loop with a built in, remove a guard or change how errors are handled carry much more. Spend your checking time in proportion. A quick read is enough for the first kind. The second kind gets the contract review and, if anything looks off, a differential check.
The cost of not checking
Skipping the check saves a minute and occasionally costs much more. A silent change accepted early in a round can make a later step fail for reasons that seem unrelated, such as a twist that depends on tie order or a test that depends on an empty case. By then, the change is buried under other edits and hard to trace. A minute at the time of the refactor is cheaper than ten minutes of debugging later.
A refactor claims the new code does exactly what the old code did. Test that claim on the inputs where it is most likely to fail: ties, empties, missing values, errors and edge values.