← Create New Paste

Test Your Own Code Before You Say "Done": Edge Cases and Dry Runs in Coding Interviews

3 views
Many candidates lose points in a coding interview not because their algorithm is wrong, but because they announce "I'm done" and the interviewer immediately finds a bug with an empty input. Testing your own solution is a skill interviewers explicitly score, usually under a heading like "verification" or "code quality". Here is a simple routine you can use in the last five to eight minutes of any coding round. 1. List edge cases before you write code Right after you agree on an approach, spend thirty seconds saying the edge cases out loud and writing them as comments at the top of your editor. A short checklist covers most problems: - Empty input: an empty array, empty string, or null tree. - Single element: one number, one character, one node. - Duplicates: repeated values, all elements equal. - Boundaries: negative numbers, zero, very large values that might overflow. - Already-solved input: an array that is already sorted, a string that is already a palindrome. - Invalid or unexpected input, if the interviewer says it can happen. Writing these first has two benefits. It shows the interviewer you think about correctness early, and it gives you a ready-made test list when you finish. 2. Dry run with a small, normal example When the code is written, do not jump to edge cases yet. Pick a small but typical input, for example an array of four or five numbers, and trace your code line by line. Track the important variables in a little table: index, pointer positions, running sum, the contents of a map or stack. Say the values out loud as they change. This is where most real bugs appear: an off-by-one loop bound, a pointer that moves in the wrong branch, or a variable that is never reset. Fixing a bug you found yourself looks far better than having the interviewer point it out. 3. Run the edge cases from your list Now go back to the comments you wrote in step one and check each case quickly. You do not need a full trace for every one. For an empty array, simply ask: does the loop run zero times, and is the return value correct? For a single element, does the code avoid reading index i + 1? Tick each case off as you go. 4. State the complexity and any trade-offs Finish by stating time and space complexity in one sentence and mention one alternative you considered. For example: "This is O(n) time and O(n) space because of the hash map; if memory were tight, sorting first would give O(n log n) time with O(1) extra space." 5. Practice the routine until it is automatic Under pressure, people skip steps they have not practiced. During mock interviews, force yourself to follow the same order every time: edge cases, code, dry run, edge-case check, complexity. After a couple of weeks it becomes a habit, and interviewers notice the calm, methodical finish. A small tool tip If you want support in the moment, Linkjob AI (https://linkjob.ai) gives real-time help during live job interviews and technical interviews, including reminders about edge cases and complexity while you are solving a problem. It works best when you already have a routine like the one above, so treat it as a safety net rather than a replacement for practice. The main idea is simple: the interview is not over when the code compiles in your head. It is over when you have shown, step by step, that it actually works.
Created Nov 17, 2026 03:42 Expires Nov 17, 2027 03:42