The complete list of 20 LeetCode patterns. Each one carries the signal that identifies it in a problem statement, a code template you can reuse, and three practice problems on LeetCode. Pattern problem counts come from LeetCode's own topic tags.
LeetCode has 4,073 problems. Nobody solves them all, and nobody needs to.
The questions are generated from a much smaller set of reusable approaches. Learn to recognize those, and a problem you have never seen becomes a variation of one you have. Miss them, and every question feels new, which is why solving hundreds of problems at random produces so little.
This guide covers all 20 patterns. For each one you get the cue that gives it away, why it works, a short template in Python, and three real LeetCode problems to practice on. The order is by what each pattern returns against LeetCode's actual problem distribution, so the earliest entries are the ones worth learning first.
You will see these called LeetCode patterns, LC patterns, coding patterns, or DSA patterns. They are the same thing: a reusable approach that pairs an algorithmic technique with the data structure it runs on. A single LeetCode pattern is worth more than a hundred solved problems, because the pattern transfers and the solved problem does not.
If you want the same 20 as a short reference instead, see the coding interview patterns catalog. If you want to train the recognition skill itself rather than read the list, see how to read a problem statement and name the pattern.
All 20 LeetCode Patterns
- Two Pointers
- Sliding Window
- Modified Binary Search
- Tree Depth First Search
- Tree Breadth First Search
- Island (Matrix Traversal)
- 0/1 Knapsack (Dynamic Programming)
- Top 'K' Elements
- Backtracking
- Subsets
- Bitwise XOR
- Fast & Slow Pointers
- Merge Intervals
- Monotonic Stack
- Topological Sort
- In-place Reversal of a Linked List
- Two Heaps
- Cyclic Sort
- K-way Merge
- Multi-threaded
The 20 Patterns at a Glance
Problem counts are LeetCode topic-tag totals, pulled from LeetCode. A few patterns share a tag and two have no dedicated tag, which is noted rather than guessed.
| Pattern | Recognize it by | Time | LeetCode problems |
|---|---|---|---|
| 1. Two Pointers | sorted input, find a pair or triplet | O(n) time | 263 |
| 2. Sliding Window | longest or shortest contiguous run | O(n) time | 175 |
| 3. Modified Binary Search | sorted or rotated, or a testable answer | O(log n) time | 356 |
| 4. Tree Depth First Search | root-to-leaf path, or a subtree answer | O(n) time | 349 |
| 5. Tree Breadth First Search | levels, or fewest steps | O(n) time | 260 |
| 6. Island (Matrix Traversal) | a grid, count connected regions | O(m*n) time | 285 |
| 7. 0/1 Knapsack (Dynamic Programming) | pick a subset under a capacity | O(n*C) time | 684 |
| 8. Top 'K' Elements | k largest, smallest, or most frequent | O(n log k) time | 222 |
| 9. Backtracking | list every valid configuration | O(b^d) time | 114 |
| 10. Subsets | every combination or power set | O(n * 2^n) time | 114 |
| 11. Bitwise XOR | values pair off, find the odd one out | O(n) time | 297 |
| 12. Fast & Slow Pointers | cycle, middle, or kth from the end | O(n) time | 263 |
| 13. Merge Intervals | ranges or time slots that overlap | O(n log n) time | no dedicated tag |
| 14. Monotonic Stack | next greater or next smaller element | O(n) time | 76 |
| 15. Topological Sort | prerequisites, ordering, cycle check | O(V+E) time | 40 |
| 16. In-place Reversal of a Linked List | reverse a list without new memory | O(n) time | 82 |
| 17. Two Heaps | running median, or a split set | O(log n) insert | 222 |
| 18. Cyclic Sort | a permutation of 1..n | O(n) time | no dedicated tag |
| 19. K-way Merge | k sorted lists to combine | O(n log k) time | 17 |
| 20. Multi-threaded | coordinate or order concurrent work | depends on the coordination primitive | 9 |
The Most Common LeetCode Patterns
If you only have time for part of this list, the eight most common LeetCode patterns are the first eight above: Two Pointers, Sliding Window, Modified Binary Search, Tree Depth First Search, Tree Breadth First Search, Island (Matrix Traversal), 0/1 Knapsack, and Top 'K' Elements.
Those eight are also the most important ones to get automatic, because they are the patterns an interviewer is most likely to reach for and the ones whose variations show up across the widest range of questions. Together they account for the large majority of what gets asked in a standard coding loop.
One warning about reading tag counts straight. Bitwise XOR carries 297 tagged problems, which is more than Sliding Window's 175, but almost all of those are narrow puzzles rather than interview staples. A large tag means the technique is common in the problem set, not that it is common in interviews. The order on this page accounts for that; a raw tag ranking does not.
LeetCode Patterns Cheat Sheet: What the Wording Tells You
Pattern recognition is mostly vocabulary. The same phrases appear in problem statements again and again, and each one points at a small number of patterns. Use this as a lookup while you practice, then stop using it once the mapping is automatic.
| If the problem says | Reach for |
|---|---|
| "sorted array" plus "find a pair / triplet" | Two Pointers |
| "longest" or "shortest" plus "substring" or "subarray" | Sliding Window |
| "at most K" or "exactly K distinct" | Sliding Window |
| "rotated sorted array" | Modified Binary Search |
| "minimum / maximum value such that ..." | Modified Binary Search |
| "root-to-leaf" or "path sum" | Tree Depth First Search |
| "level order" or "level by level" | Tree Breadth First Search |
| "shortest number of steps" on a graph or grid | Tree Breadth First Search |
| "grid" plus "connected" or "regions" or "islands" | Island (Matrix Traversal) |
| "can you partition" or "reach exactly this total" | 0/1 Knapsack (Dynamic Programming) |
| "fewest coins" or "ways to make up" | 0/1 Knapsack (Dynamic Programming) |
| "top K" or "K most frequent" or "K closest" | Top 'K' Elements |
| "all permutations" or "all valid boards" | Backtracking |
| "all subsets" or "power set" or "all combinations" | Subsets |
| "every element appears twice except one" | Bitwise XOR |
| "cycle", "middle node", or "Nth from the end" | Fast & Slow Pointers |
| "intervals", "meetings", or "time slots" | Merge Intervals |
| "next greater" or "next smaller" element | Monotonic Stack |
| "prerequisites", "course order", or "build order" | Topological Sort |
| "reverse the list" with O(1) extra space | In-place Reversal of a Linked List |
| "median" of a stream or a window | Two Heaps |
| "numbers from 1 to n" with one missing or duplicated | Cyclic Sort |
| "K sorted lists" or "K sorted arrays" | K-way Merge |
| "threads must run in order" | Multi-threaded |
Two cautions. A problem can carry more than one of these signals, in which case the patterns usually compose rather than compete, such as a sliding window over a monotonic stack. And a phrase is evidence, not proof; confirm against the constraints before you commit to an approach.
If you want to train this recognition rather than look it up, this walkthrough reads a problem statement and names the pattern step by step.
Two Pointers
Use it when the input is sorted, or you need a pair, triplet, or subsequence that satisfies a condition.
Two indices moving toward each other turn an O(n^2) scan of every pair into a single O(n) pass, because a sorted order tells you which pointer to move.
def two_sum_sorted(nums, target):
lo, hi = 0, len(nums) - 1
while lo < hi:
s = nums[lo] + nums[hi]
if s == target:
return [lo, hi]
if s < target:
lo += 1 # need a bigger sum
else:
hi -= 1 # need a smaller sum
return []
Complexity: O(n) time, O(1) space. LeetCode tags 263 problems with two-pointers.
Practice on LeetCode:
Sliding Window
Use it when the question asks for the longest, shortest, or best contiguous subarray or substring.
The window expands to include new elements and contracts to restore the constraint, so each element is visited at most twice instead of being re-scanned for every start index.
def longest_unique(s):
seen, left, best = {}, 0, 0
for right, ch in enumerate(s):
if ch in seen and seen[ch] >= left:
left = seen[ch] + 1 # contract past the duplicate
seen[ch] = right
best = max(best, right - left + 1)
return best
Complexity: O(n) time, O(k) space. LeetCode tags 175 problems with sliding-window.
Practice on LeetCode:
Modified Binary Search
Use it when the input is sorted or rotated, or the answer itself is a number you can test for feasibility.
Any question where a candidate answer can be checked in O(n) becomes O(n log n) by binary searching the answer space rather than the array.
def search_rotated(nums, target):
lo, hi = 0, len(nums) - 1
while lo <= hi:
mid = (lo + hi) // 2
if nums[mid] == target:
return mid
if nums[lo] <= nums[mid]: # left half is sorted
if nums[lo] <= target < nums[mid]:
hi = mid - 1
else:
lo = mid + 1
else: # right half is sorted
if nums[mid] < target <= nums[hi]:
lo = mid + 1
else:
hi = mid - 1
return -1
Complexity: O(log n) time, O(1) space. LeetCode tags 356 problems with binary-search.
Practice on LeetCode:
Tree Depth First Search
Use it when the answer depends on a full root-to-leaf path, or on information returned from a subtree.
Recursion carries state down the path and returns an answer back up, which is exactly the shape of path sums, depths, and subtree validity checks.
def has_path_sum(node, target):
if not node:
return False
rest = target - node.val
if not node.left and not node.right: # leaf
return rest == 0
return has_path_sum(node.left, rest) or has_path_sum(node.right, rest)
Complexity: O(n) time, O(h) space. LeetCode tags 349 problems with depth-first-search.
Practice on LeetCode:
Tree Breadth First Search
Use it when the question mentions levels, or asks for the shortest number of steps.
A queue visits every node at distance k before any node at distance k+1, so the first time you reach a target you have reached it by the shortest route.
from collections import deque
def level_order(root):
if not root:
return []
out, q = [], deque([root])
while q:
level = []
for _ in range(len(q)): # freeze the level width
node = q.popleft()
level.append(node.val)
if node.left:
q.append(node.left)
if node.right:
q.append(node.right)
out.append(level)
return out
Complexity: O(n) time, O(w) space. LeetCode tags 260 problems with breadth-first-search.
Practice on LeetCode:
- Binary Tree Level Order Traversal
- Binary Tree Zigzag Level Order Traversal
- Minimum Depth of Binary Tree
Island (Matrix Traversal)
Use it when the input is a grid and you need to find or count connected regions.
A grid is a graph whose neighbors are implicit, so one flood fill per unvisited cell counts regions in a single pass over the matrix.
def num_islands(grid):
if not grid:
return 0
rows, cols, count = len(grid), len(grid[0]), 0
def sink(r, c):
if r < 0 or c < 0 or r >= rows or c >= cols or grid[r][c] != '1':
return
grid[r][c] = '0' # mark visited in place
sink(r + 1, c); sink(r - 1, c); sink(r, c + 1); sink(r, c - 1)
for r in range(rows):
for c in range(cols):
if grid[r][c] == '1':
count += 1
sink(r, c)
return count
Complexity: O(m*n) time, O(m*n) space. LeetCode tags 285 problems with matrix.
Practice on LeetCode:
0/1 Knapsack (Dynamic Programming)
Use it when you must choose a subset under a capacity or budget, and subproblems repeat.
Each item is either taken or skipped, so the answer for a capacity depends only on smaller capacities, which a table fills once instead of re-deriving exponentially.
def can_partition(nums):
total = sum(nums)
if total % 2:
return False
target = total // 2
dp = [False] * (target + 1)
dp[0] = True
for n in nums:
for cap in range(target, n - 1, -1): # backwards: each item once
dp[cap] = dp[cap] or dp[cap - n]
return dp[target]
Complexity: O(n*C) time, O(C) space. LeetCode tags 684 problems with dynamic-programming.
Practice on LeetCode:
Top 'K' Elements
Use it when the question asks for the k largest, k smallest, k most frequent, or k closest.
A heap of size k keeps only the candidates that can still win, which costs O(n log k) instead of the O(n log n) of sorting everything.
import heapq
def kth_largest(nums, k):
heap = []
for n in nums:
heapq.heappush(heap, n)
if len(heap) > k:
heapq.heappop(heap) # drop the smallest candidate
return heap[0]
Complexity: O(n log k) time, O(k) space. LeetCode tags 222 problems with heap-priority-queue.
Practice on LeetCode:
Backtracking
Use it when the question asks for all valid configurations, not just a count or a best one.
You build a candidate one choice at a time and undo the choice on the way out, which explores the whole space while holding only one path in memory.
def permute(nums):
out, path, used = [], [], [False] * len(nums)
def walk():
if len(path) == len(nums):
out.append(path[:]) # copy, the path mutates
return
for i, n in enumerate(nums):
if used[i]:
continue
used[i] = True; path.append(n)
walk()
path.pop(); used[i] = False # undo
walk()
return out
Complexity: O(b^d) time, O(d) space. LeetCode tags 114 problems with backtracking, and it shares the backtracking tag with Subsets.
Practice on LeetCode:
Subsets
Use it when you need every combination, subset, or power set of the input.
Each element is in or out, so the answer set doubles per element, and you can build it iteratively by cloning what you already have.
def subsets(nums):
out = [[]]
for n in nums:
out += [cur + [n] for cur in out] # clone everything, add n
return out
Complexity: O(n * 2^n) time, O(n * 2^n) space. LeetCode tags 114 problems with backtracking, and it shares the backtracking tag with Backtracking.
Practice on LeetCode:
Bitwise XOR
Use it when elements pair up and cancel, or you are asked to find a single missing or unique value.
XOR of a value with itself is zero and XOR is order independent, so every duplicate cancels and the lone survivor is the answer in O(1) space.
def single_number(nums):
out = 0
for n in nums:
out ^= n # pairs cancel to 0
return out
Complexity: O(n) time, O(1) space. LeetCode tags 297 problems with bit-manipulation.
Practice on LeetCode:
Fast & Slow Pointers
Use it when the input is a linked list or an implicit sequence, and you need a cycle, a middle, or a kth-from-end node.
Two pointers at different speeds meet inside a cycle and land the slow one at the middle on a straight run, with no extra memory.
def has_cycle(head):
slow = fast = head
while fast and fast.next:
slow = slow.next # one step
fast = fast.next.next # two steps
if slow is fast:
return True
return False
Complexity: O(n) time, O(1) space. LeetCode tags 263 problems with two-pointers, and it shares the two-pointers tag with Two Pointers.
Practice on LeetCode:
Merge Intervals
Use it when the input is a list of ranges, meetings, or time slots that may overlap.
Once intervals are sorted by start, every overlap is adjacent, so one pass merges or counts them without comparing all pairs.
def merge(intervals):
intervals.sort(key=lambda iv: iv[0])
out = []
for start, end in intervals:
if out and start <= out[-1][1]: # overlaps the previous
out[-1][1] = max(out[-1][1], end)
else:
out.append([start, end])
return out
Complexity: O(n log n) time, O(n) space. LeetCode has no dedicated tag for this one; these sit under array and sorting.
Practice on LeetCode:
Monotonic Stack
Use it when you need the next greater or next smaller element, or the span a value dominates.
A stack kept in sorted order discards elements that can never be an answer again, so every element is pushed and popped at most once.
def daily_temperatures(temps):
out, stack = [0] * len(temps), [] # stack holds indices
for i, t in enumerate(temps):
while stack and temps[stack[-1]] < t:
j = stack.pop()
out[j] = i - j
stack.append(i)
return out
Complexity: O(n) time, O(n) space. LeetCode tags 76 problems with monotonic-stack.
Practice on LeetCode:
Topological Sort
Use it when tasks, courses, or builds have prerequisites, and you need a valid order or a cycle check.
Repeatedly removing nodes with no remaining prerequisites produces a legal order, and a leftover node proves a cycle exists.
from collections import deque
def find_order(n, prereqs):
graph, indeg = [[] for _ in range(n)], [0] * n
for course, need in prereqs:
graph[need].append(course)
indeg[course] += 1
q = deque(i for i in range(n) if indeg[i] == 0)
out = []
while q:
node = q.popleft()
out.append(node)
for nxt in graph[node]:
indeg[nxt] -= 1
if indeg[nxt] == 0:
q.append(nxt)
return out if len(out) == n else [] # short means a cycle
Complexity: O(V+E) time, O(V+E) space. LeetCode tags 40 problems with topological-sort.
Practice on LeetCode:
In-place Reversal of a Linked List
Use it when you must reverse a list or a sublist without allocating a new one.
Rewiring the next pointer of each node as you walk reverses the list in one pass and O(1) extra space.
def reverse_list(head):
prev, cur = None, head
while cur:
nxt = cur.next # save before overwriting
cur.next = prev
prev, cur = cur, nxt
return prev
Complexity: O(n) time, O(1) space. LeetCode tags 82 problems with linked-list.
Practice on LeetCode:
Two Heaps
Use it when you need a running median, or to keep a set split into a smaller half and a larger half.
A max-heap over the low half and a min-heap over the high half put the middle value at the two tops, so the median is O(1) to read.
import heapq
class MedianFinder:
def __init__(self):
self.low, self.high = [], [] # low is a max-heap (negated)
def add(self, num):
heapq.heappush(self.low, -num)
heapq.heappush(self.high, -heapq.heappop(self.low))
if len(self.high) > len(self.low):
heapq.heappush(self.low, -heapq.heappop(self.high))
def median(self):
if len(self.low) > len(self.high):
return -self.low[0]
return (-self.low[0] + self.high[0]) / 2
Complexity: O(log n) insert, O(1) median. LeetCode tags 222 problems with heap-priority-queue, and it shares the heap tag with Top 'K' Elements.
Practice on LeetCode:
Cyclic Sort
Use it when the input is a permutation of numbers in a known range such as 1 to n.
When a value implies its own index, swapping each number home sorts the array in O(n) with no extra space, which exposes missing and duplicate values.
def cyclic_sort(nums):
i = 0
while i < len(nums):
home = nums[i] - 1 # value n belongs at index n-1
if 0 <= home < len(nums) and nums[i] != nums[home]:
nums[i], nums[home] = nums[home], nums[i]
else:
i += 1
return nums
Complexity: O(n) time, O(1) space. LeetCode has no dedicated tag for this one; these sit under array and sorting.
Practice on LeetCode:
K-way Merge
Use it when you are given k sorted lists, arrays, or streams to combine or search across.
A heap holding one candidate from each list always exposes the global smallest next element, so the merge costs O(n log k).
import heapq
def merge_k_sorted(lists):
heap = [(lst[0], i, 0) for i, lst in enumerate(lists) if lst]
heapq.heapify(heap)
out = []
while heap:
val, li, idx = heapq.heappop(heap)
out.append(val)
if idx + 1 < len(lists[li]): # refill from the same list
heapq.heappush(heap, (lists[li][idx + 1], li, idx + 1))
return out
Complexity: O(n log k) time, O(k) space. LeetCode tags 17 problems with merge-sort.
Practice on LeetCode:
Multi-threaded
Use it when the question asks you to coordinate concurrent work, or to enforce an order between threads.
The algorithm is usually trivial; what is graded is whether you reach for the right primitive and avoid a race or a deadlock.
import threading
class Foo:
def __init__(self):
self.second = threading.Semaphore(0)
self.third = threading.Semaphore(0)
def first(self, printFirst):
printFirst()
self.second.release() # unblock the next stage
def second_(self, printSecond):
self.second.acquire()
printSecond()
self.third.release()
def third_(self, printThird):
self.third.acquire()
printThird()
Complexity: depends on the coordination primitive. LeetCode tags 9 problems with concurrency.
Practice on LeetCode:
Which LeetCode Patterns Are Most Important
This is the part most pattern lists leave out. Not every pattern earns the same return, because LeetCode's own problems are not evenly spread across them.
Every question on LeetCode carries one or more topic tags. Counting those tags shows where the problems actually are, which is a better guide to study order than any opinion. Here are the 20 largest tags across the 4,073 problems.
| LeetCode topic tag | Problems |
|---|---|
| Array | 2273 |
| String | 895 |
| Hash Table | 843 |
| Dynamic Programming | 684 |
| Sorting | 540 |
| Greedy | 483 |
| Binary Search | 356 |
| Depth-First Search | 349 |
| Bit Manipulation | 297 |
| Matrix | 285 |
| Prefix Sum | 277 |
| Tree | 270 |
| Two Pointers | 263 |
| Breadth-First Search | 260 |
| Heap (Priority Queue) | 222 |
| Graph | 190 |
| Stack | 182 |
| Sliding Window | 175 |
| Backtracking | 114 |
| Union Find | 98 |
Three things follow from this.
Array, String, and Hash Table are not patterns, they are the surface. They head the list because almost everything is phrased in terms of them. What matters is the technique applied to them, which is why Two Pointers and Sliding Window carry so much weight despite smaller tag counts.
A small set of patterns covers most of the volume. Two Pointers, Sliding Window, Modified Binary Search, the two tree traversals, and Dynamic Programming together account for more tagged problems than the rest of this list combined. If your preparation time is short, those are the ones to install first.
The long tail is still worth knowing, but last. K-way Merge has 17 tagged problems and Multi-threaded has 9. They are rare, and they are also the ones candidates most often have no answer for. Learn them when the common patterns are automatic, not before.
How This Compares With the Other LeetCode Pattern Lists
Three resources come up whenever people look for this, and they are all worth knowing about. They do different jobs, and two of them are free.
Sean Prashad's Leetcode Patterns
seanprashad.com/leetcode-patterns is a free, open source list, and it is the most widely used of the three. Its repository describes it as "a pattern-based approach to learn technical interview questions" and carries 14,117 stars.
What it gives you is a curated set of 179 problems you can filter by difficulty, by company, and by pattern, plus a condition-to-approach table that maps a problem characteristic to a suggested technique. It is excellent for deciding what to solve next, and for working a company-specific list before an onsite.
What it does not do is teach the patterns. The labels it sorts by are mostly LeetCode's own topic tags, around 75 of them, so "Array" and "Hash Table" sit alongside "Sliding Window". If you already know the patterns, that is exactly what you want. If you are trying to learn them, a list cannot explain why a window contracts or when binary search applies to an answer rather than an array.
AlgoMaster's 15 Patterns
AlgoMaster's post covers 15 patterns, each with a diagram, a one-line note on when to use it, and three linked LeetCode problems. It is well made and it is the piece most people have read on this topic.
It stops short of code. There is no template for any of the 15, so you get the idea of a pattern without the implementation you would actually write under time pressure.
NeetCode
NeetCode is a roadmap built around curated problem lists with solution walkthroughs, and it is the strongest option if you prefer to learn by watching rather than reading. We cover it separately rather than summarize it here: the NeetCode roadmap on one page maps the pattern behind each topic, and NeetCode compared with LeetCode puts the numbers side by side.
Where this page fits
This one is the explained version. Every pattern gets the cue that identifies it, why the technique works, a template in Python, a diagram, and three problems, so you can go from never having seen a pattern to writing it from memory without leaving the page.
Use whichever fits what you need right now. If you want a filterable queue of problems, use Sean Prashad's list. If you want video, use NeetCode. If you want to understand the 20 patterns well enough to recognize them on a question you have never seen, read this page and then practice against one of those lists. They work well together, and a free list plus a real explanation beats either on its own.
For a wider view of the paid and free options, including the video courses, see the best DSA courses compared.
How to Use This List
Work one pattern at a time rather than one problem at a time. Read the cue, write the template from memory, then solve the three linked problems in a row. Practicing LeetCode problems pattern wise, meaning grouped by the pattern that solves them rather than in list order, teaches you more than solving ten unrelated ones, because the third problem in a group is where recognition starts to happen on its own.
That is why the 60 problems on this page are grouped under their pattern instead of being given as one flat list. A flat list trains you to grind. Problems grouped by pattern train you to recognize.
When a problem defeats you, do not jump straight to the solution. Ask which of these 20 it resembles first. If you can name the pattern and still cannot finish, that is a template problem and it is quick to fix. If you cannot name the pattern at all, that is the skill actually being tested, and it is the one worth practicing.
The full curriculum, with each pattern taught in six languages and grouped practice problems, is in Grokking the Coding Interview.
Check out Blind75 for more problems. If you are choosing a course to learn these patterns from, The Best DSA Courses Compared: Paid, Free, and YouTube reviews the main options side by side.
FAQs - LeetCode Patterns and Interview Prep
Q1. What are LeetCode patterns?
LeetCode patterns are common coding techniques or strategies that repeatedly show up in LeetCode problems and technical interviews. Instead of solving every problem from scratch, learning these patterns helps you recognize how to approach and solve new problems based on familiar logic (e.g., Two Pointers, Sliding Window, DFS, etc.).
Q2. Why should I learn LeetCode patterns instead of solving random problems?
Focusing on patterns helps you avoid burnout and prepares you faster. Each pattern unlocks the ability to solve dozens of problems, which is much more efficient than solving 500+ random questions without structure. Interviewers often test your ability to apply known patterns to new scenarios, not just memorize solutions.
Q3. How many LeetCode patterns should I learn for FAANG interviews?
Learn all 20, in the order on this page. The first six, Two Pointers, Sliding Window, Modified Binary Search, the two tree traversals, and Dynamic Programming, cover the largest share of what gets asked, so start there if your time is short. The remaining fourteen are what separate a candidate who handles the common question from one who is not stopped by an unusual one.
Q4. Do LeetCode patterns actually help in real interviews?
Yes, most FAANG interview questions map to well-known patterns. Recognizing the right pattern during an interview helps you solve problems faster and with more confidence, especially under time pressure. It also shows your structured thinking, which is exactly what interviewers want.
Q5. Where can I practice LeetCode patterns?
You can start with categorized problem lists on LeetCode itself, or check out structured resources like Grokking the Coding Interview, which teaches these patterns with guided explanations and practice problems grouped by pattern.
Q6. Are LeetCode patterns the same as algorithms?
Not exactly. Algorithms are step-by-step procedures for solving specific types of problems (like Dijkstra’s or Merge Sort). Patterns are reusable problem-solving approaches, like frameworks, that help you decide how to apply different algorithms or data structures depending on the question.
Q7. How do I identify which pattern a question belongs to?
Look at the problem constraints and the goal. For example:
- Need to find a subarray or substring? → Try Sliding Window
- Working with sorted data or binary decisions? → Use Binary Search
- Need to explore all paths or combinations? → Think DFS or Backtracking
The more patterns you practice, the easier it becomes to recognize which one fits.
Q8. Is mastering patterns enough to crack coding interviews?
Patterns are your foundation, but combine them with good communication, mock interviews, and time management. You should also review system design (for senior roles), behavioral interview questions, and understand the company’s specific process.
Q9. What are the best LeetCode patterns to know?
The best LeetCode patterns to focus on are the ones that appear most frequently in coding interviews and help solve a wide variety of problems. These include:
- Two Pointers – great for arrays and strings
- Sliding Window – ideal for subarray/substring problems
- Depth-First Search (DFS) – for tree and graph traversal
- Breadth-First Search (BFS) – used in shortest path and level order problems
- Binary Search – for problems with sorted data or monotonic conditions
- Merge Intervals – useful in scheduling and overlapping intervals
- Dynamic Programming (DP) – for optimization and counting problems
- Recursion & Backtracking – perfect for exhaustive search and decision trees
- Monotonic Stack – for next greater/smaller element problems
- Union-Find (DSU) – for detecting cycles and grouping connected components
Mastering these patterns allows you to recognize problem types quickly and apply efficient solutions, critical for success in FAANG interviews.
Q10. Why study coding patterns for interviews?
Studying coding patterns helps you avoid random practice and prepare more strategically. Instead of solving every problem from scratch, patterns teach you how to recognize the underlying structure of a problem and reuse proven techniques. This saves time, builds confidence, and dramatically improves your problem-solving skills.
Most interview problems are variations of core patterns.
By mastering them, you’ll be able to tackle new problems more quickly, reduce anxiety during live interviews, and demonstrate structured thinking, something interviewers love to see. In short, patterns are the shortcut to smarter and faster coding interview prep.
Go deeper: for the expanded version of this pattern-first approach, see the complete guide to all 42 coding interview patterns, which includes the tell that identifies each pattern from the problem statement, a printable cheat sheet, and free pattern-by-pattern deep dives.
Q11. How many LeetCode patterns are there?
There is no official count, because LeetCode does not publish one. This guide uses 20, which is the set that covers the overwhelming majority of interview questions without padding the list. Other lists quote 14, 15, or 23; the differences are mostly about whether closely related techniques are split apart or grouped together, not about the underlying ideas.
Q12. Are LeetCode patterns the same as design patterns or pattern matching?
No, and the three get confused often.
Design patterns are object-oriented structures such as Singleton, Factory, and Observer. They belong to object-oriented design and low level design rounds, not to the algorithmic patterns on this page. LeetCode does have a separate Design tag, with 134 problems like LRU Cache and Design Twitter, which asks you to build a data structure to a specification. That is a different skill again.
Pattern matching means string matching, regular expressions, and problems like Regular Expression Matching or Wildcard Matching. It is a problem topic, not a solving strategy.
The 20 on this page are coding patterns, also called DSA patterns: reusable strategies for recognizing and solving algorithm questions.
Related questions
- Which is better CodeChef or LeetCode or HackerRank?
- How many LeetCode problems should I do per day?
- What is a good rank on LeetCode?
- How much LeetCode is enough for Google?
- Do Faang companies ask LeetCode hard?
- What is a good acceptance rate on LeetCode?
- What is the most used language on LeetCode?
Originally published on DesignGurus.io.





















Top comments (0)