Skip to main content
PatternsLeetCodeInterview Prep

The Complete LeetCode Patterns List — 21 Patterns Explained [2026]

· 12 min read

Syed Peera Saheb

Software Engineer · 5+ years in tech interviews

Summary

Stop grinding random problems. These 21 patterns cover 95% of what you'll see in coding interviews. Learn the pattern, not the problem.

Why patterns beat random grinding

LeetCode has 3,000+ problems. Nobody solves all of them. Top engineers solve 150–300 problems but pick them strategically — one representative problem per sub-pattern until the pattern is internalized. The insight: every "new" problem you see is almost always a combination of 2–3 patterns you already know. Learn the 21 patterns and you have a mental library to draw from.

Array patterns (1–5)

1. Two Pointers — converging on sorted arrays, same-direction for in-place ops, fast/slow for cycles. Signals: sorted array, in-place, "pair sum". 2. Sliding Window — variable or fixed window on arrays/strings. Signals: longest/shortest subarray, "at most k distinct". 3. Prefix Sum — precompute cumulative sums for O(1) range queries. Signals: "sum of subarray", "count subarrays with sum = k". 4. Binary Search — not just on sorted arrays, also on answer space. Signals: sorted data, "minimum X satisfying condition". 5. Merge Intervals — sort by start, merge overlapping. Signals: intervals, "overlapping meetings", "free time".

Linked list and stack patterns (6–9)

6. Linked List In-Place — reversal, slow/fast pointer, merge. No extra memory allowed signals this. 7. Stack — monotonic stack for next greater/smaller element problems. Signals: "next greater", "largest rectangle", "daily temperatures". 8. Monotonic Queue — deque for sliding window maximum/minimum. Signals: sliding window + max/min per window. 9. Hash Map / Set — frequency counting, "seen before", grouping. O(1) lookup makes brute-force O(n²) become O(n).

Tree and graph patterns (10–14)

10. Tree DFS — recursion, all traversal orders. 11. Tree BFS — queue, level-order. 12. Graph BFS — shortest path, multi-source flood fill. 13. Graph DFS — path existence, cycle detection, topological sort. 14. Union-Find — connected components, cycle in undirected graph, merging groups dynamically.

Advanced patterns (15–21)

15. Heap / Priority Queue — top-K elements, K closest, merge K sorted. Signals: "kth largest", "top K", "K closest". 16. Trie — prefix search, autocomplete, word search. 17. Backtracking — permutations, combinations, N-Queens. Prune the search tree aggressively. 18. Dynamic Programming — optimal substructure + overlapping subproblems. 19. Greedy — local optimum leads to global optimum. Signals: interval scheduling, gas station. 20. Bit Manipulation — XOR for find-the-missing/unique, bit masks for subsets, shifts for powers of 2. 21. Math / Number Theory — GCD, prime sieve, modular arithmetic, combinatorics. Appears in hard problems at Google.

How to study the patterns

For each pattern: (1) Read the pattern template and understand the invariant. (2) Solve 3 easy problems to build muscle memory. (3) Solve 5 medium problems — these are interview-level. (4) Solve 1–2 hard problems to understand the ceiling. (5) Without notes, write the template from memory. You do not need to solve every problem — you need to reach the point where you can identify the pattern within 60 seconds of reading a problem statement.

Frequently Asked Questions

How many LeetCode patterns are there?
There are approximately 15-21 core patterns depending on how finely you categorize them. The essential ones for interviews: Two Pointers, Sliding Window, Binary Search, Prefix Sum, Hash Map, Stack (Monotonic), BFS, DFS, Heap, Linked List (Fast/Slow), Trees, Graphs, Union-Find, Backtracking, and Dynamic Programming. Some educators split DP into 5-6 sub-patterns, bringing the total to 21+.
What is the most important LeetCode pattern to learn first?
Start with Hash Map / Hash Set — it is used in 40%+ of interview problems as either the primary approach or a supporting data structure. Then learn Two Pointers and Sliding Window (both O(n) on arrays/strings). Then Binary Search. These four patterns alone cover roughly 60% of easy and medium interview problems and build the foundation for everything else.
Do coding interview patterns change every year?
The core patterns are stable year-over-year because they are based on fundamental computer science — sorting, graph traversal, divide and conquer, dynamic programming. What changes is which specific problems companies ask. The pattern underlying "Design a rate limiter" (sliding window) is the same as "Longest Substring Without Repeating Characters." Learn the pattern, not the problem.
How do I recognize which pattern to use during an interview?
Build a "trigger word" mental map: "contiguous subarray" → Sliding Window. "sorted array + pair/triplet" → Two Pointers. "shortest path" → BFS. "all paths / count arrangements" → DFS or Backtracking. "minimum/maximum of something" → DP or Greedy. "top K" → Heap. "prefix" or "range sum" → Prefix Sum. Practice enough problems per pattern that these triggers become automatic.

Syed Peera Saheb

Software Engineer · 5+ years · ServiceNow

Software engineer with hands-on experience passing technical interviews at top tech companies. Built Coding Prep Guide to share the pattern-first prep strategy that actually works. Writes about DSA, system design, and interview strategy.

Buy me a coffee