Coding interview prep
April 2, 2026
The 7 Algorithm Patterns That Cover 80% of Coding Interview Problems
Most coding interview problems aren't unique — they're variations of a small set of patterns. Learn to recognize these 7 and you'll stop memorizing solutions and start seeing the underlying structure behind every problem you encounter.
The most common mistake in interview prep is grinding problems in isolation. You solve 200 LeetCode problems and still freeze in an interview because you've never seen that exact problem before. The fix isn't more problems — it's recognizing that most problems map to one of a handful of patterns. Once you internalize a pattern, you can apply it to problems you've never seen.
These 7 patterns cover the vast majority of medium and hard problems you'll encounter at FAANG and top-tier tech companies. For each one, we'll cover when to use it, which classic problems it applies to, and the key insight that makes it click.
The 7 patterns
Sliding Window
Contiguous subarray or substring problems
When to use it: You need to find the maximum, minimum, or some property of a contiguous subarray or substring of a fixed or variable size. The key signal: the problem involves an array or string and asks about a 'window' of elements.
Classic problems:
- Maximum Sum Subarray of Size K
- Longest Substring Without Repeating Characters (LC 3)
- Minimum Window Substring (LC 76)
- Permutation in String (LC 567)
Interview tip: Start with a brute-force O(n²) and ask yourself: 'What changes as I move one step forward?' If the answer is 'I only add one element and remove one,' a sliding window brings it to O(n). Interviewers love when you verbalize this transition.
Two Pointers
Sorted arrays, pairs, or partitioning
When to use it: The input is sorted (or can be sorted) and you're looking for pairs, triplets, or need to partition elements. Also applies to linked list problems involving cycle detection or finding a midpoint.
Classic problems:
- Two Sum II — Input Array Is Sorted (LC 167)
- 3Sum (LC 15)
- Container With Most Water (LC 11)
- Linked List Cycle (LC 141) — fast & slow pointer variant
Interview tip: There are two variants: same-direction (fast/slow) and opposite-direction (left/right). Make sure you know which one applies. In interviews, draw the array and physically move the pointers — it makes your reasoning visible and reduces errors.
BFS / Level-order Traversal
Shortest path in unweighted graphs, level-by-level tree processing
When to use it: You need the shortest path in an unweighted graph, need to process a tree level by level, or need to explore all neighbors before going deeper. BFS guarantees the shortest path in terms of number of edges.
Classic problems:
- Binary Tree Level Order Traversal (LC 102)
- Rotting Oranges (LC 994)
- Word Ladder (LC 127)
- Number of Islands (LC 200) — also solvable with DFS
Interview tip: The queue is everything in BFS. In an interview, always state explicitly: 'I'm using a queue to process nodes level by level.' Then explain why that gives you the shortest path. Knowing the O(V+E) complexity and being able to justify it out loud is what separates average from strong candidates.
DFS / Backtracking
Exhaustive search, tree paths, combinations and permutations
When to use it: You need to explore all possibilities, build combinations or permutations, or traverse a tree/graph looking for a specific path. Backtracking adds the ability to undo choices and explore alternatives.
Classic problems:
- Number of Islands (LC 200)
- Subsets (LC 78)
- Permutations (LC 46)
- Word Search (LC 79)
- N-Queens (LC 51)
Interview tip: The backtracking template is always: choose → explore → unchoose. Write that structure explicitly in interviews. The most common mistake is forgetting to 'unchoose' — make sure your solution restores state before returning from each recursive call.
Binary Search
Search in sorted space — not just arrays
When to use it: The search space is sorted or monotonic. This is broader than 'find an element in a sorted array' — binary search applies whenever you can answer 'is the answer ≥ X?' for any X in a sorted range. This includes problems like finding the minimum capacity, the kth smallest, or the optimal resource allocation.
Classic problems:
- Binary Search (LC 704)
- Find Minimum in Rotated Sorted Array (LC 153)
- Koko Eating Bananas (LC 875)
- Capacity To Ship Packages Within D Days (LC 1011)
Interview tip: The off-by-one errors in binary search are a common failure point. Internalize one template (lo=0, hi=n-1, while lo<=hi) and stick to it. For the 'search on answer' variant, always verify: 'Is my search space monotonic? Can I define a condition that splits it cleanly?' If yes, binary search works.
Dynamic Programming
Overlapping subproblems with optimal substructure
When to use it: The problem asks for a count, minimum, maximum, or existence of something, and the naive recursive solution has overlapping subproblems (you compute the same sub-answer multiple times). DP caches those sub-answers to avoid recomputation.
Classic problems:
- Climbing Stairs (LC 70)
- Longest Common Subsequence (LC 1143)
- Coin Change (LC 322)
- 0/1 Knapsack
- Longest Increasing Subsequence (LC 300)
Interview tip: Always start DP with the recursive definition. Define dp[i] (or dp[i][j]) in plain English before writing any code. Then convert to bottom-up if needed. In interviews, saying 'dp[i] represents the minimum cost to reach step i' shows structured thinking — that's what the interviewer wants to see, not just a working solution.
Graph Shortest Path (Dijkstra / BFS weighted)
Weighted shortest path, priority queues
When to use it: You need the shortest path in a weighted graph (all non-negative weights). BFS doesn't work here because edges have different costs — you need to always expand the cheapest node first. That's Dijkstra with a min-heap.
Classic problems:
- Network Delay Time (LC 743)
- Path With Minimum Effort (LC 1631)
- Cheapest Flights Within K Stops (LC 787)
- Find the City With the Smallest Number of Neighbors (LC 1334)
Interview tip: Dijkstra requires a min-heap (priority queue). The pattern is always: push (cost, node) → pop cheapest → skip if already visited → process neighbors. Know the O((V+E) log V) complexity. For interviews involving negative weights, mention Bellman-Ford — it shows you understand the boundaries of each algorithm.
How to study these patterns effectively
Knowing the 7 patterns is necessary but not sufficient. The gap between "I've read about sliding window" and "I can apply it under pressure in 20 minutes" is closed by two things: seeing the execution and connecting it to your own code.
- Learn the pattern visually first. Before writing a single line of code, watch the algorithm run step by step. Where does the pointer move? What gets added to the queue? What state changes at each step? This builds the mental model you'll need to reconstruct the solution from scratch.
- Code it without looking. Once you've seen the visual execution, close the reference and implement it. Run it on the same example you visualized. This reveals exactly where your understanding breaks down — which is the most valuable information you can get.
- Write down the intuition, not just the code. After solving a problem, write one sentence: "This is a sliding window because the window expands and contracts to maintain a constraint." That sentence is what you'll say in an interview. Without it, the knowledge stays as code you memorized rather than a pattern you can apply.
- Add the complexity analysis. For every problem: time complexity, space complexity, and why. Being able to derive O(n log n) for Dijkstra instead of just reciting it is the difference between passing and failing the follow-up questions.
- Practice recognition, not recall. Given a new problem, ask: "Which of the 7 patterns applies here?" That's the skill that transfers to real interviews. Practice it by reading problem statements and writing down the pattern before looking at any solution.
This is the workflow Expora is built for: visual execution step by step, a coding notebook where you write and run your own implementation, and structured notes where you capture the intuition and complexity — all for the same problem, in the same place.
Which pattern to learn first
If you're starting from scratch, this is the order that minimizes wasted time and maximizes coverage:
- Two Pointers — simplest to implement, appears in many easy/medium problems
- Sliding Window — builds directly on Two Pointers, massive coverage in strings/arrays
- BFS — once you have the queue pattern, it's systematic and reliable
- DFS / Backtracking — learn the template, practice the choose/unchoose structure
- Binary Search — focus on the "search on answer" variant, it's underestimated
- Dynamic Programming — hardest to internalize, start with 1D DP (climbing stairs, coin change)
- Dijkstra — last because it requires heap + graph knowledge, but very high signal in interviews
Two to three solid weeks on each pattern, with 8–10 problems per pattern, is enough to build reliable recognition. That's 14–21 weeks for all 7 — a realistic timeline for a structured preparation.
Summary
The 7 patterns — Sliding Window, Two Pointers, BFS, DFS/Backtracking, Binary Search, Dynamic Programming, and Dijkstra — cover the structural foundation behind the vast majority of coding interview problems. Recognizing which pattern applies is the skill; the implementation follows from that.
Study each pattern by seeing its execution visually, coding it without reference, writing the intuition in one sentence, and practicing recognition on unseen problems. That's the preparation that transfers — not the number of problems solved, but the depth of understanding behind each one.
Explore more
- Interactive algorithm visualizer →See BFS, DFS, Dijkstra, Sliding Window run step by step
- Coding interview prep →Roadmaps and visual debuggers by pattern
- How to visualize algorithms step by step →BFS, DFS, DP with interactive execution
Practice these patterns in Expora
Step-by-step visualizers for every pattern above, a coding notebook with Judge0 execution, and structured notes to capture intuition and complexity. Join the whitelist for early access.