Say your test cases out loud

In an interview, writing the code is half the job. The other half is showing it works. Before you run anything, say your test cases out loud: "a normal input, then the edge cases."

Use the same checklist every time:

  • empty: [], "", {}
  • one item: [5]
  • duplicates: [2, 2, 2]
  • negatives and zero: [-3, 0]
  • huge: a million items, or a very big number
  • unicode: "café", "日本", emoji

Most bugs live in these cases, not in the normal one. Interviewers notice when you find a bug yourself before they point it out.

The program runs second_largest on each case from the checklist. Run it. One case gives an answer you might not expect. Decide what it should return, then fix the function.