Skip to main content

Coding Interview Strategy

A reliable process matters more than memorised solutions.

The 7-step framework​

  1. Clarify: restate the problem; ask about input size, ranges, duplicates, empty input, and expected output.
  2. Examples: work through a small example and an edge case by hand.
  3. Brute force: state the simplest solution and its complexity out loud.
  4. Optimise: look for the bottleneck; apply a pattern or data structure.
  5. Plan: describe the approach before writing code; get agreement.
  6. Code: write clean code with meaningful names; talk while you type.
  7. Test: trace an example, then edge cases; state final time and space complexity.

Pattern recognition​

Signal in the problemTry
Sorted array, find pair or targetTwo pointers, binary search
Contiguous subarray or substringSliding window, prefix sums
"Top K", "kth largest"Heap
Need fast lookup or countingHash map or set
Next greater / matching bracketsStack (monotonic stack)
Shortest path in unweighted graph or gridBFS
All combinations, permutations, subsetsBacktracking
Overlapping subproblems, optimal substructureDynamic programming
Tree traversalsDFS recursion, BFS with a queue

Review the basics: Arrays, Hash tables, Recursion, Searching and sorting.

When you are stuck​

  • Say what you have tried and what is blocking you; ask a targeted question.
  • Simplify: solve a smaller version or a special case first.
  • Draw it. Many problems become clear on paper.
  • Never stay silent for more than a minute.

Communication template​

"My understanding is ... Is that right?"
"A brute force approach is ..., which is O(n^2). We can do better by ..."
"I will use a hash map to ..., giving O(n) time and O(n) space."
"Let me trace this with the example ..."

Common mistakes​

  • Jumping into code before agreeing on an approach.
  • Ignoring edge cases (empty input, single element, duplicates, negatives).
  • Not testing the solution.
  • Over-engineering: write the simplest correct solution first.