A reference for the long game

The Holy Grail of Problem Solving

315 problems. 28 patterns. 11 families. 8 primitive moves. One thinking process you'll keep for the rest of your career.

Built for Python. Built for FAANG and startups. Built for those who cannot memorize but can learn to recognize.

315
Problems
28
Patterns
11
Families
8
Primitives
00 - Foundations

How to think (and remember)

Memorizing 500 problems will not save you if you cannot think on a new one. The goal is a reliable process that generates solutions from a small set of primitives.

The central insight: you are not trying to remember. You are trying to recognize. Your memory is not the bottleneck; your process for asking the right questions is.

The 7-question tree

  1. What is the input shape? Array, linked list, tree, graph, grid, intervals, stream.
  2. Is it sorted, or would sorting help? Sorted usually unlocks two pointers or binary search. Sorting often unlocks greedy.
  3. What is the local relationship? Pair sum, next greater, prefix difference, parent/child, neighbor cell, overlapping interval.
  4. What is the output? Single number, boolean, all solutions, top-k, shortest distance, merged structure.
  5. What do constraints imply? n <= 20 means backtracking or bitmask. n <= 100000 means linear or sort. n huge means logarithmic or math.
  6. Where does brute force repeat work? Same pair, same window, same subproblem, same graph state, same prefix.
  7. Can a tiny example reveal the recurrence? Compute n=1,2,3 by hand and name what state changes.

Curiosity is a tool. After every problem, ask one why and one what-if: what if sorted, duplicates, streaming, weighted, mutable, or too large for memory?

01 - Foundations

The 60-second triage

Before writing a line, classify the input. The input signal usually tells you the pattern.

Input signal
Likely pattern
Sorted array, find pair or triplet
Two pointers / binary search
Subarray, substring, contiguous
Sliding window / prefix sum / Kadane
All subsets, permutations, combinations
Backtracking
Top K, K largest, smallest, frequent
Heap / quickselect / bucket sort
Shortest path or min steps in grid or graph
BFS if unweighted, Dijkstra if weighted
Reachability, components, cycle
DFS / BFS / Union-Find
Ordering with prerequisites
Topological sort
Next greater / smaller, brackets, daily temps
Monotonic stack
Minimize max / maximize min with bounded answer
Binary search on answer
Count ways, min cost, best ending here
Dynamic programming
Intervals, meetings, merge ranges
Sort by start or end, then sweep
LRU or O(1) insert/delete/lookup
HashMap + doubly linked list

Pattern recognition trainer

Read the fragment, pick the pattern. Train the reflex.
Loading...
Score: 0 / 0
02 - Foundations

The 8 primitive moves

Every solution is a composition of two or three of these. If memory is hard, memorize these eight.

i

HASH

Trade space for O(1) lookup. Two Sum's secret weapon.

ii

SORT

Impose order to enable scans. Greedy's gateway.

iii

TWO POINTERS

Two indices guided by an invariant.

iv

SLIDING WINDOW

Maintain a valid range while sweeping.

v

BINARY SEARCH

Halve a sorted or monotonic space.

vi

DFS / BFS

Explore reachable states. BFS for shortest unweighted.

vii

HEAP

Top-K, running median, scheduling.

viii

STACK

Defer decisions until context arrives.

03 - Foundations

11 problem families - connect the dots

Do not ask "have I seen this?" Ask "which family is this?" The family gives you the skeleton.

Exhaustive search

choose -> recurse -> unchoose

Subsets, permutations, N-Queens, Combination Sum, Word Search.

Best so far ending here

dp[i] = f(dp[i-1], dp[i-2])

Kadane, House Robber, Decode Ways, Climbing Stairs.

Match two sequences

dp[i][j] on two prefixes

LCS, Edit Distance, Regex, Wildcard, Distinct Subsequences.

Fill a knapsack

pick item or skip item

Partition Equal Subset, Target Sum, Coin Change.

