On this page

All 20 LeetCode Patterns

The 20 Patterns at a Glance

The Most Common LeetCode Patterns

LeetCode Patterns Cheat Sheet: What the Wording Tells You

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

Which LeetCode Patterns Are Most Important

How This Compares With the Other LeetCode Pattern Lists

Sean Prashad's Leetcode Patterns

AlgoMaster's 15 Patterns

NeetCode

Where this page fits

How to Use This List

FAQs - LeetCode Patterns and Interview Prep

Q1. What are LeetCode patterns?

Q2. Why should I learn LeetCode patterns instead of solving random problems?

Q3. How many LeetCode patterns should I learn for FAANG interviews?

Q4. Do LeetCode patterns actually help in real interviews?

Q5. Where can I practice LeetCode patterns?

Q6. Are LeetCode patterns the same as algorithms?

Q7. How do I identify which pattern a question belongs to?

Q8. Is mastering patterns enough to crack coding interviews?

Q9. What are the best LeetCode patterns to know?

Q10. Why study coding patterns for interviews?

Q11. How many LeetCode patterns are there?

Q12. Are LeetCode patterns the same as design patterns or pattern matching?

Related questions

LeetCode Patterns: The Complete List of 20 to Master (With Examples)

Image
Arslan Ahmad
All 20 LeetCode patterns in one place, each with the signal that identifies it, a code template, and three practice problems. Ordered by what each returns on LeetCode.
Image

All 20 LeetCode Patterns

The 20 Patterns at a Glance

The Most Common LeetCode Patterns

LeetCode Patterns Cheat Sheet: What the Wording Tells You

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

Which LeetCode Patterns Are Most Important

How This Compares With the Other LeetCode Pattern Lists

Sean Prashad's Leetcode Patterns

AlgoMaster's 15 Patterns

NeetCode

Where this page fits

How to Use This List

FAQs - LeetCode Patterns and Interview Prep

Q1. What are LeetCode patterns?

Q2. Why should I learn LeetCode patterns instead of solving random problems?

Q3. How many LeetCode patterns should I learn for FAANG interviews?

Q4. Do LeetCode patterns actually help in real interviews?

Q5. Where can I practice LeetCode patterns?

Q6. Are LeetCode patterns the same as algorithms?

Q7. How do I identify which pattern a question belongs to?

Q8. Is mastering patterns enough to crack coding interviews?

Q9. What are the best LeetCode patterns to know?

Q10. Why study coding patterns for interviews?

Q11. How many LeetCode patterns are there?

Q12. Are LeetCode patterns the same as design patterns or pattern matching?

Related questions

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

  1. Two Pointers
  2. Sliding Window
  3. Modified Binary Search
  4. Tree Depth First Search
  5. Tree Breadth First Search
  6. Island (Matrix Traversal)
  7. 0/1 Knapsack (Dynamic Programming)
  8. Top 'K' Elements
  9. Backtracking
  10. Subsets
  11. Bitwise XOR
  12. Fast & Slow Pointers
  13. Merge Intervals
  14. Monotonic Stack
  15. Topological Sort
  16. In-place Reversal of a Linked List
  17. Two Heaps
  18. Cyclic Sort
  19. K-way Merge
  20. Multi-threaded
Image

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.

PatternRecognize it byTimeLeetCode problems
1. Two Pointerssorted input, find a pair or tripletO(n) time263
2. Sliding Windowlongest or shortest contiguous runO(n) time175
3. Modified Binary Searchsorted or rotated, or a testable answerO(log n) time356
4. Tree Depth First Searchroot-to-leaf path, or a subtree answerO(n) time349
5. Tree Breadth First Searchlevels, or fewest stepsO(n) time260
6. Island (Matrix Traversal)a grid, count connected regionsO(m*n) time285
7. 0/1 Knapsack (Dynamic Programming)pick a subset under a capacityO(n*C) time684
8. Top 'K' Elementsk largest, smallest, or most frequentO(n log k) time222
9. Backtrackinglist every valid configurationO(b^d) time114
10. Subsetsevery combination or power setO(n * 2^n) time114
11. Bitwise XORvalues pair off, find the odd one outO(n) time297
12. Fast & Slow Pointerscycle, middle, or kth from the endO(n) time263
13. Merge Intervalsranges or time slots that overlapO(n log n) timeno dedicated tag
14. Monotonic Stacknext greater or next smaller elementO(n) time76
15. Topological Sortprerequisites, ordering, cycle checkO(V+E) time40
16. In-place Reversal of a Linked Listreverse a list without new memoryO(n) time82
17. Two Heapsrunning median, or a split setO(log n) insert222
18. Cyclic Sorta permutation of 1..nO(n) timeno dedicated tag
19. K-way Mergek sorted lists to combineO(n log k) time17
20. Multi-threadedcoordinate or order concurrent workdepends on the coordination primitive9

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 saysReach 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 gridTree 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" elementMonotonic Stack
"prerequisites", "course order", or "build order"Topological Sort
"reverse the list" with O(1) extra spaceIn-place Reversal of a Linked List
"median" of a stream or a windowTwo Heaps
"numbers from 1 to n" with one missing or duplicatedCyclic 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.

