Skip to main content

Complete Guide · 2026

Coding Interview Patterns: 15 Essential Templates for 2026

The 15 coding interview patterns that appear in 95%+ of FAANG technical interviews — with recognition cues, code templates in Python, Java, and C++, and a recommended learning order from beginner to advanced.

What Are Coding Interview Patterns?

Coding interview patterns are reusable algorithmic templates — not memorized solutions, but mental frameworks for recognizing and solving entire classes of problems. When you see a problem asking to "find the longest substring without repeating characters," a Sliding Window pattern immediately comes to mind. When you see "find a pair in a sorted array that sums to a target," Two Pointers is the answer.

The 15 patterns in this guide appear in 95%+ of coding interviews at FAANG companies. Google, Amazon, Meta, Microsoft, and Apple test the same core algorithmic concepts across thousands of interviews each year. Mastering these patterns means you're solving the problem type, not just the specific problem.

Pattern-based prep is the approach behind resources like Grokking the Coding Interview, NeetCode, and this guide. The insight is simple: there are roughly 2,000+ LeetCode problems, but only ~15 underlying patterns. Learn the patterns, and you can solve any problem variant you encounter.

Two Pointer is a technique where two index variables traverse a data structure — typically an array or string — simultaneously, moving toward or away from each other based on a condition. It eliminates the need for nested loops, reducing time complexity from O(n²) to O(n). Use Two Pointer when the input is sorted and you need to find pairs, triplets, or subarrays satisfying a sum or range constraint. Classic examples include finding two numbers that sum to a target, removing duplicates from a sorted array, and the container with most water problem. The key insight is that on a sorted array, you can confidently move the left pointer right to increase the sum, or move the right pointer left to decrease it, converging on the answer in a single linear pass.
Sliding Window is an algorithmic technique that maintains a contiguous subarray or substring as a "window" that slides across the input. Unlike the Two Pointer approach, Sliding Window operates on contiguous elements and is ideal for problems asking for the longest, shortest, or optimal subarray or substring meeting a given constraint. It comes in two forms: fixed-size windows (where the window length is given, useful for maximum sum of k elements) and variable-size windows (where the window expands and contracts based on validity, useful for longest substring without repeating characters). Both forms run in O(n) time — each element is added and removed from the window at most once — compared to O(n²) or O(n³) for brute-force approaches over all subarrays.

Why Pattern-Based Prep Beats Random Grinding

Random grinding — solving 200+ problems in no particular order — produces diminishing returns. After 50 random problems, you start memorizing specific solutions rather than building transferable intuition. The "recognize then solve" framework changes this fundamentally.

Here's how it works: When you encounter a new problem, your first question should not be "how do I solve this?" but "which pattern does this look like?" The pattern recognition step narrows down your approach from infinite possibilities to 2–3 candidates. Then you apply the pattern's template and adapt it to the specific constraints.

Step 1

Recognize

Identify signal words in the problem statement that point to a pattern

Step 2

Apply

Reach for the pattern's template and adapt it to the specific constraints

Step 3

Optimize

Analyze time/space complexity and optimize if needed

The 15 Essential Coding Interview Patterns

Organized by learning tier — master Tier 1 first, then 2, then 3. Click any pattern to see full templates and example problems.

Tier 3 — Cover if Time For senior roles or top-tier companies

How to Recognize Which Pattern to Use

When you read a problem statement, look for these signal phrases. They reliably map to specific coding interview patterns.

If the problem says / asks for... Use this pattern
Contiguous subarray / substring with a constraint Sliding Window →
Sorted array, find a pair / triplet / sum Two Pointers →
Find / search in a sorted array or range Binary Search →
Count subarrays, range queries, prefix/suffix sums Prefix Sum →
Count frequency, find duplicates, find complement Hash Map / Set →
Matching brackets, next greater element, evaluate expressions Stack →
Shortest path, level-order traversal, flood fill Queue / BFS →
Depth of tree, path sum, serialize/deserialize Trees / DFS →
Top K elements, merge sorted lists, data stream median Heap / Priority Queue →
Find all permutations, subsets, combinations Backtracking →
Overlapping subproblems, optimal substructure Dynamic Programming →
Path / connectivity in graph, cycle detection Graphs →
Dependency ordering, DAG, prerequisites Topological Sort →
Prefix search, autocomplete, word dictionary Trie →
Group nodes, connected components, merge accounts Union Find →
Locally optimal choice leads to global solution Greedy →
Next / previous greater or smaller, histogram area Monotonic Stack →
Overlapping intervals, meeting rooms, schedule Intervals →

Pattern Complexity Quick Reference

Use this table when analyzing your solutions during interviews. Knowing the expected time and space complexity for each pattern prevents overcomplicated solutions.

