# Coding Interview Patterns: The Complete Catalog

Source: https://www.techinterview.org/coding-patterns-catalog/
Updated: 2026-08-09 · techinterview.org

patterns catalog

Coding Patterns CatalogEvery coding-interview pattern on the site, one canonical deep-dive per pattern. Learn the template, then drill it against real problems.

**52** patternsSliding window over an array271828182lrslidewindow sum = 19grow r, shrink lO(n), one pass[**Short on time? The 15-pattern master cheat sheet →**](https://www.techinterview.org/post/3233474379/coding-interview-coding-patterns-master-cheat-sheet-all-15-patterns-recognition-template-time-complexity-when-to-use/)  ·  [**Practice: the problem index →**](https://www.techinterview.org/problem-index/)

## Arrays, strings & the core toolkit 10 guides
[**Two pointers**Two Pointers Fundamentals Two pointers use two indices traversing an array or string to solve…](https://www.techinterview.org/post/3233460663/two-pointers-interview-patterns/)[**Sliding window**The Sliding Window Technique The sliding window technique optimizes brute-force O(n^2) or O(n^3) problems to…](https://www.techinterview.org/post/3233460634/sliding-window-interview-patterns/)[**Binary search**Why Binary Search Is Tested So Frequently Binary search appears in roughly 10-15% of FAANG…](https://www.techinterview.org/post/3233460596/binary-search-interview-patterns/)[**Hash-map patterns**Hash maps (dictionaries in Python, HashMaps in Java) provide O(1) average-case lookup, insertion, and deletion.…](https://www.techinterview.org/post/3233461740/hash-map-interview-patterns/)[**Prefix sums**Build a prefix array where prefix[i] = arr[0] + arr[1] + ... + arr[i-1]. Then…](https://www.techinterview.org/post/3233467116/prefix-sum-patterns/)[**String patterns**Strings appear in roughly 25-30% of coding interviews. Unlike arrays or trees, string problems have…](https://www.techinterview.org/post/3233466852/string-patterns/)[**String matching (KMP / Z-algorithm)**For each position i in text (0 to n-m): check if text[i:i+m] == pattern. O(n*m)…](https://www.techinterview.org/post/3233465044/string-matching-algorithms-interview-patterns/)[**Rolling hash (Rabin-Karp)**Given a text T of length n and a pattern P of length m, find…](https://www.techinterview.org/post/3233465339/rolling-hash-rabin-karp-interview-patterns/)[**Sorting-algorithm patterns**While most interviews don't ask you to implement sorting from scratch, understanding the algorithms helps…](https://www.techinterview.org/post/3233463353/sorting-algorithm-interview-patterns/)[**Matrix traversal**Most matrix problems involve: (1) BFS from one or multiple source cells, (2) DFS to…](https://www.techinterview.org/post/3233467378/matrix-traversal-patterns/)
## Stacks, queues, heaps & maps 7 guides
[**Stack patterns**A stack (LIFO) is the right tool when the most recently seen element determines the…](https://www.techinterview.org/post/3233467185/stack-patterns/)[**Queue patterns**Monotonic Deque Pattern - Sliding Window Maximum LeetCode 239. Given an array and window size…](https://www.techinterview.org/post/3233466781/queue-patterns/)[**Monotonic stack & queue**A monotonic stack maintains elements in strictly increasing or decreasing order. Elements that violate the…](https://www.techinterview.org/post/3233465178/monotonic-stack-queue-interview-patterns/)[**Heap / priority queue**Heap Fundamentals A heap is a complete binary tree satisfying the heap property: in a…](https://www.techinterview.org/post/3233460622/heap-priority-queue-interview-patterns/)[**The two-heaps pattern**Two heaps maintain the lower and upper halves of a data stream, allowing O(1) access…](https://www.techinterview.org/post/3233467401/two-heaps-pattern/)[**Ordered-map patterns**An ordered map maintains keys in sorted order with O(log n) insert, delete, and lookup,…](https://www.techinterview.org/post/3233467305/ordered-map-patterns/)[**Linked-list patterns**Linked list problems trip up candidates because pointer manipulation is easy to mess up under…](https://www.techinterview.org/post/3233466900/linked-list-patterns/)
## Trees, tries & range structures 6 guides
[**Binary-tree patterns**Binary tree problems appear in nearly every technical interview. The foundation is traversal order, which…](https://www.techinterview.org/post/3233461462/binary-tree-interview-patterns/)[**Tree traversal**Binary tree traversals: Inorder (left, root, right) -- gives sorted order for a BST. Preorder…](https://www.techinterview.org/post/3233465674/tree-traversal-patterns/)[**Advanced tree patterns**A segment tree answers range queries (range sum, range minimum) in O(log n) and supports…](https://www.techinterview.org/post/3233464939/advanced-tree-interview-patterns/)[**Trie patterns**Trie (prefix tree) problems appear frequently in coding interviews. This guide covers the core patterns…](https://www.techinterview.org/post/3233466827/trie-patterns/)[**Segment tree & Fenwick tree**Range query problems appear frequently in senior engineering interviews and competitive programming: "find the sum…](https://www.techinterview.org/post/3233460884/segment-tree-fenwick-tree-interview/)[**Range-query patterns**Range query problems appear frequently in competitive programming and technical interviews. Knowing which data structure…](https://www.techinterview.org/post/3233466803/range-query-patterns/)
## Graphs 7 guides
[**Graph patterns: the fundamentals**Graph problems appear in every serious technical interview. They cover a wide range of difficulty…](https://www.techinterview.org/post/3233460806/graph-interview-patterns/)[**BFS & DFS**Graph traversal is one of the most tested interview topics. BFS (Breadth-First Search) and DFS…](https://www.techinterview.org/post/3233463119/graph-bfs-dfs-interview-patterns/)[**Topological sort**A topological sort of a directed acyclic graph (DAG) produces a linear ordering of vertices…](https://www.techinterview.org/post/3233461698/topological-sort-interview-patterns/)[**Union-Find (disjoint set)**Union-Find (DSU) solves the dynamic connectivity problem: given a graph where edges are added one…](https://www.techinterview.org/post/3233464033/union-find-dsu-interview-patterns/)[**Shortest paths (Dijkstra, Bellman-Ford)**Shortest path problems are fundamental in graph interviews. Knowing when to apply BFS, Dijkstra, Bellman-Ford,…](https://www.techinterview.org/post/3233463789/shortest-path-algorithm-patterns/)[**Minimum spanning tree**A Minimum Spanning Tree (MST) of a weighted undirected graph is a spanning tree (connects…](https://www.techinterview.org/post/3233465237/minimum-spanning-tree-interview-patterns/)[**Advanced graph algorithms**Finds shortest paths from a source to all nodes, handling negative edge weights. Algorithm: initialize…](https://www.techinterview.org/post/3233465014/advanced-graph-algorithms-interview-patterns/)
## Dynamic programming 11 guides
[**DP patterns: the overview**Dynamic programming applies when a problem has two properties: (1) Optimal substructure: the optimal solution…](https://www.techinterview.org/post/3233465644/dynamic-programming-patterns/)[**1-D DP**1D DP problems have a state space that reduces to a single index or value.…](https://www.techinterview.org/post/3233463177/dynamic-programming-1d-interview-patterns/)[**2-D and grid DP**2D DP Pattern Overview 2D dynamic programming problems use a 2D table where dp[i][j] represents…](https://www.techinterview.org/post/3233466996/dp-2d-patterns/)[**Knapsack patterns**The 0/1 Knapsack problem is one of the most important DP patterns — its structure…](https://www.techinterview.org/post/3233464194/dp-knapsack-patterns/)[**DP on strings**String DP problems share a common structure: a 2D table where one dimension indexes into…](https://www.techinterview.org/post/3233466948/dp-string-patterns/)[**Longest increasing subsequence**LIS: find the length of the longest strictly increasing subsequence of an array. Elements of…](https://www.techinterview.org/post/3233465443/longest-increasing-subsequence-interview-patterns/)[**Stock-trading DP**Stock trading dynamic programming problems are a classic interview cluster. Every variant - one transaction,…](https://www.techinterview.org/post/3233467043/dp-stock-patterns/)[**Interval DP**What is Interval DP? Interval DP is a dynamic programming pattern where you optimize over…](https://www.techinterview.org/post/3233467020/dp-intervals-patterns/)[**State-machine DP**State machine DP models problems as transitions between discrete states over a sequence. The key:…](https://www.techinterview.org/post/3233466264/dp-state-machine-patterns/)[**DP on trees**Tree DP solves optimization problems where the answer for each node depends on the answers…](https://www.techinterview.org/post/3233465704/dp-on-trees-interview-patterns/)[**Advanced DP (digit, bitmask, tree)**Tree DP, digit DP, and bitmask DP are three dynamic programming patterns, each matched to…](https://www.techinterview.org/post/3233461051/dynamic-programming-advanced-patterns/)
## Recursion, greedy & everything else 11 guides
[**Recursion patterns**Every recursive solution has: a base case (stops the recursion), a recursive case (reduces the…](https://www.techinterview.org/post/3233466479/recursion-patterns/)[**Backtracking**Backtracking is systematic trial and error — explore a decision tree, and when you reach…](https://www.techinterview.org/post/3233460794/backtracking-interview-patterns/)[**Divide & conquer**Divide and conquer solves problems by: (1) Divide — split the problem into smaller subproblems…](https://www.techinterview.org/post/3233461565/divide-and-conquer-interview-patterns/)[**Greedy patterns**Greedy algorithms make the locally optimal choice at each step. They are provably correct when…](https://www.techinterview.org/post/3233466876/greedy-patterns/)[**Interval algorithms**Interval problems appear constantly in coding interviews — at Google, Meta, Airbnb, and Uber. The…](https://www.techinterview.org/post/3233463966/interval-algorithm-interview-patterns/)[**Bit manipulation**Bit manipulation problems appear at Google, Meta, and Amazon interviews. They test low-level reasoning and…](https://www.techinterview.org/post/3233460816/bit-manipulation-interview-patterns/)[**Number theory**Euclidean algorithm: gcd(a,b) = gcd(b, a%b), base case gcd(a,0) = a. Time O(log min(a,b)). LCM:…](https://www.techinterview.org/post/3233467138/number-theory-patterns/)[**Math patterns**Math interview problems test number theory, combinatorics, and modular arithmetic. Common patterns: prime checking and…](https://www.techinterview.org/post/3233465524/math-interview-patterns/)[**Concurrency patterns**Concurrency problems appear at senior-level interviews (SDE-2 and above) at companies like Apple, Google, and…](https://www.techinterview.org/post/3233461782/concurrency-interview-patterns/)[**SQL question patterns**The recurring SQL patterns that show up across almost every database and data interview, each…](https://www.techinterview.org/post/3233476262/sql-interview-question-patterns/)[**LeetCode patterns by frequency**LeetCode has 3,000+ problems. You can't solve them all, and you don't need to. The…](https://www.techinterview.org/post/3233474682/leetcode-patterns-by-frequency/)
