Interview Playbook

The meta-framework. Re-read this the morning of the interview — it is how to use every other page on this site.

1. The 7-step method

For any DSA problem, walk these seven steps out loud. Interviewers grade the process as much as the answer.

Step 1

Clarify

Convert an ambiguous problem statement into a precise contract before you touch code.

Say

  • "Let me restate the problem to make sure I understand..."
  • "A few assumptions I want to confirm..."

Write

  • Input/output types and shapes
  • Size bounds (n, value range)
  • Duplicates allowed? Sorted? Negative values? Empty input?
  • Is there a memory or latency budget?

Avoid

  • Jumping to code before bounds are known
  • Silently assuming distinct / sorted / non-empty inputs
Step 2

Examples

Anchor the contract with concrete cases — especially edge cases.

Say

  • "Let me walk through a small example and then an edge case..."

Write

  • One happy-path example
  • One edge case (empty, single element, all duplicates, max size)
  • Expected output for each

Avoid

  • Only using the example from the prompt
  • Skipping the edge case — the interviewer will bring it up later anyway
Step 3

Brute force first

Get any correct answer on the board to establish a baseline and unblock discussion.

Say

  • "The obvious approach is O(n²) — let me state it so we have a baseline, then I will optimize."

Write

  • Brute-force complexity (time + space)
  • A one-line description, not full code

Avoid

  • Implementing the brute force in full — waste of time
  • Acting as if the brute force is beneath you; interviewers want to see the jump
Step 4

Optimize

Identify what is wasted in the brute force and pick a pattern.

Say

  • "The brute force recomputes X — I can cache it with a hash map."
  • "The input is sorted, which suggests two pointers or binary search."

Write

  • The wasted work in one sentence
  • The pattern you are reaching for and why
  • Target complexity before coding

Avoid

  • Optimizing by guessing a data structure without a reason
  • Jumping past multiple better solutions to an exotic one
Step 5

Code

Translate the chosen approach to clean, running code.

Say

  • "I will use meaningful names and extract helpers where it aids clarity."

Write

  • Invariants as comments at the top of loops
  • Inputs validated at the boundary only

Avoid

  • Premature micro-optimizations
  • Silent mutation of input arguments
  • Off-by-one errors in loop bounds — state the half-open vs closed convention
Step 6

Test

Trace through examples to catch off-by-ones and bad edge behavior.

Say

  • "Let me trace through the happy path, then the edge case."

Write

  • Dry-run state changes on the edge case
  • Flag any lines you are unsure about and fix before moving on

Avoid

  • Declaring done without any trace
  • Only testing the happy path
Step 7

Complexity

State final time and space complexity with a one-line justification.

Say

  • "Time is O(n log n) because we sort once and scan once; space is O(n) for the hash map."

Write

  • Time complexity + dominant term reasoning
  • Space complexity including recursion stack
  • Amortized vs worst-case if they differ

Avoid

  • Quoting a complexity without reasoning
  • Forgetting recursion-stack space in DFS solutions

2. Pattern from problem signals

Read the signals out of the problem statement, then reach for the candidate pattern. If the first candidate does not fit, cycle to the next.

If the problem says… Try
Sorted array / asked to find a pair / asked to remove duplicates in-place Two pointers (opposite ends, same direction)
Contiguous subarray / substring with a property / "longest ... with at most K" Sliding window (fixed or variable)
Linked list cycle / find middle node / Nth from the end Fast/slow pointers
"Find X in O(log n)" / sorted input / "smallest value such that predicate is true" Binary search (classic, first-true, answer-space)
Unweighted graph shortest path / level-order traversal BFS
Exhaustively explore / tree traversal / topological problems on DAGs DFS
Generate all combinations / permutations / valid configurations Backtracking
"Next greater / smaller element" / histogram rectangle / daily temperatures Monotonic stack
Dynamic connectivity / merge groups / "are A and B in the same set?" Union-Find
"Top K" / K most frequent / median from stream Heap / Quickselect
Task ordering with dependencies / "is there a cycle in a DAG?" Topological sort (Kahn / DFS)
Overlapping intervals / merge intervals / minimum rooms Sort-by-start + sweep
"Count the number of ways" / optimal sub-structure / overlapping subproblems Dynamic programming
"Minimum / maximum in a greedy local choice" Greedy (prove exchange argument)
XOR to find unique / count set bits / subset enumeration via bitmask Bit manipulation

Senior insight

Most interview problems are dressed-up versions of a handful of canonical shapes. Train yourself on signals — the phrases in the problem — not on memorizing solutions to specific LeetCode numbers.

3. Edge-case checklist

Run this list against every solution before you say "done".

4. Complexity computation cheat

Recognize the recurrence shape and read off the answer. For most interview analysis this beats invoking the Master Theorem formally.

Recurrence shape Result Canonical example
T(n) = T(n/2) + O(1) O(log n) Binary search
T(n) = 2·T(n/2) + O(n) O(n log n) Merge sort, quicksort (average)
T(n) = 2·T(n/2) + O(1) O(n) Tree traversal of balanced tree
T(n) = T(n - 1) + O(n) O(n²) Selection sort, naive insertion sort
T(n) = T(n - 1) + O(1) O(n) Linked list traversal
T(n) = 2·T(n - 1) + O(1) O(2ⁿ) Naive Fibonacci without memoization

Amortized analysis in one paragraph

Some operations are expensive but happen rarely enough that the average cost across many operations stays low. A dynamic array doubles when full, costing O(n), but the cost is spread across the n−1 prior cheap inserts — so append is O(1) amortized, even though the worst single call is O(n). Say "amortized" explicitly when the worst case and the long-run average diverge.

5. What to say when stuck

Silence is the enemy. These phrases keep the interviewer in the loop and often unlock the solution by forcing you to reason out loud.

6. Behavioral: the STAR template

A disciplined STAR answer is ~90 seconds. Budget your words accordingly — over-spending on Situation is the most common mistake.

Letter Part Budget Hint
S Situation 1–2 sentences Context the interviewer needs — team, stakes, constraints. Not your whole org chart.
T Task 1 sentence What you specifically had to do. Use "I", not "we".
A Action 3–5 sentences The decisions and trade-offs. This is the heart — spend most of your time here.
R Result 1–2 sentences Concrete outcome. Numbers when honest, qualitative when not. End with a lesson if you have one.

7. Questions to ask the interviewer

The questions you ask signal seniority. Skip "what do you like about working here" — ask things that only this interviewer can answer.

  1. What does a great engineer on your team look like 12 months in?
  2. What is the single biggest technical challenge the team is facing right now?
  3. How are architectural decisions made and documented here?
  4. What is the on-call rotation like, and how do you balance feature work with reliability?
  5. What would success in the first 30 / 60 / 90 days look like for this role?

How to actually use this page

Do not read this as prose. Use it as a recall prompt: cover the right column of the signal table and test yourself on what pattern each signal points to. Cover the "Write" column of the 7-step method and see if you can produce the bullets yourself. Passive reading does not transfer to the interview room.