Core problem patterns
Two pointers, sliding window, prefix sums, fast/slow pointers. Roughly 40% of screens are one of these four wearing a costume.
The mental model
Interview problems are not a thousand distinct puzzles. They are a small number of shapes wearing different costumes. "Find two numbers that sum to a target", "find a pair of lines that hold the most water", "merge two sorted lists" — all three are the same shape: two indices walking through data, with a rule for which one moves.
The analogy that sticks: chess openings. A club player calculates every move from scratch and runs out of clock by move 20. A stronger player recognises the position — "this is a Sicilian, the plan is queenside counterplay" — and spends the saved time on the part that is genuinely new. Patterns are openings. They do not solve the problem for you; they get you to the interesting part with 35 minutes still on the clock.
Why do these four patterns in particular exist? Because they all attack the same enemy: the nested loop. The brute-force answer to most array and string problems is "try every pair" (O(n²)) or "try every subarray" (O(n³) naively). Each pattern is a different way of proving that you do not need to look at most of those pairs:
- Two pointers — exploit order so that moving one pointer eliminates a whole family of candidates at once.
- Sliding window — exploit the fact that a window's answer can be updated from the previous window instead of recomputed.
- Prefix sums — exploit precomputation, so a range query becomes one subtraction.
- Fast/slow pointers — exploit relative speed, so structural properties (cycles, midpoints) fall out with O(1) memory.
The claim in the roadmap is worth taking literally: a large fraction of screening rounds is one of these four. Learning to name the shape within two minutes is the highest-return skill in interview preparation, because naming it collapses a 45-minute problem into a 10-minute one.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision