HomeCoursesBlog
← Back to Blog
Article

The DSA Patterns Cheat Sheet: All 41 on One Page

The DSA Patterns Cheat Sheet: All 41 on One Page

TL;DR: This is the full list of the 41 patterns that cover coding interview questions: 30 common patterns and 11 advanced ones. Each row gives the tell, meaning the words or structures in a question that identify the pattern. It also gives the data structure it needs and the complexity to quote. Bookmark this page and use it as a lookup while you practice.

Interview questions are not unique. They are generated from a small set of reusable families, and each family has a tell: specific features in the question that give it away.

Once you can name the family, most of the work is done. The template is known, the complexity is known, and the remaining effort goes into writing the code carefully.

This page is the reference version of that idea. No essay, just the map. If you want the reasoning behind pattern-based preparation, the complete patterns guide covers it. If you want the code, the 10 templates on one page has it.

All 41 coding interview patterns grouped into arrays and strings, stacks and lists, trees and graphs, search and selection, recursion and dynamic programming, plus the 11 advanced patterns

How to use this sheet

Read the question once. Then look for a phrase in the lookup table below, and check the matching pattern in the full list.

Two rules make this work:

  1. Look for the tell before you look for a solution. Most wrong answers come from starting to code before naming the family.
  2. If two patterns fit, say both out loud. Interviewers grade the reasoning. Naming two candidates and choosing between them scores better than silently picking one.

The fast lookup: from phrase to pattern

These are the phrases that appear most often in questions, and what each one usually means.

The question saysReach the pattern
"longest / shortest substring or subarray"Sliding Window
"contiguous" plus a fixed sizeSliding Window
"sorted array" plus "pair" or "triplet"Two Pointers
"cycle" in a linked listFast and Slow Pointers
"overlapping" or "merge" rangesMerge Intervals
"numbers from 1 to n" with one missing or duplicatedCyclic Sort
"reverse" a linked list or part of oneIn-place Reversal of a Linked List
"valid parentheses", "nested", "undo"Stacks
"next greater" or "next smaller" elementMonotonic Stack
"count", "group by", "have we seen this"Hash Maps
"level by level" in a treeTree Level Order Traversal
"root to leaf" or "path sum"Tree Depth First Search
"connected", "shortest path", unweightedGraphs
a 2D grid with regions to countIsland (Matrix Traversal)
"median" of a running streamTwo Heaps
"all subsets", "all permutations", "all combinations"Subsets
"sorted" plus "find the first or last position"Modified Binary Search
"every element appears twice except one"Bitwise XOR
"top K", "K most frequent", "K closest"Top K Elements
"merge K sorted lists"K-way Merge
"maximum number of meetings", "minimum coins"Greedy Algorithms
"pick or skip" with a capacity limit0/1 Knapsack
"ways to climb", "state depends on the last two"Fibonacci Numbers
"longest palindromic substring or subsequence"Palindromic Subsequence
"place N queens", "solve the board", constraintsBacktracking
"prefix", "autocomplete", "starts with"Trie
"prerequisites", "build order", "dependencies"Topological Sort
"are these two in the same group", merging groupsUnion Find
need sorted order plus fast insert and deleteOrdered Set
repeated "sum between index i and j" queriesPrefix Sum
"synchronize", "two threads alternate"Multi-threaded

The 30 common patterns

These cover the large majority of interview questions. Learn these first.

Arrays and strings

PatternThe tellStructure usedTypical complexity
Two PointersSorted input, find a pair or tripletTwo indicesO(n) time, O(1) space
Fast and Slow PointersCycle detection, find the middleTwo moving indicesO(n) time, O(1) space
Sliding WindowLongest or shortest contiguous runWindow plus a hash mapO(n) time, O(k) space
Merge IntervalsOverlapping ranges, meeting roomsSort, then scanO(n log n) time
Cyclic SortValues are 1 to n, one missing or duplicatedSwap into placeO(n) time, O(1) space
Prefix SumMany range sum queries, subarray summing to KRunning total arrayO(n) build, O(1) per query
Hash MapsCounting, grouping, seen beforeHash mapO(n) time, O(n) space

Stacks and linked lists

PatternThe tellStructure usedTypical complexity
StacksNested structure, matching pairs, undoStackO(n) time, O(n) space
Monotonic StackNext greater or smaller elementStack kept in orderO(n) time, O(n) space
In-place Reversal of a Linked ListReverse a list or a sublist, no extra spaceThree pointersO(n) time, O(1) space

Trees and graphs

PatternThe tellStructure usedTypical complexity
Tree Level Order TraversalOutput grouped by levelQueueO(n) time, O(w) space
Tree Depth First SearchRoot to leaf paths, subtree propertiesRecursion or stackO(n) time, O(h) space
GraphsConnectivity, shortest path when unweightedAdjacency list plus queueO(V + E) time
Island (Matrix Traversal)2D grid, count or fill regionsGrid searchO(rows x cols) time
Topological SortPrerequisites, build order, a directed acyclic graphIn-degree counts plus queueO(V + E) time
Union FindAre two items in the same group, merge groupsDisjoint setNear O(1) per operation
TriePrefix search, autocomplete, dictionaryTrieO(L) per word

Search and selection

