Coding Patterns — Practice These, Not 1000
Random LeetCode Problems
Instead of grinding random problems, master these 21 core patterns. Most interview
problems are just variations of one of these.
Legend
Each pattern covers a specific problem-solving template
5 LeetCode problems per pattern — from easy warm-up to hard stretch
Difficulty: 🟢 Easy · 🟡 Medium · 🔴 Hard
The Patterns
# Pattern When to Use Problem 1 Problem 2 Problem 3 Problem 4 Problem 5
1 Two Pointers Sorted array/string; 🟢 Valid 🟡 Two 🟡 3Sum 🟡 🔴
find pairs, triplets, or Palindrom Sum II #15 Container Trapping
squeeze from both e #125 #167 With Most Rain Water
ends Water #11 #42
2 Sliding Contiguous 🟡 🟡 🟡 🔴 🔴 Sliding
Window subarray/substring Longest Permutatio Longest Minimum Window
with a constraint Substring n in String Repeating Window Maximum
(size, sum, unique Without #567 Character Substring #239
chars) Repeating Replaceme #76
Characters nt #424
#3
3 Fast & Slow Cycle detection in 🟢 Linked 🟢 Middle 🟡 Linked 🟡 Happy 🟡 Find
Pointers linked list or array; List Cycle of the List Cycle Number the
find middle of list #141 Linked List II #142 #202 Duplicate
#876 Number
#287
4 Merge Overlapping intervals; 🟡 Merge 🟡 Insert 🟡 Non- 🟡 Meeting 🔴
Intervals scheduling; range Intervals Interval overlappin Rooms II Employee
merging #56 #57 g Intervals #253 Free Time
#435 #759
5 Cyclic Sort Array contains 🟢 Missing 🟡 Find 🟡 Find All 🟡 Find All 🔴 First
numbers in range [1, Number the Numbers Duplicates Missing
n]; find #268 Duplicate Disappear in an Array Positive
missing/duplicate Number ed in an #442 #41
#287 Array
#448
Coding Patterns — 21 Core Patterns 1/4
6 In-place Reverse all or part of 🟢 🟡 🟡 🟡 Reorder 🔴
Reversal of a linked list without Reverse Reverse Palindrome List #143 Reverse
Linked List extra space Linked List Linked List Linked List Nodes in
#206 II #92 #234 k-Group
#25
7 Tree BFS Level-by-level 🟢 🟡 Binary 🟡 Binary 🟡 Binary 🟡
(Level Order) processing; shortest Symmetric Tree Level Tree Right Tree Populating
path in unweighted Tree #101 Order Side View Zigzag Next Right
tree Traversal #199 Level Pointers in
#102 Order Each Node
Traversal #116
#103
8 Tree DFS (Path Root-to-leaf paths; 🟢 Path 🟡 Path 🟡 Sum 🟡 Path 🔴 Binary
Problems) tree sums; tree Sum #112 Sum II Root to Sum III Tree
structure validation #113 Leaf #437 Maximum
Numbers Path Sum
#129 #124
9 Two Heaps Stream of numbers; 🔴 Find 🔴 Sliding 🔴 IPO 🔴 🔴
median; find elements Median Window #502 Maximum Minimize
from two halves from Data Median Performan Deviation
simultaneously Stream #480 ce of a in Array
#295 Team #1675
#1383
10 Subsets / Enumerate all 🟡 🟡 🟡 🟡 🔴
Backtracking combinations, Subsets Subsets II Permutatio Combinatio Palindrom
permutations, or #78 #90 ns #46 n Sum #39 e
power sets Partitionin
g #131
11 Binary Search Sorted input; "find X" 🟢 Binary 🟡 Find 🟡 Search 🟡 Find 🔴 Median
in O(log n); search on Search Minimum in Rotated Peak of Two
answer space #704 in Rotated Sorted Element Sorted
Sorted Array #33 #162 Arrays #4
Array #153
12 Top K Kth largest/smallest; 🟡 Kth 🟡 Top K 🟡K 🟡 Top K 🔴 Find K
Elements top K frequent; K Largest Frequent Closest Frequent Pairs with
(Heap) closest Element in Elements Points to Words Smallest
an Array #347 Origin #692 Sums
#215 #973 #373
13 K-way Merge Merge K sorted 🔴 Merge 🟡 Kth 🔴 🔴 Find K 🔴 K-th
arrays/lists; kth k Sorted Smallest Smallest Pairs with Smallest
smallest across K Lists #23 Element in Range Smallest Prime
sorted structures a Sorted Covering Sums #373 Fraction
Matrix Elements #786
#378 from K
Lists #632
Coding Patterns — 21 Core Patterns 2/4
14 Dynamic Optimal substructure 🟢 🟡 House 🟡 🟡 Coin 🟡 Word
Programming in sequences; Climbing Robber Longest Change Break
— 1D counting paths; Stairs #70 #198 Increasing #322 #139
max/min over choices Subseque
nce #300
15 Dynamic Grid paths; string 🟡 Unique 🟡 🟡 🔴 Edit 🔴 Burst
Programming matching; subset Paths #62 Longest Partition Distance Balloons
— 2D / Interval sum; knapsack Common Equal #72 #312
Subseque Subset
nce #1143 Sum #416
16 Topological Dependency 🟡 Course 🟡 Course 🟡 Find 🟡 🔴
Sort (Graph) ordering; detect cycle Schedule Schedule II Order of Minimum Sequence
in directed graph; #207 #210 Characters Height Reconstru
course scheduling (Alien Trees #310 ction #444
Dictionary)
#269
17 Graph BFS / Connected 🟡 🟡 Clone 🟡 Max 🟡 Pacific 🔴 Word
DFS components; shortest Number of Graph Area of Atlantic Ladder
path (unweighted); Islands #133 Island Water Flow #127
island problems #200 #695 #417
18 Union Find Dynamic connectivity; 🟡 🟡 🟡 🟡 Number 🔴
(Disjoint Set) grouping elements; Number of Redundant Accounts of Smallest
cycle detection in Provinces Connectio Merge Operations String
undirected graph #547 n #684 #721 to Make With
Network Swaps
Connected #1202
#1319
19 Monotonic Next greater/smaller 🟢 Next 🟡 Daily 🟡 Online 🔴 Largest 🔴
Stack element; histogram Greater Temperatu Stock Rectangle Trapping
areas; span problems Element I res #739 Span #901 in Rain Water
#496 Histogram #42
#84
20 Prefix Sum / Subarray sum equals 🟡 🟡 🟡 🟡 Path 🟡 Count
Hash Map K; count subarrays Subarray Continuou Subarray Sum III Number of
with property; running Sum s Subarray Sums #437 Nice
totals Equals K Sum #523 Divisible Subarrays
#560 by K #974 #1248
21 Trie (Prefix String search with 🟡 🟡 Design 🟡 Replace 🟡 Index 🔴 Word
Tree) prefix matching; Implement Add and Words Pairs of a Search II
autocomplete; word Trie (Prefix Search #648 String #212
dictionaries Tree) #208 Words #1065
Data
Structure
#211
Coding Patterns — 21 Core Patterns 3/4
Study Order Recommendation
Week 1-2 → Two Pointers · Sliding Window · Fast & Slow Pointers · Binary Search
Week 3-4 → Tree BFS · Tree DFS · Merge Intervals · Cyclic Sort
Week 5-6 → Top K Elements · Two Heaps · K-way Merge · Monotonic Stack
Week 7-8 → Subsets/Backtracking · DP 1D · DP 2D
Week 9-10 → Graph BFS/DFS · Topological Sort · Union Find · Trie · Prefix Sum
Pattern Recognition Cheatsheet
Signal in the problem Most likely pattern
Sorted array + find pair/triplet Two Pointers
Contiguous subarray + sum/length constraint Sliding Window
Linked list + cycle or middle Fast & Slow Pointers
Overlapping date/time ranges Merge Intervals
Array with numbers 1–N, find missing/duplicate Cyclic Sort
Reverse part of a linked list In-place Reversal
Process tree level by level Tree BFS
Root-to-leaf path sum Tree DFS
Running median / two halves Two Heaps
All combinations / permutations Backtracking
Sorted input, O(log n) target Binary Search
Kth largest/smallest Top K Elements (Heap)
Merge K sorted structures K-way Merge
Count/max/min over sequences Dynamic Programming
Dependencies / ordering tasks Topological Sort
Island / connected component problems Graph BFS/DFS
Dynamic grouping / cycle in undirected graph Union Find
Next greater / smaller element Monotonic Stack
Subarray sum equals K Prefix Sum + Hash Map
Prefix word search / autocomplete Trie
Coding Patterns — 21 Core Patterns 4/4