Interviewers Grade the Thinking, Not Just the Answer

Your first coding interview question will probably not be hard. It will be small — ten lines, one idea — and that is exactly why it is hard to prepare for. There is nowhere to hide a shaky process behind a clever answer, because the interviewer is watching how you get there. They grade four moments: the questions you ask before you start, the plan you say out loud, the trade-off you choose when you improve the answer, and the edge cases you test at the end. The final code is only one part of the score.

That is good news: the first question is a routine you can practise, not a talent test. This article works through Two Sum the way an interviewer grades it, so you can practise the routine instead of memorising an answer.

The Question: Two Sum

Given a list of numbers and a target, return the indices of the two numbers that add up to the target. Each input has exactly one answer, and you may not use the same element twice. With [2, 7, 11, 15] and target 9, the answer is [0, 1], because 2 + 7 = 9.

Before you write anything, ask the clarifying question out loud: do the numbers come sorted, can they be negative, and do I return the indices or the numbers themselves? For this question the answers are: unsorted, yes they can be negative, and return the indices. One question asked early saves you from solving the wrong problem — and interviewers notice when you ask it.

Start With the Slow Answer on Purpose

Say your plan before you type it: "I will check every pair of numbers until I find the two that add to the target." That is brute force — two loops, every pair, stop at the match. It runs in O(n²) time, which is slow, and that is fine. A slow answer that works beats a fast answer you cannot explain, and it proves you understand the problem before you optimise it.

Say the cost out loud too: "For n numbers there are about n² pairs, so this is O(n²) time and O(1) extra space." Interviewers listen for that sentence. It tells them you think about scale, and it sets up the improvement — now you have something concrete to beat.

Try It: Two Solutions, Three Tests

Here is both solutions in one file, with three tests. Paste it into the browser editor and run it — then change the test numbers and run it again.

# two_sum.py — brute force first, then the one-pass hash map def two_sum_brute(nums, target): for i in range(len(nums)): for j in range(i + 1, len(nums)): if nums[i] + nums[j] == target: return [i, j] return [] def two_sum(nums, target): seen = {} for i, num in enumerate(nums): need = target - num if need in seen: return [seen[need], i] seen[num] = i return [] tests = [ ([2, 7, 11, 15], 9, [0, 1]), ([3, 2, 4], 6, [1, 2]), ([3, 3], 6, [0, 1]),
] for nums, target, expected in tests: got = two_sum(nums, target) status = "PASS" if got == expected else "FAIL" print(f"{status}: {nums} target {target} -> {got} (expected {expected})") print("Brute force:", two_sum_brute([2, 7, 11, 15], 9))
print("No pair:", two_sum([1, 2, 3], 10))

All three tests pass. The third one is the trap: [3, 3] with target 6 must return [0, 1], two different positions holding the same value. That only works because the code checks whether the complement is already in seen before storing the current number — if it stored first, 3 would match itself and return [0, 0]. Writing edge cases as tests is how you prove you thought of them.

The One-Pass Trick, in Plain Words

The fast solution comes from one question: standing at each number, what would I need to know to finish right now? At 7, with target 9, you need to know whether you have already seen 2. So store every number you pass, with its index, in a hash map — then each step is a single lookup instead of a scan. Walk through [2, 7, 11, 15]: at 2, the complement 7 is not stored yet, so store 2 at index 0. At 7, the complement 2 is stored at index 0 — done, return [0, 1].

The trade-off is honest: O(n) time instead of O(n²), paid for with O(n) extra space for the map. Say that sentence in the interview. "Faster, but it uses memory" is the kind of trade-off interviewers want to hear you name, not hide.

What Interviewers Listen For

Put the routine together and it sounds like this. Clarify first: one question about the input, said out loud. Plan next: "brute force first, then improve" — the talk-through habit applied to a real question. Code the slow version, run it, then improve it and name the trade-off. Finally, test the edges: duplicates like [3, 3], a pair at the end of the list, and a list with no pair at all, which returns an empty list. Each moment is a point on the score sheet, and none of them needs you to be a genius — they need you to be deliberate.

If you freeze, narrate the freeze: "I know the slow version; let me get that working and think about the faster one while I test it." Interviewers would rather help a thinking candidate than watch a silent one, and a working slow answer gives you something to talk about while your brain catches up.

Practise Like It Is Real

One question a day, timed at 25 minutes, re-solved from a blank file until it feels easy — that is the whole practice plan. Get your next question from the interview practice page, where you pick a language and a difficulty and get a challenge to solve in the editor. Save each finished solution as a snippet with a one-line note — "hash map, look up the complement" — so your portfolio records questions you can actually solve.

Then prove you understand it: open the Teach-Back Apprentice and teach the hash-map idea in your own words. If the Apprentice solves a new problem from your teaching alone, you own the idea; if it fails, the failure names the exact gap. And try Two Sum in a second language on the Two Sum practice page — translating a solution you understand is the fastest way to learn a new language.

When the Free Plan Runs Out Mid-Prep

Interview prep burns executions fast — one timed question a day, run after every step, plus re-solves from scratch. Free gives you 20 executions a day, 10 AI requests a day, 10 saved snippets, 3 private snippets, and 3 collaborators per snippet. That fits one careful question a day. Practising two or three daily before an interview is the upgrade moment: Pro is $9/month or $69/year — unlimited saved snippets and executions, 100 AI requests a day, 10 collaborators per snippet, unlimited private snippets, and GitHub integration, which Free does not include. Team ($19/user/month, or $15/user/month billed annually) covers a class or study group preparing together — see the pricing page.

Your next step is today: run both solutions above, save the hash-map version as a snippet called "two-sum", and set a 25-minute timer tomorrow to solve it again from a blank file. Then write your first test for it the way the first-test habit teaches — normal, duplicate, and no-pair cases — because the test is what proves the solution, in practice and in the interview.