LeetCode Patterns: The 15 You Must Know
Master these 15 coding patterns and you can solve 90% of the problems that show up in real FAANG interviews. Stop grinding random problems — learn the patterns instead.
Why Patterns Beat Problem Memorization
There are over 3,000 problems on LeetCode. You cannot memorize them all, and you shouldn't try. What you can do is recognize that most problems are variations on a small set of underlying patterns. Once you see that a problem is a sliding window problem, the solution structure becomes clear even if you've never seen that exact problem before.
Pattern recognition is also more robust under interview pressure. When you're nervous, recall breaks down — but pattern matching is more automatic. Training yourself to identify the pattern first, then apply the template, is the professional way to prepare.
The 15 Core Patterns
1. Two Pointers
Use when working with sorted arrays or when you need to find pairs/triplets. Classic problems: 3Sum, Container With Most Water, Trapping Rain Water.
2. Sliding Window
Use for finding subarrays/substrings that satisfy a condition. Look for 'contiguous subarray' or 'substring' in the problem. Classic: Longest Substring Without Repeating Characters, Minimum Window Substring.
3. Fast & Slow Pointers
Use for linked list cycle detection, finding middle nodes, or palindrome checking. The tortoise and hare algorithm. Classic: Linked List Cycle, Happy Number.
4. Binary Search
Beyond sorted arrays — use when the search space is monotonic. If you can ask 'can I achieve X?' and the answer transitions from yes to no (or no to yes), binary search applies. Classic: Search in Rotated Array, Capacity to Ship Packages.
5. BFS (Breadth-First Search)
Use for shortest paths in unweighted graphs, level-order traversals, or finding minimum steps. Classic: Binary Tree Level Order Traversal, Word Ladder, Rotting Oranges.
6. DFS (Depth-First Search)
Use for exploring all paths, backtracking, connected components, and tree traversals. Classic: Number of Islands, Course Schedule, Path Sum.
7. Dynamic Programming
The hardest pattern to master. Look for: overlapping subproblems and optimal substructure. Break into 1D DP, 2D DP, and interval DP. Classic: Coin Change, Longest Common Subsequence, Edit Distance.
8. Merge Intervals
Use when given a list of intervals and asked to merge, insert, or check for overlap. Classic: Merge Intervals, Insert Interval, Meeting Rooms.
9. Cyclic Sort
Use when given a range 1 to N and asked to find missing/duplicate numbers. O(n) time, O(1) space. Classic: Find Missing Number, Find Duplicate.
10. In-place Reversal of Linked List
Use for reversing linked lists or sublists. Classic: Reverse Linked List, Reverse Nodes in k-Group.
11. Tree BFS / DFS
Level-order traversal = BFS. Path problems, root-to-leaf = DFS. Know both recursively and iteratively. Classic: Maximum Depth, Zigzag Level Order, Path Sum III.
12. Heap / Priority Queue
Use when repeatedly finding min or max. Two heaps pattern for median finding. Classic: Kth Largest Element, Find Median from Data Stream, Task Scheduler.
13. Monotonic Stack
Use for next greater/smaller element problems and histogram-type problems. Classic: Daily Temperatures, Largest Rectangle in Histogram, Next Greater Element.
14. Union-Find (Disjoint Set)
Use for connectivity problems, detecting cycles in undirected graphs. Classic: Number of Connected Components, Redundant Connection, Accounts Merge.
15. Trie (Prefix Tree)
Use for prefix-based search, autocomplete, and word dictionaries. Classic: Implement Trie, Word Search II, Design Add and Search Words.
How to Use This in Your Prep
Don't try to cover all 15 patterns at once. Spend a full week on a single pattern: watch one explanation video, solve 3 easy problems to understand the template, then solve 5–8 medium problems to internalize variations. By the end of the week you should be able to identify the pattern in under 30 seconds and write the solution structure without thinking.
Then combine this with company-specific frequency data. If you're targeting a company that asks a lot of dynamic programming problems, spend two weeks on DP variants instead of one. If the company leans toward graph problems, prioritize BFS/DFS/Union-Find. Real interview data from LeakCode gives you this calibration signal.
Find the Highest-Frequency Coding Questions at Your Target Company
Real interview reports from 10+ sources, ranked by how often each question appears.
Browse by Company