DSA Crash Course
17 FAANG Patterns

17 FAANG Patterns — Overview

Mark when done:

Phase 3 -- The 17 FAANG Coding Patterns (Days 23-38)

Goal: Transform topic knowledge into pattern recognition speed. This is the bridge between "I know arrays" and "I instantly see this is a sliding window problem."

Pre-req: Complete Phases 1-2 first. Read how-to-think.md if you haven't.

Why This Phase Exists (Read First)

Phase 1 and 2 taught you topics in blocked practice — all arrays in one block, all DP in another. Blocked practice feels productive but produces shallow learning. Research on retrieval practice (Roediger & Karpicke, 2006) and interleaved practice (Rohrer & Taylor, 2007) shows that:

  1. Re-solving without notes beats re-reading. Your goal in Phase 3 is not to learn new content. It is to retrieve what you've already seen, under time pressure, without scaffolding. Each successful retrieval strengthens the pattern's neural trace far more than re-reading the README would.
  2. Mixing patterns within a session forces real recognition. When all problems in a session are sliding-window problems, your brain doesn't have to recognise the pattern — it knows. Phase 3's mixed days (37-38) are deliberately designed to remove that crutch.
  3. The bottleneck in real interviews is identification, not implementation. You don't fail because you can't write BFS. You fail because, given a new problem, you don't see that it's a BFS problem in the first 60 seconds.

Diagnose Your Failures

When a Phase 3 problem stumps you, the failure type tells you where to revisit:

Failure modeWhat it meansWhere to go back
Picked the wrong patternYou haven't built the "this shape → this pattern" lookup yetRe-read how-to-think.md Step 3 ("Pattern Recognition") + the pattern's "Key Signal" column below
Right pattern, wrong implementationPattern recognised but the template muscle isn't theretemplates.py — copy the relevant template and adapt it
Right answer, wrong complexityTime/space estimate was offPhase 0 Big-O cheat sheet + the module-specific complexity table
Couldn't even startThe underlying topic isn't solid yetGo back to the Phase 1 or Phase 2 module that owns the topic

What "Identify Pattern Before Coding" Looks Like

For Day 37-38 mixed practice, your literal sequence on each problem is:

1. Read the problem twice. DO NOT scroll to hints.
2. Write down on paper, BEFORE coding:
   - Pattern guess (one of the 17 below)
   - Why you think so (one signal sentence — e.g. "sorted array + pair = Two Pointers")
   - Expected time / space complexity
3. Now solve. If your guess was right and your complexity matched, full credit.
   If you guessed wrong, study the actual pattern signal you missed.
4. Whether you got it right or wrong, log the pair (your guess, actual) in the
   accuracy log at the bottom of this file.

A single problem solved this way teaches more than three problems solved by jumping straight to code.

How Phase 3 Works

Phase 3 is NOT about learning new topics. It's about speed and recognition.

Daily Routine (Days 23-38)

1. Pick a pattern from the tracker below (work top to bottom)
2. Re-read the "When to Recognize" signals
3. Solve 2-3 NEW problems for that pattern (from LeetCode, filtered by tag)
4. Re-solve 1-2 problems from Phase 1-2 that use this pattern -- TIMED
   - Easy: must finish in 10 min
   - Medium: must finish in 20 min
   - Hard: must finish in 30 min
5. If you can't finish timed -> add to the redo queue
6. End of day: quiz yourself -- "given this problem statement, which pattern?"

Pattern Rotation Schedule

DaysPatterns to DrillSource
23-24Two Pointers, Fast & Slow, Sliding WindowPhase 2 modules 2-3
25-26BFS, DFS, BacktrackingPhase 2 modules 4-5
27-28Binary Search (classic + on answer), Prefix SumPhase 2 module 1, Phase 1 module 2
29-30Dynamic Programming (1D, 2D, knapsack)Phase 2 module 7
31-32Merge Intervals, Greedy, Monotonic Stack/QueuePhase 2 module 6, Phase 1 module 6
33-34Top K / Heaps, Two Heaps, K-way MergePhase 1 module 8
35-36Topological Sort, Union-Find, Cyclic SortPhase 1 module 9, Phase 4 preview
37-38MIXED -- random problems, identify pattern before solvingAll

