Skip to content
[ Coding craft ]

The 15 Coding Interview Patterns That Cover Most Questions (With One Problem Each)

The 15 coding interview patterns behind most questions, from two pointers to dynamic programming, with the signal for each and one practice problem.

By TechInView6 min read
  • leetcode patterns
  • DSA patterns
  • sliding window pattern
  • two pointers pattern

Short answer: most coding interview questions are variations of about 15 coding interview patterns: two pointers, sliding window, hash map counting, prefix sums, binary search, fast and slow pointers, linked list reversal, monotonic stack, heaps, intervals, tree DFS, BFS, topological sort, backtracking, and dynamic programming. Learn the signal that triggers each one and solve one core problem per pattern before you add volume.

Solving hundreds of random problems is a slow way to prepare. Interviewers draw from a fairly small set of patterns, and once you recognize the pattern, the problem gets much easier. Each section below gives the signal to look for, the core idea, and one problem to practice on.

The 15 patterns at a glance

#PatternSignal in the problemPractice problem
1Two pointersSorted array, pairs, or reversing in placeContainer With Most Water
2Sliding windowLongest or shortest contiguous subarray or substringLongest Substring Without Repeating Characters
3Hash map countingFrequencies, duplicates, "have I seen this"Group Anagrams
4Prefix sumsRange sums or products, many queriesProduct of Array Except Self
5Binary searchSorted input, or "minimum value that works"Koko Eating Bananas
6Fast and slow pointersCycles, middle of a listLinked List Cycle
7Linked list reversalReverse all or part of a listReverse Linked List
8Monotonic stack"Next greater" or "next smaller" elementDaily Temperatures
9Heap / top-kk largest, k most frequent, running medianTop K Frequent Elements
10IntervalsOverlapping ranges, meetings, bookingsMerge Intervals
11Tree DFSPaths, heights, validating a treeValidate Binary Search Tree
12BFSShortest path in unweighted graphs, level orderNumber of Islands
13Topological sortDependencies, prerequisites, orderingCourse Schedule
14BacktrackingAll combinations, subsets, permutationsSubsets
15Dynamic programmingCount ways, min or max cost, overlapping subproblemsCoin Change

Array and string patterns

1. Two pointers

Move two indices toward each other, or both forward at different speeds. It turns many O(n²) pair searches into O(n) on sorted input. Ask yourself: if I move the left pointer, does the answer only get better or only get worse? If yes, two pointers probably works.

2. Sliding window

Keep a window [left, right] and a running state (a count, a set, a sum). Expand right; shrink left when the window breaks the rule. Each index enters and leaves once, so it is O(n).

3. Hash map counting

When the problem mentions frequencies, duplicates, or complements, a hash map turns lookups into O(1). Two Sum is the classic example.

4. Prefix sums

Precompute running totals so any range sum is one subtraction. Variants include prefix products and difference arrays for many range updates.

5. Binary search, including on the answer

Binary search is not only for finding a value in a sorted array. If you can write a yes/no check like "can she finish at speed k?" and the answers flip from no to yes once, binary search the smallest k that works.

Linked list and stack patterns

6. Fast and slow pointers

One pointer moves one step, the other two. If there is a cycle, they meet. The same trick finds the middle of a list.

7. Linked list reversal

Keep prev, curr, and next, and flip one link at a time. Draw it on paper first; most bugs here are lost references.

8. Monotonic stack

Keep a stack of indices whose values are always increasing or decreasing. When a new value breaks the order, pop and answer the "next greater" question for each popped index.

Heap and interval patterns

9. Heaps and top-k

A heap of size k keeps the k best items in O(n log k). Two heaps (a max-heap and a min-heap) keep a running median.

10. Intervals

Sort by start time, then sweep and merge or count overlaps. Meeting rooms, calendar bookings, and merging ranges are all this pattern.

Tree and graph patterns

11. Tree DFS

Most tree problems are a recursive function that returns something from each subtree (height, validity, a max path) and combines the results. Decide what each call returns before you write it.

12. BFS

Use a queue to explore level by level. BFS gives the shortest path in an unweighted graph and powers grid problems like flood fill.

13. Topological sort

For dependency problems, count incoming edges, start from nodes with zero, and remove edges as you go (Kahn's algorithm). If you cannot process every node, there is a cycle.

Search and optimization patterns

14. Backtracking

Build a solution step by step, recurse, then undo the step. Subsets, permutations, combination sums, and word search all follow the same template: choose, explore, un-choose.

15. Dynamic programming

If a brute-force recursion recomputes the same subproblems, store the results. Define the state ("min coins to make amount a"), the transition, and the base case. Start with one-dimensional DP before grids.

Two more worth knowing

How to study patterns

  1. Learn one pattern at a time. Solve the core problem, then two variations.
  2. For each problem, write the signal that told you which pattern to use.
  3. Mix the patterns after a week, so you practice recognizing them without a label.

The data structure decision guide helps with the "which structure?" step, and the time complexity cheat sheet helps you check your approach against the input size.

FAQ

How many coding interview patterns are there?

Lists range from about 12 to 25 depending on how finely you split them. The 15 here cover most questions asked in typical coding interviews.

Should I learn patterns or just solve many problems?

Learn the patterns first, then solve problems to practice recognizing them. Volume without patterns tends to produce memorized solutions that fail on new variations.

Which pattern is asked most often?

Arrays with hash maps, two pointers, and sliding windows come up constantly, followed by trees, graphs, and dynamic programming.

How can I practice recognizing patterns under interview conditions?

Solve problems without the topic tag, then explain your choice out loud. TechInView's AI interviewer asks why you chose an approach, which is exactly the skill interviewers test. Browse the practice problems by category to start.


Summary: learn these 15 coding interview patterns, the signal for each, and one core problem per pattern. Recognizing the pattern is most of the work in an interview; the code follows from it.

[ Practice out loud ]

Reading this is the easy half.

Start with free DSA practice, then switch into a voice mock interview with live coding and a scored breakdown when you want the full simulation.