Brute2Best ยท DSA Pattern Mastery (30 Core Patterns)
The 30 Core DSA Patterns: Pattern-Based Problem Solving & Questions
Stop memorising disconnected LeetCode problems. Learn to solve the unseen: every question is taught as an unbroken chain of reasoning โ discover the repeated work, define the invariant, and write verified C++23 code.
Overall DSA Progress440 Total
0/440
30 Core Patterns122 Sub-patterns
The 6-Step Thinking Blueprint
Full Blueprint & Decision Tree01
Recognise
Which words & constraints point to a pattern?
02
Brute force
What is the obvious slow solution?
03
Repeated work
What does brute force recompute again & again?
04
State + validity
What invariant do I maintain, and when is it valid?
05
Transitions
When do I move which pointer, and why is it safe?
06
Code + test
Write modern C++23, dry-run edge cases & compare.
Algorithmic Mental Model
6-Step Thinking Blueprint & Clue Tree
Recognise โ brute force โ repeated work โ state โ transitions โ test, plus the visual clue-to-pattern decision tree.
Featured Guided Lesson
Arrays & Hashing
Use a hash map or set to remember what you have already seen, so you never search the array twice.
Categories:Arrays & Strings5Stacks & Intervals4Linked Lists2Trees3Heaps3Graphs4Recursion & Greedy2Dynamic Programming6Math & Bits1
Arrays & Strings
(5 patterns)Arrays & Hashing
lessonWhen to use:"Have I seen X before?", pairs that add up to a target, grouping things that look alike, counting occurrences.
4 sub-patternsOpen
0/12
Two Pointers
lessonWhen to use:Sorted array, pairs/triplets with a target, comparing from both ends, compacting an array in place.
4 sub-patternsOpen
0/22
Sliding Window
lessonWhen to use:Contiguous subarray / substring + longest, shortest, maximum, count, or "of size K".
6 sub-patternsOpen
0/34
Prefix Sum
lessonWhen to use:Range sums, "subarray sum equals K" (especially with negatives), equal counts, divisible by K.
5 sub-patternsOpen
0/18
Binary Search
lessonWhen to use:Sorted data, "minimum X such thatโฆ", "maximum X such thatโฆ", rotated arrays, answers that are monotonic (if X works, X+1 also works).
4 sub-patternsOpen
0/15
Stacks & Intervals
(4 patterns)Stack
lessonWhen to use:Matching pairs, nested structure, undo, evaluating expressions, "the last one wins".
3 sub-patternsOpen
0/10
Monotonic Stack
lessonWhen to use:Next/previous greater or smaller element, spans, histogram areas, "for each element, how far does it dominate?"
5 sub-patternsOpen
0/19
Intervals
lessonWhen to use:Input is [start, end] pairs; overlap, merge, insert, meeting rooms, free time, minimum removals.
4 sub-patternsOpen
0/16
Cyclic Sort
lessonWhen to use:Numbers in range 1..n or 0..n, find missing / duplicate / both, O(1) extra space.
3 sub-patternsOpen
0/9
Linked Lists
(2 patterns)Linked List โ Fast & Slow
lessonWhen to use:Cycle detection, middle of list, "n-th from end", two lists meeting, repeating sequences.
3 sub-patternsOpen
0/13
Linked List โ Reversal
lessonWhen to use:Reverse whole / part / every k nodes, reorder, palindrome check, numbers stored as lists.
4 sub-patternsOpen
0/16
Trees
(3 patterns)Tree BFS
lessonWhen to use:Level order, per-level max/average, right side view, minimum depth, nodes at distance k.
4 sub-patternsOpen
0/14
Tree DFS
lessonWhen to use:Paths, heights, diameters, validating structure, ancestors, anything "for every subtree".
6 sub-patternsOpen
0/26
Trie
lessonWhen to use:Many words + prefix search, autocomplete, word dictionary with wildcards, maximum XOR.
3 sub-patternsOpen
0/7
Heaps
(3 patterns)Heap โ Top K
lessonWhen to use:"K largest / smallest / most frequent / closest", kth element, streaming top-K.
4 sub-patternsOpen
0/12
Two Heaps
lessonWhen to use:Running median, sliding median, choosing from two pools (available vs locked).
3 sub-patternsOpen
0/6
K-way Merge
lessonWhen to use:K sorted lists/arrays, kth smallest across sorted rows, smallest range covering all lists.
3 sub-patternsOpen
0/9
Graphs
(4 patterns)Graph BFS / DFS
lessonWhen to use:Grid of cells, islands, regions, "minimum steps", transformations between states, connected components.
6 sub-patternsOpen
0/24
Topological Sort
lessonWhen to use:Prerequisites, dependencies, build order, "can all courses be finished?", ordering letters from sorted words.
4 sub-patternsOpen
0/15
Union-Find (DSU)
lessonWhen to use:Edges arrive one by one, "are these connected?", merge equivalent items, count components, extra edge creating a cycle.
4 sub-patternsOpen
0/16
Shortest Paths (Weighted)
lessonWhen to use:Weighted edges, "minimum cost / time / effort", at most K stops, negative weights, all-pairs distances.
3 sub-patternsOpen
0/6
Recursion & Greedy
(2 patterns)Backtracking
lessonWhen to use:"All subsets / permutations / combinations", place items under rules (N-Queens, Sudoku), find a path in a grid.
7 sub-patternsOpen
0/20
Greedy
lessonWhen to use:Maximise count / minimise cost with a natural "best next step", sorting makes the choice obvious, reachability.
6 sub-patternsOpen
0/22
Dynamic Programming
(6 patterns)DP โ 1D Linear
lessonWhen to use:"Number of ways", "maximum/minimum up to i", choices at each step that depend on the previous one or two.
3 sub-patternsOpen
0/8
DP โ Kadane / Subarray
lessonWhen to use:Maximum (or minimum) sum/product of a contiguous subarray, stock buy/sell, circular arrays.
4 sub-patternsOpen
0/11
DP โ Knapsack
lessonWhen to use:Pick a subset to hit a target sum / capacity, partition into two groups, count the ways to reach an amount.
4 sub-patternsOpen
0/14
DP โ Longest Increasing Subsequence
lessonWhen to use:Longest chain where each item must be bigger/fit inside the previous one (numbers, pairs, envelopes, words).
3 sub-patternsOpen
0/12
DP โ Grid
lessonWhen to use:Move only right/down, count paths, minimum path cost, largest square of 1s.
2 sub-patternsOpen
0/7
DP โ Strings
lessonWhen to use:Longest common subsequence, edit distance, palindromes, matching with wildcards, interleaving.
4 sub-patternsOpen
0/17