leetcode-textbook

01 - Patterns Overview (Cheat Sheet)

This is the single most important page in the book. Print it. Bookmark it. When a new problem appears, scan the “Trigger signals” column first.

Each pattern below has its own folder under patterns/ with a full README.md template.


Quick decision table

If the problem involves… Use pattern Section
Counting, existence, grouping, frequency Arrays & Hashing 1
Sorted array, “find pair / triplet” Two Pointers 2
“Longest / shortest subarray with property X” Sliding Window 3
“Next greater”, “valid parentheses”, “recent” Stack 4
Sorted data, “find in O(log n)” Binary Search 5
Linked list, “reverse”, “cycle”, “merge” Linked List 6
Trees, “depth”, “level order”, “validate” Trees 7
“Word starts with”, “autocomplete” Tries 8
“Top K”, “Kth largest”, scheduling Heap / PQ 9
“All permutations / combinations / subsets” Backtracking 10
Grid, network, “connected”, “shortest path” Graphs 11
“Minimum steps / cost”, locally-best choice Greedy 12
Ranges, meetings, “merge intervals” Intervals 13
“How many ways”, “max/min over choices” 1-D DP 14
2-D grid paths, two-string edit distance 2-D DP 15
XOR, “without extra space”, power of 2 Bit Manipulation 16

The 16 patterns in depth

1. Arrays & Hashing

2. Two Pointers

3. Sliding Window

4. Stack

6. Linked List

7. Trees

8. Tries

9. Heap / Priority Queue

10. Backtracking

11. Graphs

12. Greedy

13. Intervals

14. 1-D Dynamic Programming

15. 2-D Dynamic Programming

16. Bit Manipulation


How patterns combine

Real interview problems often blend patterns. Examples:

Once the 16 individual patterns are automatic, combinations become easy to recognize.


Next: 02-complexity-cheatsheet.md