The Edge Case Instinct: Testing Your Own Code Before the Interviewer Has To
There's a moment near the end of most coding interviews that shapes the writeup more than candidates realize, and it's the one right after "I think that's done." In the interviews I've conducted, some candidates looked up at me and waited. Others grabbed an ugly little input and started walking their own code through it before I said a word. The two groups often had very similar code on the screen, and they got noticeably different writeups, because the second group was demonstrating the habit this article is about: testing your own work before someone else has to. What follows is a list of inputs to check, most of which take seconds, and the mechanics of running those checks in a room with no debugger.
Why a bug you catch yourself grades differently
Here is a mildly uncomfortable fact about how these interviews get built: your interviewer usually knows the breaking input before you walk in. When I picked a problem for an interview, I picked it partly because it had a trap in it (duplicates that wreck the obvious window, an empty array that crashes the first draft), and I generally had that input ready as a follow-up. A real part of what the interview is testing is whether you find the trap before I hand it to you.
That's why the same bug can produce two very different writeups. "Wrote the solution, I supplied the empty-input case, candidate fixed it quickly" is fine. Nobody reasonable expects a flawless first draft, and a fast recovery is real signal. But "wrote the solution, proactively traced an input with duplicates, caught the off-by-one themselves, fixed it before I said anything" sounds like watching someone review their own pull request, which is a lot closer to the actual job than puzzle-solving is. In the debriefs I've sat in, that distinction came up constantly, and it usually got discussed as a judgment question (does this person check their work before calling it done) rather than a correctness one. Practices vary between companies, so I'll hedge anything that sounds like a universal law, but I can't remember a debrief where a self-caught bug counted against someone.
The good news is that the instinct behind it looks like magic from the outside and is mostly a checklist on the inside, the same way pattern triggers are. You don't need to invent adversarial inputs from first principles with the clock running; you need a short list of the usual suspects and a habit of checking them. Here's the list I'd start with.
Empty and single-element inputs
The cheapest checks in the catalog, and the ones that catch the most first drafts. The empty input finds every loop that assumes it runs at least once, every max initialized from the first element, every division by length. The single element is sneakier: it breaks anything built on two pointers or neighbor comparisons, because there's nothing to compare against, and it's a classic place for a window or a recursion base case to be subtly wrong. If your function takes a collection, these two inputs are worth ten seconds every single time.
Duplicates
Duplicates violate assumptions you didn't notice you were making. A map keyed on value collapses entries the problem needed counted. Binary search lands on some occurrence when the problem wanted the first one. Two-pointer logic that advances on strict inequality stalls or skips. The 'abba' trace from Talk While You Code lives in this category: it's the input that punishes a sliding window that never guards against the left pointer moving backward. If your approach involves a set, a map, or a sorted anything, duplicates go on the trace list.
Sorted, reverse-sorted, and all identical
Already-ordered input is a degenerate case for a surprising number of approaches: greedy strategies that depend on some mix of rises and falls, anything hunting for a peak or a pivot that isn't there, divide-and-conquer that splits badly on ordered data. Reverse-sorted is the standard worst case for the same family. All-identical elements combine this category with duplicates, and they specifically stress every strict < that maybe should have been a <=. These three usually need a moment of thought rather than a full trace: read your comparisons and ask what happens when they're never true, or always true.
Want to practice this on a real question, with feedback attached?
Negatives and zero
Sliding windows over sums are the famous casualty here, because window-shrinking logic tends to assume that adding an element grows the sum and removing one shrinks it, and negative numbers break both assumptions at once. (When a problem's constraints explicitly allow negatives, that is often the entire reason they do.) Zero breaks products, division, and any check where the language treats 0 as falsy and your code ends up treating "missing" and "present but zero" as the same thing. Modulo on negative numbers behaves differently across languages, so say which behavior you're assuming out loud in the room rather than trusting your memory.
Boundaries
First index, last index, and k when it equals the size of the input. Targets smaller than every element and larger than every element. A window the size of the whole array. Inclusive versus exclusive bounds on every range you touch, and the midpoint arithmetic in anything binary-search shaped. Off-by-one bugs live almost exclusively at these edges, which is what makes the fixed checking order I'll describe below so effective: there are only a few places they can hide, and you know where all of them are.
The input that breaks your complexity claim
This one is a thought experiment rather than a trace. Take the largest n the constraints allow (they're printed in the problem for a reason) and reread your code asking what happens at that size. String concatenation inside a loop that makes your "linear" solution quadratic. A slice, or a contains on a list, doing the same thing less visibly. Recursion deep enough to blow the stack. The sort inside a loop you stopped noticing three edits ago. In the interviews I've conducted, this was my favorite follow-up ("would this still be okay if the input were ten million entries?"), and the candidates who got there first, out loud, had effectively taken the question away from me.
Running the test when there is no run button
Knowing what to test only pays off if you can execute a test in the room, and the mechanics matter more than people expect.
Build one small adversarial example, and never use the prompt's happy path. The example in the problem statement is the input you stared at while writing the code, so your solution almost always handles it, which is why tracing it proves nothing. Three to five elements engineered from the catalog (a duplicate and a negative, say, if your approach is exposed to either) will find more in ninety seconds than the given example finds in five minutes.
Trace it in writing, while narrating. Put the variable names down as columns (left, right, the running sum, the map) and update them line by line as you step through, saying what you're doing as you go. The in-your-head trace feels faster and is dramatically less reliable, and it produces nothing your interviewer can grade, for the same reason silent solving doesn't. A written trace catches the bug and shows your work at the same time.
Check your boundaries in a fixed order, every time. Mine: both ends of every loop, then every index expression at its extreme values, then initial values, then every return path (including the one where the function falls out the bottom). The specific order matters less than having one, because a consistent order turns "stare at the code and hope" into a preflight list you can run in under a minute, even with your adrenaline up.
The format changes what running a test means. In a shared editor with execution, run early and run often; the anti-pattern is 25 minutes of typing followed by one giant run at the end, where any failure becomes archaeology. And when a run does go red, debug out loud, because watching you localize a failure is some of the best material an interview produces (narrating your way through the wall is the same skill I wrote about in the hint economy piece). On a whiteboard, or in a doc with no execution, the written trace is the run, and it deserves the seriousness you'd give a failing test: same adversarial input, same line-by-line honesty, no skipping steps in the middle because you're confident about the middle.
Training the instinct
I spend a decent chunk of my free time backpacking, and there's a ritual before any long trip called the shakedown. You pitch the tent in the yard, run the stove in the driveway, load the pack and make sure it sits on your back just right, partly because the checks take a few minutes and a failure three days from the trailhead is a real problem. Nobody experienced skips it, and none of them expect the gear to fail, either; the check takes so little time that you run it regardless. Tracing an adversarial input before you say "done" is that same shakedown, and the interview is the trip.
The training loop is short. On every practice problem, before you check the answer or submit, write down the three inputs from the catalog that scare you most for this particular approach, then fully trace one of them. When a hidden test or a run still catches something your three didn't, add that kind of input to a personal miss list, because your own misses make a better catalog than mine. Within a few weeks the generating step starts happening while you're still writing the code, which is the instinct arriving: edge cases stop being a phase at the end and start being a voice in your ear at the moment you write the loop. The drill fits into the daily coding block of a structured prep plan without displacing your full-problem practice.
None of this needs anything paid. An editor and a scratch test file give you real execution for free, and a paper trace needs nothing but a pencil. If you want interview-shaped practice where the habit gets tested honestly, we built Preppable's coding interviews on real code execution, so the empty-array case you forgot genuinely fails in front of you instead of an AI politely guessing that it might.
One last thing: no catalog is complete, and no interviewer I respect expects a bug-free first draft. In my experience candidates get burned by skipping the check far more often than by failing it. So pick your ugly input, write the trace out, and let your interviewer watch you find the bug before they have to.
// Practice this for real
Put this into practice on a real coding question
Preppable runs the question end to end, watches how you work through it, and tells you what an interviewer would have written down. Free to start, no credit card.
Not ready yet? Get new posts by email. We usually publish a couple times a week.
Unsubscribe any time. See our Privacy Policy.
About the author
Jordan Beland
Co-founder & CTO, Preppable
Principal architect with 10+ years designing and scaling production-grade Azure systems, with deep expertise in distributed systems and developer platforms. Has run countless interview loops from the interviewer side across coding, system design, and behavioral rounds, and sat in the debriefs afterward.
Connect on LinkedIn