Technical interviews can feel like an endless stream of random problems—until you start seeing the recurring patterns behind them. Instead of memorizing solutions, build a small “pattern toolkit” you can apply under pressure.
1) The 6 patterns that show up everywhere
Here are high-leverage patterns worth mastering (and why they matter):
- Two Pointers / Sliding Window: Great for arrays/strings when you’re optimizing from (O(n^2)) to (O(n)). Think: longest substring, subarray sums, removing duplicates.
- Hash Map Frequency / Indexing: Your go-to when you need constant-time lookups: anagrams, first non-repeating, two-sum variants.
- BFS/DFS on Trees & Graphs: Used for traversal, connected components, shortest path in unweighted graphs.
- Binary Search (and “Binary Search on Answer”): Not just for sorted arrays—also for minimizing/maximizing feasible values.
- Dynamic Programming (1D/2D): Best for “optimal substructure” problems like paths, partitions, edit distance.
- Greedy + Sorting: Scheduling, intervals, and “choose locally optimal” problems where proofs matter.
2) A simple workflow to use in live interviews
When you get a new problem, try this sequence:
- Clarify: Constraints, edge cases, input format. Ask: “Can values be negative? Are duplicates allowed? What size is n?”
- Brute force first: Say it out loud. This shows you can reason, not just recall.
- Name the pattern: Literally state: “This looks like a sliding window because…”
- State complexity targets: “We can do this in (O(n)) time and (O(k)) space.”
- Write clean code in passes:
- Pass 1: correct solution
- Pass 2: refactor (names, helper functions)
- Pass 3: edge cases + quick tests
3) How to practice so it transfers to real interviews
Instead of doing 50 unrelated problems, try:
- Batch practice by pattern (e.g., 8 sliding-window problems in a week).
- Maintain a “mistake log”: What trick got you? Off-by-one? Incorrect base case? Missing null checks?
- Do 2-minute summaries after each problem: “Pattern used, invariant, and why it’s correct.”
4) What interviewers actually listen for
Even when you don’t finish, you can score well by demonstrating:
- Invariants (what remains true each loop)
- Tradeoffs (time vs space)
- Testing mindset (small examples + edge cases)
If you had to pick one pattern you struggle with the most (DP, graphs, sliding window, etc.), which is it—and what specifically trips you up during interviews?