TL;DR: This is the full list of the 41 patterns that cover coding interview questions: 30 common patterns and 11 advanced ones. Each row gives the tell, meaning the words or structures in a question that identify the pattern. It also gives the data structure it needs and the complexity to quote. Bookmark this page and use it as a lookup while you practice.
Interview questions are not unique. They are generated from a small set of reusable families, and each family has a tell: specific features in the question that give it away.
Once you can name the family, most of the work is done. The template is known, the complexity is known, and the remaining effort goes into writing the code carefully.
This page is the reference version of that idea. No essay, just the map. If you want the reasoning behind pattern-based preparation, the complete patterns guide covers it. If you want the code, the 10 templates on one page has it.

How to use this sheet
Read the question once. Then look for a phrase in the lookup table below, and check the matching pattern in the full list.
Two rules make this work:
- Look for the tell before you look for a solution. Most wrong answers come from starting to code before naming the family.
- If two patterns fit, say both out loud. Interviewers grade the reasoning. Naming two candidates and choosing between them scores better than silently picking one.
The fast lookup: from phrase to pattern
These are the phrases that appear most often in questions, and what each one usually means.
| The question says | Reach the pattern |
|---|---|
| "longest / shortest substring or subarray" | Sliding Window |
| "contiguous" plus a fixed size | Sliding Window |
| "sorted array" plus "pair" or "triplet" | Two Pointers |
| "cycle" in a linked list | Fast and Slow Pointers |
| "overlapping" or "merge" ranges | Merge Intervals |
| "numbers from 1 to n" with one missing or duplicated | Cyclic Sort |
| "reverse" a linked list or part of one | In-place Reversal of a Linked List |
| "valid parentheses", "nested", "undo" | Stacks |
| "next greater" or "next smaller" element | Monotonic Stack |
| "count", "group by", "have we seen this" | Hash Maps |
| "level by level" in a tree | Tree Level Order Traversal |
| "root to leaf" or "path sum" | Tree Depth First Search |
| "connected", "shortest path", unweighted | Graphs |
| a 2D grid with regions to count | Island (Matrix Traversal) |
| "median" of a running stream | Two Heaps |
| "all subsets", "all permutations", "all combinations" | Subsets |
| "sorted" plus "find the first or last position" | Modified Binary Search |
| "every element appears twice except one" | Bitwise XOR |
| "top K", "K most frequent", "K closest" | Top K Elements |
| "merge K sorted lists" | K-way Merge |
| "maximum number of meetings", "minimum coins" | Greedy Algorithms |
| "pick or skip" with a capacity limit | 0/1 Knapsack |
| "ways to climb", "state depends on the last two" | Fibonacci Numbers |
| "longest palindromic substring or subsequence" | Palindromic Subsequence |
| "place N queens", "solve the board", constraints | Backtracking |
| "prefix", "autocomplete", "starts with" | Trie |
| "prerequisites", "build order", "dependencies" | Topological Sort |
| "are these two in the same group", merging groups | Union Find |
| need sorted order plus fast insert and delete | Ordered Set |
| repeated "sum between index i and j" queries | Prefix Sum |
| "synchronize", "two threads alternate" | Multi-threaded |
The 30 common patterns
These cover the large majority of interview questions. Learn these first.
Arrays and strings
| Pattern | The tell | Structure used | Typical complexity |
|---|---|---|---|
| Two Pointers | Sorted input, find a pair or triplet | Two indices | O(n) time, O(1) space |
| Fast and Slow Pointers | Cycle detection, find the middle | Two moving indices | O(n) time, O(1) space |
| Sliding Window | Longest or shortest contiguous run | Window plus a hash map | O(n) time, O(k) space |
| Merge Intervals | Overlapping ranges, meeting rooms | Sort, then scan | O(n log n) time |
| Cyclic Sort | Values are 1 to n, one missing or duplicated | Swap into place | O(n) time, O(1) space |
| Prefix Sum | Many range sum queries, subarray summing to K | Running total array | O(n) build, O(1) per query |
| Hash Maps | Counting, grouping, seen before | Hash map | O(n) time, O(n) space |
Stacks and linked lists
| Pattern | The tell | Structure used | Typical complexity |
|---|---|---|---|
| Stacks | Nested structure, matching pairs, undo | Stack | O(n) time, O(n) space |
| Monotonic Stack | Next greater or smaller element | Stack kept in order | O(n) time, O(n) space |
| In-place Reversal of a Linked List | Reverse a list or a sublist, no extra space | Three pointers | O(n) time, O(1) space |
Trees and graphs
| Pattern | The tell | Structure used | Typical complexity |
|---|---|---|---|
| Tree Level Order Traversal | Output grouped by level | Queue | O(n) time, O(w) space |
| Tree Depth First Search | Root to leaf paths, subtree properties | Recursion or stack | O(n) time, O(h) space |
| Graphs | Connectivity, shortest path when unweighted | Adjacency list plus queue | O(V + E) time |
| Island (Matrix Traversal) | 2D grid, count or fill regions | Grid search | O(rows x cols) time |
| Topological Sort | Prerequisites, build order, a directed acyclic graph | In-degree counts plus queue | O(V + E) time |
| Union Find | Are two items in the same group, merge groups | Disjoint set | Near O(1) per operation |
| Trie | Prefix search, autocomplete, dictionary | Trie | O(L) per word |
Search and selection
| Pattern | The tell | Structure used | Typical complexity |
|---|---|---|---|
| Modified Binary Search | Sorted or rotated input, find a boundary | Two bounds | O(log n) time |
| Top K Elements | K largest, K smallest, K most frequent | Heap | O(n log k) time |
| K-way Merge | Merge K sorted lists or arrays | Min heap | O(n log k) time |
| Two Heaps | Median of a stream, split into halves | Max heap plus min heap | O(log n) per insert |
| Ordered Set | Sorted order plus fast insert, delete, lookup | Balanced tree or ordered set | O(log n) per operation |
| Bitwise XOR | Every element appears twice except one | XOR accumulator | O(n) time, O(1) space |
Recursion and dynamic programming
| Pattern | The tell | Structure used | Typical complexity |
|---|---|---|---|
| Subsets | All subsets, permutations, or combinations | Recursion, building up | O(2^n) or O(n!) |
| Backtracking | Constraints, place and undo, board puzzles | Recursion plus undo step | Exponential, pruned |
| Greedy Algorithms | Best local choice each step, scheduling | Sort, then one pass | O(n log n) time |
| 0/1 Knapsack | Pick or skip each item, capacity limit | 2D table | O(n x capacity) |
| Fibonacci Numbers | State depends on the previous one or two | 1D table | O(n) time, O(1) space possible |
| Palindromic Subsequence | Longest palindromic substring or subsequence | 2D table | O(n^2) time |
Concurrency
| Pattern | The tell | Structure used | Typical complexity |
|---|---|---|---|
| Multi-threaded | Synchronize threads, alternate output, shared state | Locks, semaphores, conditions | Depends on the design |
The 11 advanced patterns
These appear in senior loops and in harder rounds. Learn them after the common ones are solid.
| Pattern | Level | The tell |
|---|---|---|
| Counting | Easy | Count occurrences to shortcut a scan, bucket by value |
| Monotonic Queue | Easy | Sliding window maximum or minimum |
| Simulation | Easy | Follow the described process step by step, no clever trick |
| Linear Sorting Algorithm | Easy | Small fixed value range, sort faster than O(n log n) |
| Meet in the Middle | Medium | Search space too large, split it in half and combine |
| MO's Algorithm | Medium | Many offline range queries on a static array |
| Serialize and Deserialize | Medium | Convert a structure to a string and back |
| Clone | Medium | Deep copy a graph or a list with random pointers |
| Articulation Points and Bridges | Hard | Which node or edge disconnects the graph if removed |
| Segment Tree | Hard | Range queries with updates between them |
| Binary Indexed Tree | Hard | Prefix sums with updates, less code than a segment tree |
The order to learn them in
Do not work down the list from top to bottom. Each stage below reuses machinery from the one before it.
- Arrays and strings: Two Pointers, Sliding Window, Prefix Sum, Hash Maps
- Linked lists: Fast and Slow Pointers, In-place Reversal
- Stacks: Stacks, Monotonic Stack
- Trees: Tree Depth First Search, then Tree Level Order Traversal
- Graphs: Graphs, Island, Topological Sort, Union Find
- Heaps and intervals: Top K Elements, K-way Merge, Two Heaps, Merge Intervals
- Recursion: Subsets, then Backtracking
- Dynamic programming: Fibonacci Numbers, 0/1 Knapsack, Palindromic Subsequence
- The rest: Trie, Bitwise XOR, Cyclic Sort, Ordered Set, Greedy, Multi-threaded
- Advanced tier, only if your loop calls for it
About 14 of these cover most questions asked in a standard loop. The rest matter when a question falls outside the core, which happens often enough to be worth knowing the map.
Grokking the Coding Interview teaches all 41 in this order. Each one comes as a tell, a template, and a set of variations, with problems grouped so that recognition builds instead of memory.
How to practice with this sheet
Reading a cheat sheet does not install recognition. Use it as a drill instead.
The diagnosis drill. Open ten random problems. Do not solve any of them. For each one, write down the pattern name and the phrase that told you. Then check your answers. Ten minutes, and it trains the exact skill the first two minutes of an interview needs.
The cover-up drill. Hide the tell column. Read a pattern name and say the tell out loud from memory. Any pattern you cannot describe is one you have not learned yet.
Spaced review. Revisit a pattern three days after you learn it, then a week later. Recognition fades faster than people expect.
For how many problems this takes in total, see how many LeetCode problems you actually need. The number is smaller than most people assume, and it is closer to 100 to 150 when practice is organized by pattern.
Frequently asked questions
How many DSA patterns are there for coding interviews? There are 41 in this list: 30 common patterns and 11 advanced ones. About 14 of the common patterns cover most questions in a standard interview loop, and the advanced tier appears mainly in senior rounds.
Which patterns should I learn first? Start with Two Pointers, Sliding Window, Hash Maps, and Prefix Sum. They apply to the largest share of array and string questions and they build the habits the later patterns reuse.
Do I need all 41 patterns for a FAANG interview? No. The core 14 cover the majority of what is asked. The rest are worth knowing so that an unfamiliar question does not read as impossible, since it usually belongs to a named family.
Is a cheat sheet enough to prepare? No. A cheat sheet gives you the map, not the skill. You need to solve problems grouped by pattern so recognition becomes automatic, and you need to practice explaining your reasoning out loud.
How is a pattern different from a data structure? A data structure is a way to store data, like a heap or a trie. A pattern is a reusable way to handle a family of questions. It usually specifies which data structure to use, plus the shape of the code around it.
What if a question does not match any pattern? Most do. When one does not, it is usually two patterns combined, for example a sliding window that maintains a monotonic queue inside it. Name both parts out loud and build the solution from the pieces.
Related reading
- Coding Interview Patterns: The Complete Guide
- The 10 Coding Interview Templates on One Page
- Dynamic Programming Patterns
- Coding Interview Patterns in Python
- Coding Interview Patterns in Java
Learn all 41 the way this sheet lists them: Grokking the Coding Interview: Patterns for Coding Questions teaches every pattern as a tell, a template, and a set of variations, with more than 300 hand-picked problems in Python, Java, JavaScript, C++, C#, and Go. It costs $79 once, with lifetime access.
