Complete Guide · 2026
Coding Interview Patterns: 15 Essential Templates for 2026
The 15 coding interview patterns that appear in 95%+ of FAANG technical interviews — with recognition cues, code templates in Python, Java, and C++, and a recommended learning order from beginner to advanced.
What Are Coding Interview Patterns?
Coding interview patterns are reusable algorithmic templates — not memorized solutions, but mental frameworks for recognizing and solving entire classes of problems. When you see a problem asking to "find the longest substring without repeating characters," a Sliding Window pattern immediately comes to mind. When you see "find a pair in a sorted array that sums to a target," Two Pointers is the answer.
The 15 patterns in this guide appear in 95%+ of coding interviews at FAANG companies. Google, Amazon, Meta, Microsoft, and Apple test the same core algorithmic concepts across thousands of interviews each year. Mastering these patterns means you're solving the problem type, not just the specific problem.
Pattern-based prep is the approach behind resources like Grokking the Coding Interview, NeetCode, and this guide. The insight is simple: there are roughly 2,000+ LeetCode problems, but only ~15 underlying patterns. Learn the patterns, and you can solve any problem variant you encounter.
Why Pattern-Based Prep Beats Random Grinding
Random grinding — solving 200+ problems in no particular order — produces diminishing returns. After 50 random problems, you start memorizing specific solutions rather than building transferable intuition. The "recognize then solve" framework changes this fundamentally.
Here's how it works: When you encounter a new problem, your first question should not be "how do I solve this?" but "which pattern does this look like?" The pattern recognition step narrows down your approach from infinite possibilities to 2–3 candidates. Then you apply the pattern's template and adapt it to the specific constraints.
Step 1
Recognize
Identify signal words in the problem statement that point to a pattern
Step 2
Apply
Reach for the pattern's template and adapt it to the specific constraints
Step 3
Optimize
Analyze time/space complexity and optimize if needed
The 15 Essential Coding Interview Patterns
Organized by learning tier — master Tier 1 first, then 2, then 3. Click any pattern to see full templates and example problems.
Sliding Window
Efficiently process subarrays or substrings of a fixed or variable size.
O(n)
Two Pointers
Use two indices moving toward each other or in the same direction to solve linear problems.
O(n)
Binary Search
Halve the search space each step to find an element or boundary in O(log n).
O(log n)
Hash Map / Set
Trade space for time using O(1) lookup to find pairs, duplicates, and frequencies.
O(1) average for lookup/insert, O(n) space
Stack
LIFO structure for matching brackets, evaluating expressions, and monotonic problems.
O(n)
Queue / BFS
Level-by-level traversal for shortest paths and layer-based problems.
O(V + E) for graphs, O(n) for trees
Trees / DFS
Recursive and iterative depth-first traversal for tree structure problems.
O(n)
Dynamic Programming
Break problems into overlapping subproblems and build up solutions bottom-up.
Depends on state space
Prefix Sum
Precompute cumulative sums to answer range queries in O(1).
O(n) build, O(1) per query
Heap / Priority Queue
Efficiently track the k-th largest/smallest element or merge sorted sequences.
O(log n) insert/delete, O(1) peek
Greedy
Make the locally optimal choice at each step to achieve a globally optimal solution.
O(n log n)
Backtracking
Explore all possibilities recursively, pruning invalid branches early.
Exponential
Trie
Prefix tree for efficient string search, autocomplete, and word matching.
O(m) per operation where m is word length
Union Find
Disjoint set union for grouping, connectivity, and cycle detection.
O(α(n)) per operation
Intervals
Merge, insert, and count overlapping intervals after sorting by start time.
O(n log n)
Linked List
Pointer manipulation for in-place list operations without extra memory.
O(n)
Graphs
DFS and BFS on adjacency lists for connectivity, cycles, and path problems.
O(V + E)
Monotonic Stack
Maintain a sorted stack to find next/previous greater or smaller elements in O(n).
O(n)
Topological Sort
Linear ordering of vertices in a DAG — essential for dependency problems.
O(V + E)
Bit Manipulation
Use bitwise operations to solve XOR, subset, and number theory problems.
O(1) or O(log n) for most operations
Matrix
Navigate 2D grids with DFS/BFS, rotation, spiral traversal, and flood fill.
O(m × n)
How to Recognize Which Pattern to Use
When you read a problem statement, look for these signal phrases. They reliably map to specific coding interview patterns.
| If the problem says / asks for... | Use this pattern |
|---|---|
| Contiguous subarray / substring with a constraint | Sliding Window → |
| Sorted array, find a pair / triplet / sum | Two Pointers → |
| Find / search in a sorted array or range | Binary Search → |
| Count subarrays, range queries, prefix/suffix sums | Prefix Sum → |
| Count frequency, find duplicates, find complement | Hash Map / Set → |
| Matching brackets, next greater element, evaluate expressions | Stack → |
| Shortest path, level-order traversal, flood fill | Queue / BFS → |
| Depth of tree, path sum, serialize/deserialize | Trees / DFS → |
| Top K elements, merge sorted lists, data stream median | Heap / Priority Queue → |
| Find all permutations, subsets, combinations | Backtracking → |
| Overlapping subproblems, optimal substructure | Dynamic Programming → |
| Path / connectivity in graph, cycle detection | Graphs → |
| Dependency ordering, DAG, prerequisites | Topological Sort → |
| Prefix search, autocomplete, word dictionary | Trie → |
| Group nodes, connected components, merge accounts | Union Find → |
| Locally optimal choice leads to global solution | Greedy → |
| Next / previous greater or smaller, histogram area | Monotonic Stack → |
| Overlapping intervals, meeting rooms, schedule | Intervals → |
Pattern Complexity Quick Reference
Use this table when analyzing your solutions during interviews. Knowing the expected time and space complexity for each pattern prevents overcomplicated solutions.
| Pattern | Time | Space |
|---|---|---|
| Sliding Window | O(n) | O(k) |
| Two Pointers | O(n) | O(1) |
| Binary Search | O(log n) | O(1) |
| Prefix Sum | O(n) build, O(1) per query | O(n) |
| Hash Map / Set | O(1) average for lookup/insert, O(n) space | O(n) |
| Stack | O(n) | O(n) |
| Queue / BFS | O(V + E) for graphs, O(n) for trees | O(V) |
| Heap / Priority Queue | O(log n) insert/delete, O(1) peek | O(n) |
| Linked List | O(n) | O(1) |
| Trees / DFS | O(n) | O(h) |
| Graphs | O(V + E) | O(V) |
| Dynamic Programming | Depends on state space | O(n) |
| Greedy | O(n log n) | O(1) |
| Backtracking | Exponential | O(n) |
| Trie | O(m) per operation where m is word length | O(ALPHABET_SIZE |
| Union Find | O(α(n)) per operation | O(n) |
| Monotonic Stack | O(n) | O(n) |
| Topological Sort | O(V + E) | O(V) |
| Bit Manipulation | O(1) or O(log n) for most operations | O(1) |
| Intervals | O(n log n) | O(n) |
| Matrix | O(m × n) | O(m |
Recommended Order to Learn Coding Interview Patterns
Follow this sequence to build intuition progressively. Each pattern builds on the previous ones — jumping straight to Dynamic Programming before understanding Hash Maps and BFS leads to frustration.
Two Pointers
Sliding Window
Binary Search
Hash Map / Set
Stack
Queue / BFS
Trees / DFS
Heap / Priority Queue
Backtracking
Intervals
Prefix Sum
Dynamic Programming
Graphs
Trie
Union Find
Coding Interview Patterns by Company
Different companies emphasize different coding interview algorithm patterns. Tailor your prep to your target company after mastering the core patterns.
- 1 Dynamic Programming
- 2 Graph BFS/DFS
- 3 Binary Search
- 4 Trees
- 5 Topological Sort
Amazon
- 1 Trees
- 2 BFS / Graphs
- 3 Two Pointers
- 4 Hash Maps
- 5 Greedy
Meta
- 1 Sliding Window
- 2 Two Pointers
- 3 BFS/DFS Trees
- 4 Hash Map
- 5 Dynamic Programming
Microsoft
- 1 Trees
- 2 Dynamic Programming
- 3 Graphs
- 4 Linked List
- 5 Binary Search
Apple
- 1 Arrays
- 2 Trees
- 3 Binary Search
- 4 Sliding Window
- 5 Stack
Frequently Asked Questions
How many coding interview patterns are there?
There are approximately 15 core coding interview patterns covering 95%+ of FAANG problems. These include Sliding Window, Two Pointers, Binary Search, Hash Map, Stack, BFS, DFS, Heap, Backtracking, Dynamic Programming, Graphs, Trie, Union Find, Greedy, and Intervals. Some resources break these into sub-patterns, but mastering the 15 core patterns gives you the complete toolkit.
What is the most important pattern to learn first?
Start with Two Pointers and Sliding Window — these appear in dozens of problems across arrays, strings, and linked lists. Then learn Hash Map (unlocks Two Sum variants) and Binary Search. These four Tier 1 patterns cover roughly 40% of all coding interview questions and form the foundation for advanced patterns.
Is learning patterns enough to pass FAANG interviews?
Pattern knowledge is necessary but not sufficient. You also need timed practice (35–45 minutes per problem), clear communication of your thought process, and the ability to handle edge cases on demand. Most engineers fail not because they don't know patterns, but because they can't apply them quickly under pressure. Combine pattern study with regular timed practice sessions.
How long does it take to master all coding interview patterns?
Most engineers need 6–12 weeks to feel confident with all 15 patterns — roughly 1–2 weeks per tier. Budget 2 weeks for Tier 1 patterns, 3–4 weeks for Tier 2, and the remaining time for Tier 3. Spending 2–3 hours daily on problems and pattern review is the typical pace for a focused interview prep sprint.
What's the difference between Blind 75 and coding interview patterns?
Blind 75 is a list of specific problems to solve. Coding interview patterns are the algorithmic templates those problems test. Learning patterns first means you can solve any variant — not just the exact 75 problems on the list. Ideally, study patterns here, then validate with Blind 75 or Grind 75 problems.
Do I need to learn all 15 patterns?
For most mid-level roles, mastering Tier 1 + Tier 2 (8 patterns) is sufficient. For senior roles or top-tier companies like Google and Meta, cover all 15 patterns. Union Find, Monotonic Stack, and Topological Sort appear rarely in interviews but are relatively quick to learn once you have the foundations — usually a weekend each.