The 15 Coding Interview Patterns That Cover Most Questions (With One Problem Each)
The 15 coding interview patterns behind most questions, from two pointers to dynamic programming, with the signal for each and one practice problem.
- leetcode patterns
- DSA patterns
- sliding window pattern
- two pointers pattern
Short answer: most coding interview questions are variations of about 15 coding interview patterns: two pointers, sliding window, hash map counting, prefix sums, binary search, fast and slow pointers, linked list reversal, monotonic stack, heaps, intervals, tree DFS, BFS, topological sort, backtracking, and dynamic programming. Learn the signal that triggers each one and solve one core problem per pattern before you add volume.
Solving hundreds of random problems is a slow way to prepare. Interviewers draw from a fairly small set of patterns, and once you recognize the pattern, the problem gets much easier. Each section below gives the signal to look for, the core idea, and one problem to practice on.
The 15 patterns at a glance
| # | Pattern | Signal in the problem | Practice problem |
|---|---|---|---|
| 1 | Two pointers | Sorted array, pairs, or reversing in place | Container With Most Water |
| 2 | Sliding window | Longest or shortest contiguous subarray or substring | Longest Substring Without Repeating Characters |
| 3 | Hash map counting | Frequencies, duplicates, "have I seen this" | Group Anagrams |
| 4 | Prefix sums | Range sums or products, many queries | Product of Array Except Self |
| 5 | Binary search | Sorted input, or "minimum value that works" | Koko Eating Bananas |
| 6 | Fast and slow pointers | Cycles, middle of a list | Linked List Cycle |
| 7 | Linked list reversal | Reverse all or part of a list | Reverse Linked List |
| 8 | Monotonic stack | "Next greater" or "next smaller" element | Daily Temperatures |
| 9 | Heap / top-k | k largest, k most frequent, running median | Top K Frequent Elements |
| 10 | Intervals | Overlapping ranges, meetings, bookings | Merge Intervals |
| 11 | Tree DFS | Paths, heights, validating a tree | Validate Binary Search Tree |
| 12 | BFS | Shortest path in unweighted graphs, level order | Number of Islands |
| 13 | Topological sort | Dependencies, prerequisites, ordering | Course Schedule |
| 14 | Backtracking | All combinations, subsets, permutations | Subsets |
| 15 | Dynamic programming | Count ways, min or max cost, overlapping subproblems | Coin Change |
Array and string patterns
1. Two pointers
Move two indices toward each other, or both forward at different speeds. It turns many O(n²) pair searches into O(n) on sorted input. Ask yourself: if I move the left pointer, does the answer only get better or only get worse? If yes, two pointers probably works.
2. Sliding window
Keep a window [left, right] and a running state (a count, a set, a sum). Expand right; shrink left when the window breaks the rule. Each index enters and leaves once, so it is O(n).
3. Hash map counting
When the problem mentions frequencies, duplicates, or complements, a hash map turns lookups into O(1). Two Sum is the classic example.
4. Prefix sums
Precompute running totals so any range sum is one subtraction. Variants include prefix products and difference arrays for many range updates.
5. Binary search, including on the answer
Binary search is not only for finding a value in a sorted array. If you can write a yes/no check like "can she finish at speed k?" and the answers flip from no to yes once, binary search the smallest k that works.
Linked list and stack patterns
6. Fast and slow pointers
One pointer moves one step, the other two. If there is a cycle, they meet. The same trick finds the middle of a list.
7. Linked list reversal
Keep prev, curr, and next, and flip one link at a time. Draw it on paper first; most bugs here are lost references.
8. Monotonic stack
Keep a stack of indices whose values are always increasing or decreasing. When a new value breaks the order, pop and answer the "next greater" question for each popped index.
Heap and interval patterns
9. Heaps and top-k
A heap of size k keeps the k best items in O(n log k). Two heaps (a max-heap and a min-heap) keep a running median.
10. Intervals
Sort by start time, then sweep and merge or count overlaps. Meeting rooms, calendar bookings, and merging ranges are all this pattern.
Tree and graph patterns
11. Tree DFS
Most tree problems are a recursive function that returns something from each subtree (height, validity, a max path) and combines the results. Decide what each call returns before you write it.
12. BFS
Use a queue to explore level by level. BFS gives the shortest path in an unweighted graph and powers grid problems like flood fill.
13. Topological sort
For dependency problems, count incoming edges, start from nodes with zero, and remove edges as you go (Kahn's algorithm). If you cannot process every node, there is a cycle.
Search and optimization patterns
14. Backtracking
Build a solution step by step, recurse, then undo the step. Subsets, permutations, combination sums, and word search all follow the same template: choose, explore, un-choose.
15. Dynamic programming
If a brute-force recursion recomputes the same subproblems, store the results. Define the state ("min coins to make amount a"), the transition, and the base case. Start with one-dimensional DP before grids.
Two more worth knowing
- Union-find for connectivity and grouping: Graph Valid Tree.
- Trie for prefix search: Implement Trie.
How to study patterns
- Learn one pattern at a time. Solve the core problem, then two variations.
- For each problem, write the signal that told you which pattern to use.
- Mix the patterns after a week, so you practice recognizing them without a label.
The data structure decision guide helps with the "which structure?" step, and the time complexity cheat sheet helps you check your approach against the input size.
FAQ
How many coding interview patterns are there?
Lists range from about 12 to 25 depending on how finely you split them. The 15 here cover most questions asked in typical coding interviews.
Should I learn patterns or just solve many problems?
Learn the patterns first, then solve problems to practice recognizing them. Volume without patterns tends to produce memorized solutions that fail on new variations.
Which pattern is asked most often?
Arrays with hash maps, two pointers, and sliding windows come up constantly, followed by trees, graphs, and dynamic programming.
How can I practice recognizing patterns under interview conditions?
Solve problems without the topic tag, then explain your choice out loud. TechInView's AI interviewer asks why you chose an approach, which is exactly the skill interviewers test. Browse the practice problems by category to start.
Summary: learn these 15 coding interview patterns, the signal for each, and one core problem per pattern. Recognizing the pattern is most of the work in an interview; the code follows from it.