Algorithms Playbook
ConceptTime — · Space —7 min read

How to solve a coding interview problem, out loud

A repeatable six-step method for coding interviews: understand, examples, brute force, optimize, code, test. What to say in each phase and how to split 45 minutes.

In short

Interviewers grade how you think as much as the final code. Follow the same steps every time: understand → examples → brute force → optimize → code → test, and say each one out loud.

The 45 minutes, phase by phase

Click each phase to see its goal and what it sounds like on a classic problem: find two numbers in an array that add up to a target.

A 45-minute coding interview, phase by phase

01 · Goal

Understand

Restate the problem and pin down inputs, outputs and edge cases.

What it sounds like (Two Sum)

"So I get an array of integers and a target, and return the indices of two numbers that add up to it. Can there be duplicates? Is there always exactly one answer?"

"What size is the input? Negative numbers?"

Interviewers grade your process as much as the final code. Talking through each phase shows how you think, and lets them help you before you go down the wrong path.

The mistakes that sink good candidates

  • Coding immediately. Five minutes of questions save twenty minutes of rewriting.
  • Silence. If you think quietly, the interviewer can't give you credit or a hint.
  • Skipping the brute force. Saying it first shows you can always deliver something correct, and gives you a baseline to improve.
  • Not testing. Trace one example through your code before saying "done"; find your own bug before they do.

Optimizing = recognising a pattern

Most optimizations remove repeated work using one of a handful of patterns. Learning to spot them is what this playbook is about:

If you see…Try…
"Have I seen this before?" in a loopA hash map or set
A sorted array, pairs or in-place editsTwo pointers
A contiguous subarray or substringSliding window or prefix sums
Sorted data, or "minimum value such that…"Binary search
Trees, graphs, "all combinations"DFS / BFS / backtracking
Overlapping subproblemsDynamic programming

Key takeaways

  • 01Use the same six steps every time and narrate them.
  • 02Ask questions and work examples before writing code.
  • 03State the brute force and its complexity, then optimize.
  • 04Test by tracing an example, and state the final time and space.

Check your understanding

1 of 3

What should you do first when you get a problem?

Related topics