Pattern Time Space
Sliding Window O(n) O(k)
Two Pointers O(n) O(1)
Binary Search O(log n) O(1)
Prefix Sum O(n) build, O(1) per query O(n)
Hash Map / Set O(1) average for lookup/insert, O(n) space O(n)
Stack O(n) O(n)
Queue / BFS O(V + E) for graphs, O(n) for trees O(V)
Heap / Priority Queue O(log n) insert/delete, O(1) peek O(n)
Linked List O(n) O(1)
Trees / DFS O(n) O(h)
Graphs O(V + E) O(V)
Dynamic Programming Depends on state space O(n)
Greedy O(n log n) O(1)
Backtracking Exponential O(n)
Trie O(m) per operation where m is word length O(ALPHABET_SIZE
Union Find O(α(n)) per operation O(n)
Monotonic Stack O(n) O(n)
Topological Sort O(V + E) O(V)
Bit Manipulation O(1) or O(log n) for most operations O(1)
Intervals O(n log n) O(n)
Matrix O(m × n) O(m

Recommended Order to Learn Coding Interview Patterns

Follow this sequence to build intuition progressively. Each pattern builds on the previous ones — jumping straight to Dynamic Programming before understanding Hash Maps and BFS leads to frustration.

01

Two Pointers

Tier 1
02

Sliding Window

Tier 1
03

Binary Search

Tier 1
04

Hash Map / Set

Tier 1
05

Stack

Tier 2
06

Queue / BFS

Tier 2
07

Trees / DFS

Tier 2
08

Heap / Priority Queue

Tier 3
09

Backtracking

Tier 3
10

Intervals

Tier 3
11

Prefix Sum

Tier 3
12

Dynamic Programming

Tier 2
13

Graphs

Tier 3
14

Trie

Tier 3
15

Union Find

Tier 3

Coding Interview Patterns by Company

Different companies emphasize different coding interview algorithm patterns. Tailor your prep to your target company after mastering the core patterns.

Google

  • 1 Dynamic Programming
  • 2 Graph BFS/DFS
  • 3 Binary Search
  • 4 Trees
  • 5 Topological Sort

Amazon

  • 1 Trees
  • 2 BFS / Graphs
  • 3 Two Pointers
  • 4 Hash Maps
  • 5 Greedy

Meta

  • 1 Sliding Window
  • 2 Two Pointers
  • 3 BFS/DFS Trees
  • 4 Hash Map
  • 5 Dynamic Programming

Microsoft

  • 1 Trees
  • 2 Dynamic Programming
  • 3 Graphs
  • 4 Linked List
  • 5 Binary Search

Apple

  • 1 Arrays
  • 2 Trees
  • 3 Binary Search
  • 4 Sliding Window
  • 5 Stack

Frequently Asked Questions

How many coding interview patterns are there?

There are approximately 15 core coding interview patterns covering 95%+ of FAANG problems. These include Sliding Window, Two Pointers, Binary Search, Hash Map, Stack, BFS, DFS, Heap, Backtracking, Dynamic Programming, Graphs, Trie, Union Find, Greedy, and Intervals. Some resources break these into sub-patterns, but mastering the 15 core patterns gives you the complete toolkit.

What is the most important pattern to learn first?

Start with Two Pointers and Sliding Window — these appear in dozens of problems across arrays, strings, and linked lists. Then learn Hash Map (unlocks Two Sum variants) and Binary Search. These four Tier 1 patterns cover roughly 40% of all coding interview questions and form the foundation for advanced patterns.

Is learning patterns enough to pass FAANG interviews?

Pattern knowledge is necessary but not sufficient. You also need timed practice (35–45 minutes per problem), clear communication of your thought process, and the ability to handle edge cases on demand. Most engineers fail not because they don't know patterns, but because they can't apply them quickly under pressure. Combine pattern study with regular timed practice sessions.

How long does it take to master all coding interview patterns?

Most engineers need 6–12 weeks to feel confident with all 15 patterns — roughly 1–2 weeks per tier. Budget 2 weeks for Tier 1 patterns, 3–4 weeks for Tier 2, and the remaining time for Tier 3. Spending 2–3 hours daily on problems and pattern review is the typical pace for a focused interview prep sprint.

What's the difference between Blind 75 and coding interview patterns?

Blind 75 is a list of specific problems to solve. Coding interview patterns are the algorithmic templates those problems test. Learning patterns first means you can solve any variant — not just the exact 75 problems on the list. Ideally, study patterns here, then validate with Blind 75 or Grind 75 problems.

Do I need to learn all 15 patterns?

For most mid-level roles, mastering Tier 1 + Tier 2 (8 patterns) is sufficient. For senior roles or top-tier companies like Google and Meta, cover all 15 patterns. Union Find, Monotonic Stack, and Topological Sort appear rarely in interviews but are relatively quick to learn once you have the foundations — usually a weekend each.

Related Resources

Buy me a coffee