
Minute one: say the problem back
Restate the problem in your own words and wait for a yes. It feels slow. It is the cheapest way to find out you misread the question, and interviewers count it in your favor.
Minute two: ask about the inputs
- How large can the input get?
- Can it be empty? Can it contain duplicates or negative numbers?
- Is it sorted? Does the order of the output matter?
- What should happen with invalid input?
Minute three: one example by hand
Take a small input and walk through it step by step, out loud. You will usually notice the pattern you need while doing it. If the interviewer gave an example, make a second one of your own with an awkward case in it.
Minutes four and five: the simple solution first
Say the brute-force approach and what it costs in time and memory, even if you already see something better. It proves you have a working answer, and it gives you a baseline to improve. Then say what you would change and why.
While you write
- Keep talking. Silence looks the same whether you are stuck or thinking.
- Name your variables properly. It is free and it reads as care.
- When you finish, run your example through the code line by line before saying you are done.
When you are stuck
Say what you are weighing: "A map would make lookups fast, but then I lose the order. Let me think about whether I need the order." That sentence often gets you a hint, and a hint taken well is not a failure.