Loading
Practice
Anyone can look up how a sliding window works. The skill an interview tests is reading an unfamiliar problem and knowing which tool it is asking for — so every pattern here leads with its recognition clues.
20 patterns
Two indices moving under a rule that never lets them backtrack.
A contiguous range that grows and shrinks instead of restarting.
Precompute cumulative totals so any range answers in constant time.
Halve the search space using a yes/no question that flips exactly once.
Two walkers at different speeds reveal cycles and midpoints.
Trade memory for time by remembering what you have already seen.
A stack kept in sorted order answers "next greater" in one pass.
A heap of size k beats sorting everything you do not need.
Sort by start, then decide overlap against one running interval.
When values are a permutation of indices, the array is its own map.
Build a candidate incrementally, and undo the moment it cannot work.
Expand level by level, so the first time you arrive is the shortest way.
Follow one path to exhaustion, then retreat and try the next.
Track which things are connected, with near-constant merges.
Take the locally best option, when you can prove it stays best.
Solve each overlapping subproblem once and remember the answer.
Split into independent halves, solve each, combine the results.
Treat an integer as a set of flags and use the hardware directly.
Constant-time access to the extreme, logarithmic to change it.
A tree keyed by character, so shared prefixes are stored once.