Data structures & algorithms · Interview craft
The six-step method
Clarify, examples, brute force, optimise, code, test. This page runs one real problem — Two Sum — all the way through, showing what you say and what you write at every step.
Run the interview step by step →01 The idea
A method beats a memory
An interview is not a test of whether you have seen the problem before. It is thirty-five minutes of someone watching how you behave when you have not. Two candidates who know exactly the same things get different results, and the difference is almost never the algorithm. It is that one of them has an order to fall back on and the other has only the problem.
The order does not change with the question. Clarify, examples, brute force, optimise, code, test. Six steps, always the same six, always in that sequence. Because you never have to invent what to do next, you never go quiet — and going quiet is the thing the interviewer actually writes down.
02 One problem, all six steps
Two Sum, said and written
The problem: given an array of integers and a target, return the indices of the two numbers that add up to the target. Work it on [2, 7, 5, 3] with target 8. Each step below shows the words you say and the thing that lands on the board. The clock is a thirty-five minute round.
target: int, exactly one answer
return two indices, i != j
n <= 100000 → O(n^2) is too slow
edges: [] [5] [4,4] t=8 [-3,1] t=-2 [3,3,3] t=6
overflow n/a (Python ints) · no pair
for j in i+1..n-1:
if nums[i]+nums[j]==target: return [i,j]
6 pairs = n(n-1)/2 · O(n^2) time, O(1) space
lookup → hash map
seen = {value → index} · O(n) time, O(n) space
seen = {}
for i, v in enumerate(nums):
need = target - v
if need in seen:
return [seen[need], i]
seen[v] = i
return []
i=1 v=7 need=1 miss seen{2:0, 7:1}
i=2 v=5 need=3 miss seen{2:0, 7:1, 5:2}
i=3 v=3 need=5 HIT → [2, 3] matches step 2
edges: []→[] [5]→[] [4,4]→[0,1] [-3,1]→[0,1] [3,3,3]→[0,1]
Nothing above needed a clever idea. The hash map is one line, and it came out of step 4 by naming the repeated work rather than by recognising the problem. Everything else in those twenty-nine minutes was order — and order is the part you can rehearse.
03 Mechanics
The same six steps, done badly
Students do not lose marks in the left-hand column. They lose them in the right-hand one, usually without noticing. Read it as a list of the things you are about to do in your next mock.
| Step | Done well | Done badly |
|---|---|---|
| 1 Clarify | Four to six questions in ninety seconds, and the answers written down as a constraint block. | "OK, I'll start." You find out that duplicates are allowed at minute twelve, from the interviewer. |
| 2 Examples | One case worked by hand with the expected output written, then the edge list said out loud. | You reuse the interviewer's example and never write down what the answer should be, so there is nothing to test against. |
| 3 Brute force | Stated in three lines with its complexity, offered as a baseline the interviewer can accept or skip. | Skipped because it "feels too easy" — leaving an empty board when the clever idea does not arrive. |
| 4 Optimise | Name the repeated work, then name the structure that removes it. Say which resource you are spending. | Guessing algorithm names — "binary search? two pointers? DP?" — until one sticks or the time runs out. |
| 5 Code | One sentence of reason per line. No gap longer than a few seconds. | Head down, typing, four minutes of silence, then "done". |
| 6 Test | Dry-run your own example, then the edge list, then state the complexity unprompted. | "I think that's it." The interviewer finds the off-by-one instead of you. |
05 Cheat sheet
The six steps on one card
| Step | The sentence that starts it | Clock (of 35) |
|---|---|---|
| 1 Clarify | "Before I start, can I check a few things?" — sorted, negatives, duplicates, size, what to return, what if there is no answer. | 0–3 min |
| 2 Examples | "Let me work a small case by hand." — then the six edge cases, out loud. | 3–7 min |
| 3 Brute force | "The obvious solution is… that's O(n²) time and O(1) space." | 7–11 min |
| 4 Optimise | "The repeated work is… so a hash map removes it. I'm trading space for time." | 11–16 min |
| 5 Code | One sentence of reason per line, spoken while you type. | 16–22 min |
| 6 Test | "Let me dry-run this." — your example, then the edges, then the final complexity. | 22–29 min |
06 Where & why
When to run all six, and when to compress
The full method spends about sixteen minutes before the first line of code — steps 1 to 4 on the clock above. That is a defensible spend in a thirty-five or forty-five minute round and the wrong spend in a twenty-minute screen with three short questions. What never gets cut, in any format, is step 1 and step 6.
Run all six when…
Compress it when…
| Situation | Better choice | Why |
|---|---|---|
| A twenty-minute screen with three short questions | Steps 1 and 2, then code and test | There is rarely an optimisation to find, so the marks that are left sit in clarifying the input and testing the output. |
| The interviewer says "we're short on time, just code it" | One sentence of approach, then code | An explicit instruction outranks the method. Ignoring what you were just asked reads worse than skipping four steps. |
| An automated online round with hidden test cases | Steps 2 and 6, wrapped around the code | Nothing you say is recorded. The edge list and the dry run are the only two things that can still earn you marks. |
| You already know the optimal solution cold | Still give the baseline one line | Jumping straight to the memorised answer reads as rehearsed. One line of brute force shows you could have derived it. |
07 Interview questions
Say these out loud
These are asked in almost every round, and the first one is asked in words very close to these. Rehearse the answers until they are twenty seconds each.
Walk me through how you approach a problem you have never seen before.
What does "can you do better?" actually mean?
What are you doing in the first two minutes?
What if brute force is all you can come up with?
Five minutes in you realise your approach is wrong. What do you do?
Do you code the brute force, or go straight to the optimal solution?
How do you stop yourself going silent?
Which edge cases do you check, every time?
Can you ask for a hint?
How do you finish?
In your Two Sum code, why insert into the map after the check and not before?
08 Practice problems
Drills, not puzzles
These are rehearsals for the method, so write the words down. Say them to a wall, a friend or a recording — the point is that the sentences exist before the interview does.