Partition intervals

dp[l][r] = best split at k

Burst Balloons, Matrix Chain, Cut a Stick.

Sort then sweep

sort, maintain running state

Intervals, meetings, arrows, activity selection.

Top K / running order

heap size k or two heaps

K closest, median stream, merge K lists.

Next greater / parens

monotonic stack

Daily temperatures, histogram, valid parentheses.

Graph reachability

DFS/BFS with visited

Islands, clone graph, flood fill, surrounded regions.

Graph ordering

topological sort

Course Schedule, Alien Dictionary, Parallel Courses.

Shortest / cheapest path

BFS / Dijkstra / Bellman-Ford

Network Delay, Cheapest Flights, Min Effort Path.

27 - Synthesis

Interview playbook

Interviewers score problem solving, code quality, and communication. Staying silent is usually what loses communication points.

Phase 1 - Clarify

"Input is ___, return ___. Can it be empty? Duplicates? Sorted? Value range? Time vs space priority?"

Phase 2 - Examples and brute force

"The naive approach is ___, O(___). Let me find where it repeats work."

Phase 3 - Pattern identification

"I notice ___, which suggests ___."

Phase 4 - Algorithm before coding

"I will maintain ___; the invariant is ___; complexity is ___."

Phase 5 - Code

"I will handle edge cases first, then write the invariant-heavy loop carefully."

Phase 6 - Trace and test

"Let me walk the example and then check empty, single element, duplicates, and boundary values."

Phase 7 - Complexity and tradeoffs

"Time is ___ because ___. Space is ___. An alternative would trade ___ for ___."

28 - Synthesis

How problems twist

Interviewers take a base problem, then twist one knob. Recognize the knob and the new problem becomes familiar.

1. Sorted -> unsorted
Two pointers may become hashmap, or you sort first.
2. Distinct -> duplicates
Adds skip-duplicate logic after sorting.
3. Fixed input -> stream
Use heaps, running counters, queues, or incremental indexes.
4. Single query -> many queries
Precompute: prefix sums, trie, sparse table, segment tree.
5. Unweighted -> weighted
BFS becomes Dijkstra. Negative edges become Bellman-Ford.
6. Exists -> count -> enumerate
Boolean DP becomes counting DP, then backtracking.
7. Add a budget
Adds a dimension to state, like transactions or deletions.
8. 1D -> 2D
Often run the 1D idea per row, column, or compressed band.
29 - Synthesis

The pattern mindmap

Everything reduces to a small core: eight primitive moves, a ring of patterns, and families of variations.

8 Primitives Hash / Sort / Two Pointers / Window Binary Search / BFS-DFS / Heap / Stack Arrays &Hashing TwoPointers SlidingWindow Stack +BSearch StructuresTrees/Heap Backtracking GraphsPaths DynamicProgramming 1D / 2D / LCS / LIS Knapsack / Stocks / MCM Subsets / permutations / combinations / word search Next greater / on answer BFS / DFS / Dijkstra
Linear sweep
Deferred decisions
Linked/tree structures
Graphs
Exhaustive search
Dynamic programming

How to assimilate this. Read by clusters: orange means sweep, teal means structures, blue means traverse states, purple means enumerate choices, red means cache overlapping subproblems. Memorize the clusters; the details rebuild themselves through practice.

30 - Synthesis

The night-before summary

If you only remember this section, you can still do well.

Brute force first

Earns points, buys thinking time, reveals repeated work.

Name the pattern

Say it before coding so the interviewer can steer you early.

Trace one example

Catches most bugs and demonstrates rigor.

  1. What is the input shape? Array, tree, graph, intervals, grid, stream.
  2. What does the constraint size allow? Backtracking, quadratic, sort, linear, log.
  3. Which primitives combine here? Usually two or three.
  4. Which family does this belong to? Retrieve the skeleton, not a memorized answer.