Sale: Get 60% Off on all Pro Plans. Buy Now
Pattern Guide

Coding Interview Patterns Guide

Most interview problems are variations of a small set of reusable patterns. Learn the patterns, not just the problems.

Learn the pattern, then drill it from memory.

Read the guide, practice the critical lines, and track the parts you miss. Every AlgoDrill pattern guide connects directly to drillable problems.

Start with pattern guides

The core insight

Most coding interview problems are variations on a small set of templates. The specific problem changes: the data type, the constraint, the output format. The underlying structure does not. A sliding window problem about maximum subarray length uses the same core logic as one about longest substring with unique characters. A BFS problem on a graph uses the same traversal structure as one on a grid.

This matters for prep because it changes the study target. Instead of trying to memorize hundreds of specific problems, you learn a smaller set of patterns and practice recognizing which pattern applies. A person who has internalized 12 patterns and can produce each template from memory will consistently outperform someone who has seen 300 problems but cannot reproduce the solutions reliably.

Why patterns transfer

A pattern is not a specific algorithm. It is a problem structure with a canonical solution approach. When you learn the two pointers pattern, you are not memorizing how to solve a specific problem. You are learning: when a problem asks you to find pairs in a sorted array, or compare elements from opposite ends, or use two indices to track a subarray, a specific approach (one pointer at each end, both moving inward under a condition) tends to be efficient.

This transfers because the structure recurs across many surface variations. Interviewers can ask you about two-sum, three-sum, container with most water, or trapping rainwater, and all of them are solvable with variants of the same pointer manipulation approach.

The key to transfer is pattern recall, not problem recall. If you can produce the template from memory, you can adapt it. If you can only recognize it when you see it in a solution, the adaptation step is much harder.

The core patterns

The patterns that cover the majority of medium difficulty interview problems:

Pattern What it solves Key recognition signal
Hash Maps O(1) lookup, counting, grouping Need to check if something exists quickly
Two Pointers Pairs in sorted arrays, comparing from both ends Sorted input, find pairs, eliminate nested loop
Sliding Window Subarray or substring with a constraint Contiguous elements, optimize a window property
Binary Search Sorted search, search space reduction Sorted array, or a monotonic condition you can search
Stacks Matching brackets, next greater element Need to match or relate each element to a previous one
BFS Shortest paths, level order traversal Minimum steps, layer-by-layer processing
DFS Tree/graph traversal, path finding Explore all paths, tree recursion
Dynamic Programming Optimization over choices, counting paths Optimal substructure, overlapping subproblems
Backtracking Generating all valid combinations or permutations Build a solution incrementally, undo choices
Heap K largest or smallest elements, priority queues "Top K" in the problem, or stream of elements needing ordering
Merge Intervals Overlapping intervals, scheduling Problem involves ranges or time intervals
Trie Prefix search, autocomplete, word lookup Many strings with shared prefixes, prefix matching

How to identify which pattern applies

Pattern recognition is a skill that develops with practice, but there are reliable signals to look for:

Input type and structure. Sorted array: think binary search or two pointers. Graph or tree: think BFS or DFS. String with substring constraint: think sliding window. Intervals: think merge intervals or heap.

The output type. Asking for the minimum number of steps: BFS. Asking for all valid combinations: backtracking. Asking for maximum or minimum value: often dynamic programming or greedy. Asking for existence of something: often hash map.

Constraints. Very large input with O(n log n) or better time requirement suggests a heap or sorting-based approach. Space complexity O(1) rules out solutions that store auxiliary arrays.

You will not always identify the pattern immediately. The skill is in narrowing down: "this looks like a window problem, let me try the sliding window approach and see if the structure fits." With practice, the narrowing gets faster.

From pattern to code

Identifying the right pattern is the first step. The second is producing the code. This is where most people fail in actual interviews: they know the pattern but cannot write the critical lines reliably under pressure.

Every pattern has a template with lines that are easy to produce and lines that are not. For sliding window, the window shrink condition is the line that disappears. For dynamic programming, the transition formula is the line that disappears. For BFS, the visited tracking is the line that disappears.

The only way to build reliable production of those lines is retrieval practice: writing them from memory, checking what you got wrong, drilling the specific lines you missed. Watching solutions builds recognition of those lines, not reliable recall of them.

Order of study

Study patterns in order of frequency and prerequisite dependency. Hash maps and two pointers first (no prerequisites, appear everywhere). Then sliding window (builds on two pointers). Then BFS and DFS (tree and graph structure). Then dynamic programming (more abstract, higher payoff). Then the more specialized patterns: backtracking, heap, trie, merge intervals.

For each pattern, the sequence is: read the guide, write the template from memory, solve representative problems, drill specific weak lines. Do not move on until you can produce the template reliably from a blank file.

The AlgoDrill course is organized by this sequence. Each guide covers the pattern from first principles, connects to the canonical template, and links to problems that test the recall layer. Start with whatever pattern comes next in your sequence, work through the explanation, then immediately test whether it translated into actual recall by trying a practice problem from scratch.

Learn the pattern, then drill it from memory.

Read the guide, practice the critical lines, and track the parts you miss. Every AlgoDrill pattern guide connects directly to drillable problems.

Start with pattern guides

Stop forgetting solutions you already studied.

AlgoDrill turns coding interview patterns into fill-in-the-blank recall drills so you can rebuild solutions under pressure, not just recognize them.

Try recall training