The Top 20 study Patterns

Over years of accumulated LC problem taxonomies (NeetCode, Sean Prashad’s list, Grokking the Coding study, and thousands of company-tagged questions), the community has converged on roughly 20 patterns that cover ~80% of medium/hard study problems. Learn to recognize which of these a problem uses within the first 60 seconds of reading it, and you’ve done most of the work.

The 20, Ranked by study Frequency

Ranking is approximate frequency observed across FAANG-tagged problems in mid-2026. Your priorities should mirror the top of this list.

1. Hashmap / Set Lookup

Cue words: “find”, “count”, “contains”, “anagram”, “duplicate.” Templates: single-pass build; two-pass build-then-scan; sliding window with counts. C notes: use uthash.h on LC, libprep::map for your own code. int[26] when the alphabet is bounded. Examples: Two Sum, Group Anagrams, Contains Duplicate, Longest Consecutive Sequence.

2. Two Pointers

Cue words: “sorted array,” “pair,” “triple,” “palindrome.” Templates: opposite ends converging; same direction fast-slow. C notes: pure index arithmetic; native. Examples: Two Sum II, 3Sum, Container With Most Water, Valid Palindrome, Remove Duplicates.

3. Sliding Window

Cue words: “longest/shortest substring,” “subarray with property,” “window of size K.” Templates: variable window with left/right; fixed window with rolling stats. C notes: state usually needs a small hashmap or int[26]. Examples: Longest Substring Without Repeating, Minimum Window Substring, Permutation in String.

5. BFS on Trees / Graphs / Grids

Cue words: “level order,” “shortest path in unweighted,” “minimum steps.” Templates: queue-based; multi-source variant with all sources initial. C notes: libprep::queue is a requirement here. Examples: Binary Tree Level Order Traversal, Rotting Oranges, Word Ladder, Shortest Path in Binary Matrix.

6. DFS on Trees / Graphs

Cue words: “all paths,” “connected components,” “exists a path.” Templates: recursive (default); iterative with explicit stack for deep graphs. C notes: watch recursion depth; V ≤ 10⁴ recursion OK, above that iterate. Examples: Number of Islands, Clone Graph, Path Sum, All Paths From Source to Target.

7. Backtracking

Cue words: “all combinations,” “all permutations,” “generate all.” Templates: recurse-choose-recurse-unchoose; prune with constraints. C notes: pass a path array and a path_len to avoid allocation per recursion. Examples: Subsets, Permutations, Combination Sum, N-Queens, Word Search.

8. Dynamic Programming (1-D)

Cue words: “count ways,” “max/min sum,” “minimum operations.” Templates: dp[i] = answer for prefix; rolling variables when window is small. C notes: long long for accumulators; INT_MAX/2 for “infinity” to avoid overflow when adding. Examples: Climbing Stairs, House Robber, Coin Change, Longest Increasing Subsequence.

9. Dynamic Programming (2-D)

Cue words: “two strings,” “grid,” “matrix path.” Templates: dp[i][j] for two-sequence or grid state. C notes: flat int* with i * cols + j indexing beats int** for cache. Examples: Unique Paths, Edit Distance, Longest Common Subsequence, Coin Change II.

10. Fast & Slow Pointers (Floyd)

Cue words: “cycle,” “middle of list,” “find duplicate number.” Templates: tortoise/hare; Brent’s variant occasionally. C notes: linked-list native; on arrays, use indices as “next pointers.” Examples: Linked List Cycle II, Happy Number, Find the Duplicate Number.

11. Monotonic Stack / Queue

Cue words: “next greater element,” “largest rectangle,” “sliding window maximum.” Templates: push while maintaining monotone invariant; pop when violated. C notes: array-backed stack in libprep::vec doubles as monotonic stack. Examples: Daily Temperatures, Largest Rectangle in Histogram, Sliding Window Maximum, Next Greater Element.

12. Heap / Priority Queue

Cue words: “top K,” “K-th largest/smallest,” “merge K sorted,” “median from stream.” Templates: min-heap of size K; two-heaps trick; Dijkstra. C notes: libprep::heap — write once, use forever. Examples: Kth Largest, Top K Frequent, Merge K Sorted Lists, Find Median from Data Stream.

