python_coding / 19 · interview strategy lesson 19 / 19

Coding interview strategy: how to think

Most candidates fail not because they don't know algorithms, but because they don't have a repeatable process. This lesson is the "how to think"; files 01–18 are the "what to code".

Why this matters

Candidates read the prompt, freeze, and either blurt the first idea or sit silent. The interviewer is grading a signal you can fully control: "can this person take an ambiguous problem and drive it to a working, analyzed solution while thinking out loud?" That signal is a process, and a process can be rehearsed until it's automatic. This lesson is the navigation hub of the series: a framework, a way to read target complexity off the constraints, a pattern map pointing at every other lesson, then communication, common mistakes, edge cases, and a study plan.

(1) The framework — UMPIRE

A named sequence so you never freeze. Say each step out loud.

  1. U — Understand. Restate the problem in your own words. Ask clarifying questions: input types/ranges? sorted? duplicates allowed? negative values? empty input? in-place or new output? one answer or all? what to return on ties / no-answer? Never start coding until you can state the contract precisely.
  2. M — Match. What category is this? (See the pattern map below.) "Sorted + pair" smells like two pointers; "contiguous subarray" smells like sliding window; "all combinations" smells like backtracking. Matching narrows the search space of techniques.
  3. P — Plan. Walk a concrete example by hand. State a brute-force approach first (it proves you understand the problem and gives a correctness baseline), then its complexity, then propose the optimization. Get the interviewer to nod before you type.
  4. I — Implement. Code the planned approach cleanly. Narrate as you go. Use good names. Don't prematurely optimize syntax; correctness first.
  5. R — Review. Re-read your code as if it were someone else's. Trace the example through it line by line. Check the edge cases you surfaced in step U.
  6. E — Evaluate. State final time and space complexity. Mention trade-offs and what you'd change with different constraints (e.g. "if n were 1e9 I'd...").
The golden rule
Always get a brute force working or described first. A correct slow answer beats a buggy clever one, and it anchors your optimization.

(2) Reading complexity off the constraints

The input size n (often given in the constraints) tells you the target complexity, which in turn tells you the family of techniques. ~1e8 simple operations per second is the rough mental budget.

Constraint on nTargetWhat it unlocks
n ≤ 12O(n!)permutations / brute force over orderings
n ≤ 20O(2ⁿ)subsets, bitmask DP, backtracking
n ≤ 100O(n³)3 nested loops, Floyd-Warshall, interval DP
n ≤ 500O(n³)cubic still fine
n ≤ 5000O(n²)2 nested loops, simple DP, pair scans
n ≤ 1e5O(n log n)sort, heap, binary-search-the-answer
n ≤ 1e6O(n) / O(n log n)single pass / linearithmic
n ≤ 1e7O(n)hashing, two pointers, sliding window
n ≥ 1e9O(log n) / O(1)binary search on answer, math/closed form

And the special case: tiny n, huge values — the value range (not n) may drive complexity (binary search on a value range, or O(value) DP).

Use it backwards: if the brute force is O(n²) but n ≤ 1e5, you need to find an O(n log n) or O(n). The constraint is a hint, not just a limit.

(3) Pattern recognition — signal → technique → lesson

This is the heart of "matching". Each signal points to the lesson in this folder where the technique lives.

SignalTechniqueLesson
sorted array / find a pairtwo pointers / binary search05, 06
contiguous subarray / substringsliding window / prefix sum05, 07
top k / kth largest / k closestheap (or quickselect)11, 18
shortest path, unweightedBFS12
shortest path, weighted ≥ 0Dijkstra (heap)12
explore all paths / flood fillDFS12
all combinations / permutationsbacktracking13
count ways / optimal substructuredynamic programming14
next greater / smaller elementmonotonic stack08
connected groups / merge setsunion-find / DFS12, 17
prefix queries / autocompletetrie17
task ordering with dependenciestopological sort12
merge / overlapping intervalssort + sweep line15
fast lookup / dedupe / counthashmap / hashset02, 07
balanced brackets / nesting / undostack08

(4) Communication, common mistakes, edge cases

Communication

Common mistakes

Edge cases to always check

(5) A short study plan

  1. Week 1 — Fundamentals: arrays/strings, hashing, two pointers, sliding window, stacks/queues, binary search (lessons 0108-ish).
  2. Week 2 — Trees & graphs: BFS/DFS, recursion, topological sort, heaps (11, 12).
  3. Week 3 — Dynamic programming: 1D, 2D, knapsack, intervals; backtracking (13, 14).
  4. Week 4 — Advanced + review: union-find, tries, sorting internals (17, 18), and timed mock interviews. Always rehearse UMPIRE out loud.
Daily habit
2–3 problems, but review each — re-derive the pattern, redo it cold a few days later. Spaced repetition of patterns beats raw problem count.