Engineering Notes
Home/Algorithms & Coding Interviews/Foundations/The Coding Interview Method
Algorithms & Coding Interviews · Foundations

The Coding Interview Method

Interviewers score how you reach a solution, not only whether you reach one. Learn a six-step method that covers every rubric dimension, a 45-minute time budget, and how to recognize the right pattern from the wording of a problem.

🧮 Algorithms & Coding Interviews● Beginner⏱ 6 min read▶ 3 interactive🛠️ 4 exercises

🎯 What you'll learn

  • What interviewers actually score
  • The six steps: clarify, examples, brute force, optimize, code, test
  • Budgeting a 45-minute round
  • Recognizing patterns from problem wording; communicating and testing

📚 Before you start

A coding interview tests more than whether you can produce a correct function. The interviewer is scoring how you get there: whether you clarify before coding, whether you reason about trade-offs out loud, whether your code is clean, and whether you test it without being asked. A repeatable method makes all of that automatic, so your working memory is free for the actual problem.

The six steps of the method, from clarifying the problem to testing and analysing the solution
The six steps of the method, from clarifying the problem to testing and analysing the solution

1What Interviewers Actually Score

Most companies use a rubric with four or five dimensions. The exact names vary, but they map to the same things:

DimensionWhat they look forWhat loses points
Problem solvingYou find a working approach, then improve it; you explain why it worksJumping to code; getting stuck silently
CodingCorrect, readable code with good names and small helpersOff-by-one errors, copy-pasted branches, cryptic names
CommunicationYou think out loud, take hints well, keep the interviewer in the loopLong silences; arguing with hints
VerificationYou trace an example and test edge cases unprompted"I think it works"
ComplexityYou state time and space complexity correctly and know where the bottleneck isGuessing, or forgetting the space used by recursion

At senior level, the bar on communication and trade-offs rises: you are expected to drive the session, not wait to be led.

2The Six Steps

  1. Clarify. Restate the problem in your own words. Ask about input size, value ranges, duplicates, empty input, sorted or not, and the expected output for ties or "not found".
  2. Examples. Write one normal example and one or two edge cases before thinking about an algorithm. Agree on the expected outputs with the interviewer.
  3. Brute force. State the simplest correct approach and its complexity in one or two sentences. You usually don't code it, but saying it proves you understand the problem and gives you a baseline.
  4. Optimize. Find the bottleneck in the brute force (the repeated work) and pick a pattern that removes it: a hash map instead of a nested loop, two pointers on sorted data, a heap for top-k, memoization for overlapping subproblems.
  5. Code. Write the optimized solution cleanly. Talk while you write, but keep sentences short. Use helper functions for distinct steps.
  6. Test and analyse. Trace your first example through the code line by line, then run the edge cases. Finish by stating time and space complexity.
text
"Let me restate: given an array of integers and a target, return the indices
of two numbers that sum to the target. Can there be duplicates? Is there always
exactly one answer? Can I use the same element twice?  ... OK.

Brute force: check every pair, O(n²) time, O(1) space.
The repeated work is searching for the complement. A hash map from value to
index makes that lookup O(1), so one pass gives O(n) time and O(n) space."

3Time Budget for a 45-Minute Round

MinutesStep
0–5Clarify and agree on examples
5–10Brute force, then the optimized idea; get a nod before coding
10–30Code
30–38Trace, test, fix bugs
38–45Complexity, follow-up questions, your questions

If you are still choosing an approach at minute 15, say so and ask a narrowing question. Interviewers would rather give a small hint early than watch you run out of time.

4Recognizing the Pattern From the Problem Statement

Most interview problems are variations of about twenty patterns. Certain phrases are strong signals:

Signal in the problemPattern to try first
"sorted array", "pair/triplet with sum"Two pointers, binary search
"contiguous subarray/substring", "longest/shortest window"Sliding window
"subarray sum equals k", "range sum queries"Prefix sums + hash map
"next greater/smaller element", "histogram"Monotonic stack
"top k", "k-th largest", "merge k sorted"Heap
"all combinations/permutations/subsets"Backtracking
"shortest path in unweighted graph/grid", "minimum steps"BFS
"dependencies", "ordering with prerequisites"Topological sort
"connected groups", "merge accounts", "are x and y connected"Union-find or DFS
"number of ways", "min/max cost", "can you reach" with choicesDynamic programming
"minimum value such that X is possible"Binary search on the answer
"intervals", "meetings", "overlap"Sort by start, then sweep

5Communicating While You Code

  • Narrate intent, not syntax. Say "now I shrink the window until it's valid again", not "while left less than…".
  • Flag shortcuts. "I'll assume the input is valid here; in production I'd validate it." This shows judgment without wasting time.
  • When stuck, think out loud. Say what you've ruled out and why. That gives the interviewer something to hint against.
  • Take hints gracefully. Repeat the hint back, connect it to your approach, and move on. Hints are normal; ignoring them is a red flag.

6Testing Like a Senior Engineer

After coding, trace one example by hand with concrete variable values. Then check this list:

  • empty input, single element, two elements
  • all elements equal, already sorted, reverse sorted
  • negative numbers and zero, very large values (overflow in C#/Java int)
  • the answer at the very first or very last position
  • no valid answer

When you find a bug, say what was wrong before fixing it: "the window shrinks one step too late because I check after moving left".

⚠️ Common Pitfalls

  1. Coding before agreeing on the approach. You may solve the wrong problem or an over-complicated version.
  2. Silence while thinking. Interviewers can't score what they can't hear.
  3. Skipping the brute force. Without a baseline, your optimization has nothing to be compared against.
  4. Testing by rereading. Rereading finds typos; tracing concrete values finds logic bugs.
  5. Forgetting space complexity of recursion (the call stack) and of output buffers.
  6. Over-engineering: classes and interfaces where one clear function is expected.

📋 Quick Reference

text
Clarify → Examples → Brute force (+ complexity) → Optimize (find repeated work)
→ Code (narrate intent) → Trace + edge cases → Time & space

Edge cases: [] · [x] · duplicates · negatives/zero · sorted/reversed · no answer
45 min: 5 clarify · 5 plan · 20 code · 8 test · 7 follow-ups

🧠 Key takeaways

  • Interviewers score problem solving, coding, communication, verification and complexity, not only correctness.
  • Follow clarify → examples → brute force → optimize → code → test, out loud.
  • Budget the 45 minutes; get agreement on the approach before you code.
  • Map problem wording to a pattern; test by tracing concrete values and edge cases.

🛠️ Practice exercises

Each exercise is a file in this topic folder. Code exercises are self-checking: run them and make the checks pass.

#1
algo_coding_interview_method_exercise_1.py
#2
algo_coding_interview_method_exercise_2.py

✅ Check yourself

Answer the questions — feedback is instant.

1. What should you do right after hearing the problem?
Clarify first.
2. Why state the brute force even if you won't code it?
Baseline + shared understanding.
3. 'Longest substring with at most k distinct characters' suggests…
Contiguous + shrinkable condition.
4. Best way to test your code in an interview?
Concrete values find logic bugs.