PatternThe tellStructure usedTypical complexity
Modified Binary SearchSorted or rotated input, find a boundaryTwo boundsO(log n) time
Top K ElementsK largest, K smallest, K most frequentHeapO(n log k) time
K-way MergeMerge K sorted lists or arraysMin heapO(n log k) time
Two HeapsMedian of a stream, split into halvesMax heap plus min heapO(log n) per insert
Ordered SetSorted order plus fast insert, delete, lookupBalanced tree or ordered setO(log n) per operation
Bitwise XOREvery element appears twice except oneXOR accumulatorO(n) time, O(1) space

Recursion and dynamic programming

PatternThe tellStructure usedTypical complexity
SubsetsAll subsets, permutations, or combinationsRecursion, building upO(2^n) or O(n!)
BacktrackingConstraints, place and undo, board puzzlesRecursion plus undo stepExponential, pruned
Greedy AlgorithmsBest local choice each step, schedulingSort, then one passO(n log n) time
0/1 KnapsackPick or skip each item, capacity limit2D tableO(n x capacity)
Fibonacci NumbersState depends on the previous one or two1D tableO(n) time, O(1) space possible
Palindromic SubsequenceLongest palindromic substring or subsequence2D tableO(n^2) time

Concurrency

PatternThe tellStructure usedTypical complexity
Multi-threadedSynchronize threads, alternate output, shared stateLocks, semaphores, conditionsDepends on the design

The 11 advanced patterns

These appear in senior loops and in harder rounds. Learn them after the common ones are solid.

PatternLevelThe tell
CountingEasyCount occurrences to shortcut a scan, bucket by value
Monotonic QueueEasySliding window maximum or minimum
SimulationEasyFollow the described process step by step, no clever trick
Linear Sorting AlgorithmEasySmall fixed value range, sort faster than O(n log n)
Meet in the MiddleMediumSearch space too large, split it in half and combine
MO's AlgorithmMediumMany offline range queries on a static array
Serialize and DeserializeMediumConvert a structure to a string and back
CloneMediumDeep copy a graph or a list with random pointers
Articulation Points and BridgesHardWhich node or edge disconnects the graph if removed
Segment TreeHardRange queries with updates between them
Binary Indexed TreeHardPrefix sums with updates, less code than a segment tree

The order to learn them in

Do not work down the list from top to bottom. Each stage below reuses machinery from the one before it.

  1. Arrays and strings: Two Pointers, Sliding Window, Prefix Sum, Hash Maps
  2. Linked lists: Fast and Slow Pointers, In-place Reversal
  3. Stacks: Stacks, Monotonic Stack
  4. Trees: Tree Depth First Search, then Tree Level Order Traversal
  5. Graphs: Graphs, Island, Topological Sort, Union Find
  6. Heaps and intervals: Top K Elements, K-way Merge, Two Heaps, Merge Intervals
  7. Recursion: Subsets, then Backtracking
  8. Dynamic programming: Fibonacci Numbers, 0/1 Knapsack, Palindromic Subsequence
  9. The rest: Trie, Bitwise XOR, Cyclic Sort, Ordered Set, Greedy, Multi-threaded
  10. Advanced tier, only if your loop calls for it

About 14 of these cover most questions asked in a standard loop. The rest matter when a question falls outside the core, which happens often enough to be worth knowing the map.

Grokking the Coding Interview teaches all 41 in this order. Each one comes as a tell, a template, and a set of variations, with problems grouped so that recognition builds instead of memory.

How to practice with this sheet

Reading a cheat sheet does not install recognition. Use it as a drill instead.

The diagnosis drill. Open ten random problems. Do not solve any of them. For each one, write down the pattern name and the phrase that told you. Then check your answers. Ten minutes, and it trains the exact skill the first two minutes of an interview needs.

The cover-up drill. Hide the tell column. Read a pattern name and say the tell out loud from memory. Any pattern you cannot describe is one you have not learned yet.

Spaced review. Revisit a pattern three days after you learn it, then a week later. Recognition fades faster than people expect.

For how many problems this takes in total, see how many LeetCode problems you actually need. The number is smaller than most people assume, and it is closer to 100 to 150 when practice is organized by pattern.

Frequently asked questions

How many DSA patterns are there for coding interviews? There are 41 in this list: 30 common patterns and 11 advanced ones. About 14 of the common patterns cover most questions in a standard interview loop, and the advanced tier appears mainly in senior rounds.

Which patterns should I learn first? Start with Two Pointers, Sliding Window, Hash Maps, and Prefix Sum. They apply to the largest share of array and string questions and they build the habits the later patterns reuse.

Do I need all 41 patterns for a FAANG interview? No. The core 14 cover the majority of what is asked. The rest are worth knowing so that an unfamiliar question does not read as impossible, since it usually belongs to a named family.

Is a cheat sheet enough to prepare? No. A cheat sheet gives you the map, not the skill. You need to solve problems grouped by pattern so recognition becomes automatic, and you need to practice explaining your reasoning out loud.

How is a pattern different from a data structure? A data structure is a way to store data, like a heap or a trie. A pattern is a reusable way to handle a family of questions. It usually specifies which data structure to use, plus the shape of the code around it.

What if a question does not match any pattern? Most do. When one does not, it is usually two patterns combined, for example a sliding window that maintains a monotonic queue inside it. Name both parts out loud and build the solution from the pieces.

Learn all 41 the way this sheet lists them: Grokking the Coding Interview: Patterns for Coding Questions teaches every pattern as a tell, a template, and a set of variations, with more than 300 hand-picked problems in Python, Java, JavaScript, C++, C#, and Go. It costs $79 once, with lifetime access.

Grokking the Coding Interview
One-Stop Portal For Coding Interviews.
Follow us:
Copyright © 2025 Coding Interview All rights reserved.