Appendix — DSA Patterns
Sixteen patterns, kept because the reader still has to pass the round, and demoted to an appendix because pattern recognition is not what this book is about. Nothing here will make you a better engineer. It will make you faster at the forty-five minutes that stand between you and the parts of the job the other nine parts cover.
The organising claim is that almost every algorithm question in a hiring loop is one of a small number of shapes wearing a costume. The work is recognising the shape, not inventing the algorithm. Each chapter is built for that: what the pattern is, the signal in the question that gives it away, one template worth memorising, two worked examples, the complexity, and a curated problem list.
Chapters
| # | Pattern | The signal in the question |
|---|---|---|
| 01 | Time and Space Complexity | Any constraint on n — it tells you the target complexity |
| 02 | Prefix Sum | Repeated range queries over a fixed array |
| 03 | Two Pointers | A sorted array, and a pair or triplet to find |
| 04 | Sliding Window | "Longest" or "shortest" contiguous subarray |
| 05 | Fast and Slow Pointers | A cycle, a midpoint, or constant extra space required |
| 06 | In-Place Linked List Reversal | Reverse a list or a section, allocating nothing |
| 07 | Monotonic Stack | "Next greater" or "next smaller" for every element |
| 08 | Top K Elements | K largest or most frequent, without sorting everything |
| 09 | Overlapping Intervals | Any input that is a list of start and end pairs |
| 10 | Modified Binary Search | Sorted-but-rotated, or searching an answer space |
| 11 | Binary Tree Traversal | The order the problem needs is the traversal it wants |
| 12 | Depth-First Search | Explore to the depth — paths, islands, connectivity |
| 13 | Breadth-First Search | Shortest path in an unweighted graph, or level by level |
| 14 | Backtracking | Permutations, combinations, "all possible" anything |
| 15 | Dynamic Programming | Overlapping subproblems and an optimal-substructure smell |
| 16 | Graph Algorithms | Nodes and edges, weighted paths, ordering with dependencies |
What Interviewers Probe For
There is no senior signal for this appendix in BOOK-SPEC.md, because the round is not scored the way the rest of the book is. What is being watched:
- Do you clarify before you code? Input range, duplicates, empty input, and whether the array is sorted. Thirty seconds here changes which pattern you reach for.
- Can you state the complexity, and the target? A constraint of
n ≤ 10⁵rules outO(n²)and says so out loud. Reading the constraint as a hint is the fastest way to look experienced. - Do you narrate the approach before typing? Interviewers score the method. A stated plan that turns out wrong is recoverable; silent code that turns out wrong is not.
- Can you test your own solution? Walking one example and one edge case through the finished code, unprompted, closes the round well and catches roughly half of all off-by-one errors.
Mid or senior, on the same question:
| Asked | Mid answer | Senior answer |
|---|---|---|
Given n ≤ 10⁵ | Writes the nested loop and hopes | "That rules out O(n²), so this is a hash map or a sorted two-pointer pass" |
| Handed the problem | Starts typing | Clarifies duplicates, empty input and sortedness, then states the plan before typing |
| Solution finished | "That should work" | Walks one normal case and one edge case through the code, unprompted |
Reading Order
01 first — the complexity chapter is the one that makes the others legible. Then straight through: 02 to 10 are array, string and pointer patterns; 11 to 16 are trees and graphs, and get progressively harder. Do not skip 03 and 04; they underpin more questions than any other pair here.
Interview sprint: 01 → 03 → 04 → 13 → 15. Complexity, two pointers, sliding window, BFS and dynamic programming between them cover the majority of what gets asked.
⚠️ Each chapter teaches recognition, not every solution. You get the pattern's signals, how it works, the common mistakes and a curated problem table. Solve those problems yourself: recognising the pattern under time pressure is the skill the round tests.