Most coding interview problems are variations on a small set of recurring patterns. Recognizing the pattern is usually more valuable than memorizing any single solution.
Who should use this guide
Candidates preparing for coding rounds at any company that uses algorithmic problem-solving as part of its process.
The patterns worth mastering
1. Two pointers
Used for sorted array problems, pair finding, removing duplicates, reversing in place, by moving two indices toward or away from each other instead of nested loops.
2. Sliding window
For subarray/substring problems with a size or sum constraint, expand a window right, shrink it left when a condition breaks, tracking a running result as you go.
3. Fast and slow pointers
Detects cycles in linked lists, finds the middle of a list in one pass, by moving one pointer twice as fast as the other.
4. Binary search on the answer
Not just for sorted arrays, many "minimize the maximum" or "find the smallest X such that..." problems can be binary-searched over the answer space itself.
5. BFS/DFS on graphs and trees
| Use BFS when | Use DFS when |
|---|---|
| You need shortest path / level order | You need to explore all paths or backtrack |
| Memory for a queue is acceptable | Recursion depth isn't a concern |
6. Dynamic programming
Whenever a problem has overlapping subproblems and optimal substructure, define a clear state (what does
dp[i] mean?) before writing any code, most DP mistakes come from a fuzzy state definition.
Frequently Asked Questions
How many patterns do I really need to know?
These six cover the large majority of interview problems at most companies. Add heaps/priority queues and backtracking once you're comfortable with the core set.
Should I memorize solutions or understand patterns?
Patterns, always. Memorized solutions fall apart the moment the problem is slightly rephrased, which interviewers do intentionally.
Final preparation tips
After solving a problem, explicitly name which pattern you used. This habit makes pattern recognition automatic within a few weeks of practice.

