Most developers preparing for coding interviews learn the patterns. Sliding window. Two pointers. BFS. DFS. Binary search. Dynamic programming. They study them, understand them, and can implement them when told which one to use.
Then they get a problem in an interview and freeze.
Not because they forgot the patterns. Because nobody taught them how to recognize which pattern applies to a problem they have never seen before. The knowledge is there. The trigger recognition is not.
This post gives you the 7 trigger questions you ask yourself when you read a problem statement. One per pattern. When the answer is yes, you know which pattern to reach for.
Why trigger recognition is the actual skill
Every coding interview pattern has a structural signature. It is not a keyword in the problem statement. It is a property of what the problem is asking you to do.
The standard advice is to "practice enough problems until you recognize patterns." That works eventually, but it is slow and unreliable under pressure. A more direct approach is to build a decision framework: a set of specific questions that map to specific patterns. When you read a new problem, you run through the questions in order. The first one that gets a clear yes tells you where to start.
This is what experienced engineers do without realizing it. They have internalized the questions. The goal here is to make them explicit.
Pattern 1: Sliding Window
Trigger question: Does the problem ask for something about a contiguous subarray or substring of a fixed or variable size?
When the answer is yes, sliding window is the candidate. The signal is the word "contiguous". More broadly: any problem where you need the maximum, minimum, longest, or shortest subarray or substring satisfying some condition.
The window expands when adding the new element still satisfies the condition. It shrinks when it violates the condition. The answer updates as you move.
Problems that match: maximum sum subarray of size k, longest substring without repeating characters, minimum window substring, fruits into baskets.
The distinction from two pointers: sliding window problems involve a contiguous range with a condition on the range itself. Two pointer problems involve finding a pair or partition where elements do not need to be adjacent.
Pattern 2: Two Pointers
Trigger question: Does the problem involve finding a pair, triplet, or partition in a sorted array or linked list where you need to compare elements from different ends?
Two pointers works when the array is sorted (or can be sorted) and you need to find pairs that sum to a target, remove duplicates, check if a string is a palindrome, or merge two sorted arrays. One pointer starts at the left, one at the right, and they converge based on whether the current pair overshoots or undershoots the target.
The sorted order is what makes the convergence meaningful. If you move the left pointer right, the sum increases. If you move the right pointer left, the sum decreases. That binary logic is the core of the pattern.
Problems that match: two sum on a sorted array, three sum, remove duplicates in-place, valid palindrome, container with most water.
Pattern 3: BFS
Trigger question: Does the problem ask for the shortest path, minimum steps, or level-by-level traversal in an unweighted graph or tree?
BFS processes nodes layer by layer, which makes it the natural choice for shortest path problems where every edge has the same weight. If you need to find the minimum number of moves, the shortest sequence of transformations, or you need to visit all nodes at the same depth before going deeper, BFS is the pattern.
The data structure is a queue. You enqueue the starting node, then process each node by enqueuing all unvisited neighbors. The level of the queue at any point corresponds to the distance from the source.
Problems that match: shortest path in a grid, word ladder, minimum depth of binary tree, rotting oranges, number of islands (when minimum spread matters).
The distinction from DFS: BFS finds the shortest path in unweighted graphs. DFS finds any path. If the problem says "minimum" and involves a graph, BFS is almost always right.
Pattern 4: DFS and Backtracking
Trigger question: Does the problem ask you to explore all possible combinations, permutations, or paths, or does it ask whether a path exists?
DFS explores one branch completely before backtracking to try another. It is the pattern for existence problems ("is there a path"), exhaustive search problems ("find all combinations"), and problems where you build a solution incrementally and undo a choice when it leads to a dead end.
The key signal for backtracking specifically is "generate all" or "find all valid": all permutations, all subsets, all combinations that sum to a target, all valid placements. You build the candidate solution step by step, check whether the current state is still valid, and backtrack when it is not.
Problems that match: word search in a grid, N-queens, generate parentheses, combination sum, subsets, permutations.
The distinction from BFS: BFS is for shortest path. DFS is for reachability and exhaustive search. If "all possible" appears in the problem, think DFS with backtracking.
Pattern 5: Binary Search
Trigger question: Does the problem involve searching in a sorted structure, or does it ask for the minimum or maximum value that satisfies a condition you can verify in O(n)?
The first form is obvious: sorted array, find a target. The second form is less obvious and more commonly tested. When a problem asks for the minimum capacity, maximum speed, minimum days, or optimal threshold that satisfies some condition, and you can write a function that checks whether a given value satisfies the condition, binary search on the answer is the pattern.
The check function divides the search space: values below the threshold fail, values above it pass (or vice versa). You binary search on the threshold.
Problems that match: search in rotated sorted array, find minimum in rotated array, koko eating bananas, capacity to ship packages, split array largest sum.
The signal for the second form: the problem asks for "minimum X such that Y is possible" or "maximum X such that Y is possible." That is almost always binary search on the answer.
Pattern 6: Dynamic Programming
Trigger question: Does the problem ask for the maximum, minimum, count of ways, or whether something is possible, where the answer to the full problem depends on answers to smaller versions of the same problem?
The two conditions for DP are optimal substructure (the answer to the big problem depends on answers to subproblems) and overlapping subproblems (the same subproblem appears multiple times in the recursion). If both hold, DP applies.
The secondary signals: "how many ways", "minimum cost", "maximum profit", "is it possible", "longest subsequence". These are all outputs that DP produces efficiently.
The way to confirm: try to write a recursive brute-force solution. If the recursion tree re-computes the same inputs, you have overlapping subproblems. Add memoization and you have top-down DP.
Problems that match: coin change, house robber, longest common subsequence, unique paths, partition equal subset sum, word break.
The distinction from greedy: greedy makes the locally optimal choice at each step without revisiting. DP considers all choices and takes the globally optimal one. If a greedy choice fails on a counterexample, the problem needs DP.
Pattern 7: Dijkstra
Trigger question: Does the problem ask for the shortest path in a weighted graph where all edge weights are non-negative?
When edges have different weights, BFS no longer guarantees the shortest path because a path with fewer edges may have higher total cost than one with more edges. Dijkstra uses a min-heap to always process the lowest-cost node first, which ensures that the first time you reach a node, you have found the shortest path to it.
The data structure is a priority queue (min-heap). You push (cost, node) pairs and always pop the cheapest unvisited node. For each neighbor, you relax the distance if the new path is cheaper.
Problems that match: network delay time, cheapest flights within k stops (with modification), path with minimum effort, minimum cost to reach destination.
The distinction from BFS: BFS works on unweighted graphs (all edges cost 1). Dijkstra works on weighted graphs with non-negative weights. If the graph has weights, Dijkstra. If edges are uniform, BFS.
The decision sequence in an interview
When you get a new problem, run through these questions in order:
First: is there a contiguous subarray or substring condition? If yes, sliding window.
Second: is the array sorted and do I need a pair or partition? If yes, two pointers.
Third: is there a graph and do I need the shortest path with uniform edge weights? If yes, BFS.
Fourth: do I need all combinations, permutations, or does a path need to exist? If yes, DFS or backtracking.
Fifth: is there a sorted structure or a threshold I can binary search on? If yes, binary search.
Sixth: does the problem ask for max, min, count, or possibility with overlapping subproblems? If yes, DP.
Seventh: is there a weighted graph with non-negative weights and I need the shortest path? If yes, Dijkstra.
Most problems fit clearly into one of these seven. The ones that do not are hybrid problems where two patterns combine, which is a separate skill set entirely.
Building trigger recognition before the interview
Reading these seven questions once will not make them automatic under pressure. The way to internalize them is to practice applying the decision sequence to new problems before writing any code.
When you see a new problem, stop before you think about implementation. Read the problem statement. Ask yourself the seven questions in order. Write down which pattern you think applies and why. Then implement.
After you finish, check whether your pattern choice was correct. If it was not, go back to the trigger question and figure out which signal you misread. That analysis is where the learning happens.
After fifty problems of deliberate trigger practice, the decision sequence becomes automatic. You stop choosing patterns consciously and start recognizing them the way you recognize a word when you read it.
If you want to see each of these seven patterns executing step by step with interactive examples, Expora walks through all seven with live state visible at each step: Coding Interview Patterns: the 7 that cover 90% of interviews
The combination of trigger recognition and execution fluency is what makes patterns genuinely useful in interviews, rather than just a list you memorized.
Top comments (0)