Skip to content

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 ​

#PatternThe signal in the question
01Time and Space ComplexityAny constraint on n — it tells you the target complexity
02Prefix SumRepeated range queries over a fixed array
03Two PointersA sorted array, and a pair or triplet to find
04Sliding Window"Longest" or "shortest" contiguous subarray
05Fast and Slow PointersA cycle, a midpoint, or constant extra space required
06In-Place Linked List ReversalReverse a list or a section, allocating nothing
07Monotonic Stack"Next greater" or "next smaller" for every element
08Top K ElementsK largest or most frequent, without sorting everything
09Overlapping IntervalsAny input that is a list of start and end pairs
10Modified Binary SearchSorted-but-rotated, or searching an answer space
11Binary Tree TraversalThe order the problem needs is the traversal it wants
12Depth-First SearchExplore to the depth — paths, islands, connectivity
13Breadth-First SearchShortest path in an unweighted graph, or level by level
14BacktrackingPermutations, combinations, "all possible" anything
15Dynamic ProgrammingOverlapping subproblems and an optimal-substructure smell
16Graph AlgorithmsNodes 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 out O(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:

AskedMid answerSenior 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 problemStarts typingClarifies 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.

The whole book, free to read. Generated from the manuscript on every change.

Your progress

Tick each chapter in the sidebar once you have read and understood it. Your name and email keep the ticks on any device.

Your name and email are stored to save your progress. Nothing else is done with them.