13. Union-Find (Disjoint Set Union)

Cue words: “connected components,” “detect cycle in undirected,” “merge accounts.” Templates: path compression + union by rank. C notes: two int arrays (parent, rank); tiny. Examples: Redundant Connection, Number of Connected Components, Graph Valid Tree, Accounts Merge.

14. Topological Sort

Cue words: “schedule tasks,” “prerequisites,” “dependency order.” Templates: Kahn’s (BFS on in-degrees); DFS post-order reversed. C notes: needs adjacency list + queue. Examples: Course Schedule I & II, Alien Dictionary, Minimum Height Trees.

15. Prefix Sum / Difference Array

Cue words: “subarray sum,” “range queries,” “cumulative.” Templates: 1-D prefix + hashmap; 2-D prefix for matrix queries. C notes: long long prefix array when values are large. Examples: Subarray Sum Equals K, Range Sum Query, Number of Subarrays with Bounded Max.

16. Bit Manipulation

Cue words: “XOR,” “single/duplicate,” “count set bits,” “subsets via bitmask.” Templates: XOR pairing; __builtin_popcount; bitmask DP. C notes: C’s home turf; use __builtin_* intrinsics without shame. Examples: Single Number, Counting Bits, Sum of Two Integers, Missing Number, Traveling Salesman (bitmask DP).

17. Intervals / Sweep Line

Cue words: “merge intervals,” “conflict,” “schedule.” Templates: sort by start; scan and merge. C notes: qsort with a comparator function pointer. Examples: Merge Intervals, Insert Interval, Meeting Rooms II, Non-Overlapping Intervals.

18. Greedy

Cue words: “minimum coins,” “maximum profit,” “cover with fewest.” Templates: sort by a key, then linear scan making locally optimal choices. C notes: qsort again. Examples: Jump Game, Gas Station, Task Scheduler, Best Time to Buy and Sell Stock II.

19. Trie (Prefix Tree)

Cue words: “prefix,” “autocomplete,” “dictionary,” “word search with dictionary.” Templates: TrieNode.children[26], is_word flag. C notes: calloc per node; free the tree on cleanup. Examples: Implement Trie, Word Search II, Add and Search Word, Longest Common Prefix.

20. Segment Tree / Fenwick (BIT)

Cue words: “range update AND range query,” “K-th smallest with updates.” Templates: Fenwick for prefix-sum updates + queries; segment tree for arbitrary associative ops. C notes: Fenwick is ~10 lines; segment tree is ~40. Rarely tested but a strong flex. Examples: Range Sum Query Mutable, Count of Smaller Numbers After Self, Range Sum Query 2D Mutable.

How to Actually Use This List

When you read a new problem, spend 60 seconds classifying it into one of these 20 buckets before writing a line of code. study partners spot the difference between “pattern-matched confidently” and “reinvented the wheel with panic.”

Study Order (Revised for M4-M5)

  1. Weeks 1-2: patterns 1-4 (hashmap, two pointers, sliding window, binary search) — fastest wins.

  2. Weeks 3-4: patterns 5-9 (BFS, DFS, backtracking, 1-D DP, 2-D DP) — core coverage.

  3. Weeks 5-6: patterns 10-15 (fast-slow, monotonic stack, heap, union-find, topo, prefix sum) — depth.

  4. Weeks 7-8: patterns 16-20 (bits, intervals, greedy, trie, segment tree/Fenwick) — finish and polish.

By week 4, you should have libprep in usable shape (vec, map, heap, queue, stack, DSU).

The 80/20 Truth

Patterns 1-9 will cover the vast majority of study problems you see. Patterns 10-15 will make you look competent on medium problems that trip up less-prepared candidates. Patterns 16-20 are your differentiators — they’re what the study partner says “nice touch” about. Don’t skip them, but budget your time in that priority order.

What Most People Get Wrong About This

They treat pattern-matching as memorization instead of decomposition. Real problems combine two or three patterns (sliding window + hashmap, DFS + memoization = top-down DP, monotonic stack + prefix sum). What you’re training is not the ability to recognize one pattern; it’s the ability to decompose a problem into the two or three patterns whose composition is the solution. Once you feel that, medium problems collapse.


Return to README.md · Next: 09_c_specific_pitfalls_in_interviews.md