Two Pointers pattern diagram

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.

Sliding Window pattern diagram

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:

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.

Modified Binary Search pattern diagram

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:

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.

Tree Depth First Search pattern diagram

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:

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.

Tree Breadth First Search pattern diagram

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:

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.

Island (Matrix Traversal) pattern diagram

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(mn) time, O(mn) 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.

0/1 Knapsack (Dynamic Programming) pattern diagram

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.

Top 'K' Elements pattern diagram

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.

Backtracking pattern diagram

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.

Subsets pattern diagram

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.

Bitwise XOR pattern diagram

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.

Fast & Slow Pointers pattern diagram

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.

Merge Intervals pattern diagram

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.

Monotonic Stack pattern diagram

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.

Topological Sort pattern diagram

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.

In-place Reversal of a Linked List pattern diagram

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.

Two Heaps pattern diagram

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.

Cyclic Sort pattern diagram

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).

K-way Merge pattern diagram

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.

Multi-threaded pattern diagram

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 tagProblems
Array2273
String895
Hash Table843
Dynamic Programming684
Sorting540
Greedy483
Binary Search356
Depth-First Search349
Bit Manipulation297
Matrix285
Prefix Sum277
Tree270
Two Pointers263
Breadth-First Search260
Heap (Priority Queue)222
Graph190
Stack182
Sliding Window175
Backtracking114
Union Find98

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.

Disclosure: this page is published by Design Gurus, and the course linked below is ours. The descriptions of the other resources are limited to what each one publicly shows.

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.

Coding Interview
Coding Interview Questions
Coding Patterns
FAANG
LeetCode

What our users say

ABHISHEK GUPTA

My offer from the top tech company would not have been possible without Grokking System Design. Many thanks!!

Steven Zhang

Just wanted to say thanks for your Grokking the system design interview resource (https://lnkd.in/g4Wii9r7) - it helped me immensely when I was interviewing from Tableau (very little system design exp) and helped me land 18 FAANG+ jobs!

Ashley Pean

Check out Grokking the Coding Interview. Instead of trying out random Algos, they break down the patterns you need to solve them. Helps immensely with retention!

More From Designgurus
Annual Subscription
Get instant access to all current and upcoming courses for one year.

Access to 50+ courses

New content added monthly

Certificate of completion

$31.08

/month

Billed Annually

Recommended Course
Grokking the Coding Interview: Patterns for Coding Questions

Grokking the Coding Interview: Patterns for Coding Questions

196,181+ students

4.6

The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.

View Course
Join our Newsletter

Get the latest system design articles and interview tips delivered to your inbox.

Read More

Low Level Design (LLD) Interview: What It Is and How to Answer One

Arslan Ahmad

Arslan Ahmad

Apple Interview Guide: Process, Questions, and How to Prepare

Arslan Ahmad

Arslan Ahmad

3 Technologies That Will Shape the Future: The Tech Trio

Arslan Ahmad

Arslan Ahmad

OpenAI Full Stack Engineer Interview: Rounds, Questions, and How to Prepare

Arslan Ahmad

Arslan Ahmad

Design Gurus logo
One-Stop Portal For Tech Interviews.
About Us
Our Team
Careers
Partners
Contact Us
Become Affiliate
Copyright © 2026 Design Gurus, LLC. All rights reserved.