Maintain a contiguous range and slide its boundaries to avoid recomputation.
Time O(n), space O(1) or O(k) for a frequency map.- Pharmacy Pickup
- Rolling Peak Sensor
- Unique DNA Run
Replace a 75-problem list with 12 patterns. Each pattern covers dozens of problems once the shape clicks. The same fluency, a better mental organizer.
Maintain a contiguous range and slide its boundaries to avoid recomputation.
Time O(n), space O(1) or O(k) for a frequency map.Two cursors moving independently over a sorted or monotone structure.
Time O(n) after an optional O(n log n) sort; space O(1).A stack whose elements stay in non-increasing or non-decreasing order.
Time O(n) amortized (each element is pushed and popped once).Precompute cumulative arrays so range queries answer in O(1).
Preprocess O(n); query O(1).When a predicate is monotonic over the answer space, binary search the answer itself.
Time O(log R · feasibility(n)) where R is the answer range.A data structure that returns the min or max in O(log n) per operation.
Insert/pop O(log n); peek O(1); heapify O(n).A disjoint-set data structure supporting near-constant merge and find.
Amortized O(α(n)) per op with path compression + union by rank.Linear ordering of a DAG consistent with its dependencies.
Time O(V + E); space O(V).Breadth-first for shortest unweighted paths; depth-first for exhaustive traversal.
Time O(V + E); space O(V).Break an overlapping-subproblem problem into a recurrence and cache results.
State × transition cost; typical O(n), O(n²), or O(n·m).DFS through a decision tree with pruning and state restoration.
Exponential in the decision depth; pruning is the whole game.Sort events by time, sweep a line, maintain an active set for overlap questions.
Time O(n log n) for the sort; O(n) for the sweep.Ten-minute patterns quiz. No card. Personalized loop starts on the other side.