In a coding interview, getting the right answer is only half of it. The interviewer is just as interested in how you get there. If you solve the problem in complete silence, they have no idea what you're thinking, and they can't help you when you get stuck. Thinking out loud turns the interview into a conversation, and that almost always works in your favour.

Here's roughly what to say at each stage.

Make sure you understand the problem

Before writing anything, put the problem into your own words and ask a few questions. Something like:

Just so I'm sure I've got it, I need to return the positions of two numbers that add up to the target, right? Can the array have negative numbers or duplicates? And what should I return if there's no answer?

It might feel like you're wasting time, but you're not. It shows you're careful, and the answers often change what the best solution looks like.

Try a small example by hand

Work through a quick example out loud, and think about an awkward case or two.

Let's take 2, 7, 11 and 15 with a target of 9. Two plus seven is nine, so the answer would be positions 0 and 1. I should also think about an empty array, or one with a single number.

Say the simple solution first

Even if you know it's slow, mention the obvious approach.

The straightforward way is to check every pair. That works, but it's O(n²). Let me see if I can do better.

This gives you a safe fallback, and it shows you understand the trade-offs before you start optimising.

Talk through the better idea before you code it

Explain your improved approach first, then check in.

For each number, what I really need to know is whether its partner, the target minus that number, has already appeared. A HashMap can tell me that instantly. So I can do it in one pass, O(n) time with O(n) extra space. Does that sound reasonable before I start writing it?

That last question is more powerful than it looks. If you're heading the wrong way, a lot of interviewers will gently say so.

Narrate as you write

You don't need to read out every keyword. Just explain what each chunk is doing.

First I'll set up the map from value to index. Then I go through the array, and for each number I look up its partner. I check the map before adding the current number, so I never pair a number with itself.

Clear variable names make this much easier, for you and for them.

Test it out loud

Don't just say "done". Walk through your example and an edge case line by line.

With 2, 7, 11, 15: at index 1 we're looking for 2, it's in the map at index 0, so we return 0 and 1. Good. With 3, 3 and a target of 6, the second 3 finds the first one. That works too.

If you spot a bug, say so calmly and fix it. Catching your own mistakes is a good sign, not a bad one.

Finish with the complexity

This runs in O(n) time and uses O(n) extra space for the map. If the array were already sorted, two pointers would get it down to O(1) space.

When you get stuck

Going quiet is the worst thing you can do. Say what you're thinking, even if it's half-formed.

I'm stuck on how to avoid checking every pair. Let me think about what I'd need to remember as I go.

One option is sorting first, but that's O(n log n). Would that be acceptable here?

And if you're properly stuck, just ask: "Could I get a small hint?" Asking for a hint is far better than freezing.

Mistakes people often make

Jumping straight into code without clarifying the problem. Going silent for long stretches. Talking so much that you miss the interviewer's hint. And announcing you're finished without testing anything.

Getting comfortable with it

It feels strange at first, talking to yourself while you code. The only way past that is practice. Pick a problem, set a 30-minute timer, and solve it out loud, either with a friend or while recording yourself. After a handful of sessions it starts to feel normal.

You can try it right now with our Java coding problems. Two Sum is a good one to start with.