The Mixed Practice Protocol (Days 37-38)

This is the most important part. On these days:

1. Go to leetcode.com/problemset/ -> filter Medium -> Random
2. Read the problem. Do NOT look at tags.
3. BEFORE coding, write down: "I think this is [PATTERN] because [SIGNAL]"
4. Then solve. Check if your pattern guess was right.
5. Track accuracy: __/10 correct pattern identifications

Pattern Mastery Tracker

Mark [x] when you can solve 3+ problems with this pattern in under 20 min each.

#PatternConfident?Key SignalTemplate in templates.py
1Two Pointers[ ]Sorted input, find pair/triplettwo_pointers_opposite()
2Fast & Slow Pointers[ ]Cycle detection, middle findingfast_slow_pointers()
3Sliding Window[ ]Contiguous subarray/substringsliding_window_variable()
4Merge Intervals[ ]Overlapping intervalsmerge_intervals()
5Cyclic Sort[ ]Array with range [1,n]Index placement
6In-place LL Reversal[ ]Reverse part of LLreverse_linked_list()
7BFS (Tree/Graph)[ ]Level order, shortest pathbfs()
8DFS (Tree/Graph)[ ]All paths, deep explorationdfs() / dfs_grid()
9Two Heaps[ ]Median, balanced partitionMedianFinder
10Subsets / Backtracking[ ]Combinations, permutationsbacktrack()
11Modified Binary Search[ ]Sorted with twistbinary_search()
12Top K Elements[ ]K largest/smallest/frequentHeap pattern
13K-way Merge[ ]K sorted sourcesMin-heap of heads
14Topological Sort[ ]Dependencies, orderingtopological_sort()
15Dynamic Programming[ ]Overlapping subproblemsdp_1d() / dp_2d_strings()
16Prefix Sum[ ]Range queries, subarray sumsprefix_sum()
17Monotonic Stack/Queue[ ]Next greater/smaller, window extremesnext_greater_element()

Each pattern has its own folder. Open the folder README for the pattern's thinking guide. Use the extra practice problems below for deliberate drilling, or pick fresh problems from LeetCode filtered by the matching topic tag.


Pattern Recognition Cheat Sheet

"Subarray / Substring"          -> Sliding Window / Two Pointers
"Sorted array + target"         -> Two Pointers / Binary Search
"Top/Kth largest/smallest"      -> Heap
"All combinations/permutations" -> Backtracking
"Tree level by level"           -> BFS
"Shortest path (unweighted)"    -> BFS
"Dependencies / ordering"       -> Topological Sort
"Overlapping intervals"         -> Sort + Merge
"Maximum/Minimum cost/ways"     -> DP
"Linked list cycle"             -> Fast & Slow
"Connected components"          -> DFS / BFS / Union-Find
"Range sum / subarray sum = K"  -> Prefix Sum + HashMap
"Next greater/smaller element"  -> Monotonic Stack
"Sliding window max/min"        -> Monotonic Queue (Deque)
"Matrix traversal / rotation"   -> In-place / Layer-by-layer

Extra Practice Problems (Phase 3 Additions)

These are additional problems NOT in Phase 1-2. Use them for pattern drilling.

#ProblemPatternDifficultyTimeStatus
1Find K Closest ElementsBinary Search + Two PtrsMedium25 min[ ]
2Longest Mountain in ArrayTwo PointersMedium25 min[ ]
3Shortest BridgeBFS + DFSMedium30 min[ ]
4Cheapest Flights Within K StopsBFS / Bellman-FordMedium30 min[ ]
5Course Schedule IITopological SortMedium25 min[ ]
6House Robber IIIDP on TreesMedium25 min[ ]
7Longest Palindromic SubstringDP / ExpandMedium25 min[ ]
8Maximal Square2D DPMedium25 min[ ]
9Daily Temperatures (re-do timed)Monotonic StackMedium15 min[ ]
10Find Median from Data Stream (re-do timed)Two HeapsHard20 min[ ]

Pattern Identification Accuracy Log (Days 37-38)

#ProblemMy GuessActual PatternCorrect?
1
2
3
4
5
6
7
8
9
10

Accuracy target: 8/10+ -- if below, repeat Days 37-38 before moving to Phase 4.


External Resources (Hand-Picked Supplements)