What the interviewer is listening for
After this: Check your answer against the habits interviewers listen for, and test it with small checks of your own.
On this page · 4 sections · 3 checks
After an interview, many interviewers write notes. Notes like that usually say more than "the code was right". They tend to describe what the interviewer saw: did the person ask questions, did they explain, did they test? This lesson turns the four habits of this tutorial into a checklist of what interviewers often listen for, and adds one more way to test.
The checklist
Interviewers often listen for these habits. They are listed in the order they come up in an answer:
- You restated the problem and asked questions before writing code.
- You gave a correct slow answer before a fast one, or at least said what it would be.
- You named the tool and why: "a lookup by value, so a hash map".
- You said the cost without being asked, time and extra memory, in words.
- You tested with your own small inputs: the edge cases, and a dry run.
- You took a hint and used it, saying how it fits.
- You kept talking when stuck: what you know and what you are trying.
None of these is about knowing the answer in advance. They are all habits, and habits can be practised.
Small tests you write yourself
When you can run your code, small tests do the job of a dry run faster. A test calls your function on an input whose right answer you already know, and says whether the answer matches. Python has a one-line form, assert, which stops the program when a condition is false; Java has assert too, but it is switched off unless the program is started with java -ea. Here both languages use a small check function instead, which prints ok or FAIL and keeps going.
The code below holds two sum with a bug: it stores the number before it checks for the partner. Three tests run under it. Run it and read which test fails.
The first two tests pass, which is why this bug can go unnoticed. The duplicates test fails: [3, 3] with target 6 gives [0, 0], because the first 3 is stored and then found as its own partner. Fix it by moving the store line below the lookup, so that the check comes first, and run it again. All three lines should say ok, and the line under the output will say it matches.
In an interview, say the tests out loud even when you cannot run them: "for [3, 3] and 6, I expect [0, 1]". It shows the interviewer that you check your own work.
Check yourself
Which of these hurts an interview the most?
You are stuck on two sum, and the interviewer says: "What if you could look up a number quickly?" What do you do next?
You submit a solution to a practice site and it says "accepted". You had said it was O(n) time. Does "accepted" prove that cost?
Honesty notes
- Check an answer against seven habits interviewers often listen for, from restating the problem to talking when stuck.
- Write small tests that print ok or FAIL, and use one to find two sum's store-before-check bug on [3, 3].
- Use a hint by saying how it fits, then acting on it.
- Say why accepted on a judge site does not prove a cost claim, and why practice there is still needed.