Coding InterviewsFeb 202620 min read

Top 50 DSA Patterns for Coding Interviews (2026 Cheat Sheet)

FS
FirstStep Team

1Introduction

There are over 3,000 problems on LeetCode. You don't need to solve all of them. In fact, the most efficient interview preparation strategy is to learn patterns — recurring problem-solving approaches that apply across hundreds of problems.

After analyzing 1,000+ coding interview questions from Google, Meta, Amazon, Apple, and Microsoft, we've identified the 50 most important patterns. Master these, and you'll be able to solve 95% of interview problems you encounter.

2Array & String Patterns

Algorithm visualization representing data structure patterns
1Two Pointers — Use two indices moving toward each other or in the same direction. Problems: Two Sum (sorted), Container With Most Water, Remove Duplicates.
2Sliding Window — Maintain a window that expands/contracts over an array. Problems: Maximum Subarray, Longest Substring Without Repeating Characters, Minimum Window Substring.
3Prefix Sum — Precompute cumulative sums for range queries. Problems: Subarray Sum Equals K, Product of Array Except Self.
4Kadane's Algorithm — Maximum subarray sum in O(n). The foundation for many DP problems on arrays.
5Dutch National Flag — Three-way partition (0s, 1s, 2s). Useful for sorting problems with limited values.
6Boyer-Moore Voting — Find majority element in O(n) time, O(1) space.
7Merge Intervals — Sort by start time, then merge overlapping intervals. Problems: Merge Intervals, Insert Interval, Meeting Rooms.
8Cyclic Sort — When array contains numbers 1 to n, place each number at index n-1. Problems: Find Missing Number, Find Duplicate.

3Hash Map & Set Patterns

9Frequency Counter — Count occurrences using a hash map. Problems: Top K Frequent Elements, Valid Anagram, Group Anagrams.
10Two Sum Pattern — Store complements in a hash map. Foundation for many pair-finding problems.
11Subarray Sum — Use prefix sum + hash map to find subarrays with target sum in O(n).
12Union-Find (Disjoint Set) — Track connected components. Problems: Number of Islands (alt), Accounts Merge, Redundant Connection.

4Linked List Patterns

13Fast & Slow Pointers — Detect cycles, find middle, detect palindrome. Problems: Linked List Cycle, Middle of Linked List, Happy Number.
14Reverse Linked List — In-place reversal. Foundation for: Reverse Nodes in k-Group, Palindrome Linked List.
15Merge Sorted Lists — Two-pointer merge. Extend to k sorted lists with a heap.
16Dummy Head — Use a dummy node to simplify edge cases when building a new list.

5Tree & Graph Patterns

Tree data structure visualization representing graph algorithms
17DFS (Depth-First Search) — Recursive/stack traversal. Problems: Max Depth, Path Sum, Validate BST, Serialize/Deserialize.
18BFS (Breadth-First Search) — Queue-based level-order traversal. Problems: Level Order Traversal, Minimum Depth, Right Side View.
19Binary Search on Trees — Leverage BST property (left < root < right). Problems: Search BST, Kth Smallest, LCA of BST.
20Tree Construction — Build trees from traversal arrays. Problems: Build from Inorder+Preorder, Build from Inorder+Postorder.
21Topological Sort — Order nodes in a DAG. Problems: Course Schedule, Alien Dictionary, Task Scheduler.
22Dijkstra's Algorithm — Shortest path in weighted graphs. Use with priority queue.
23Bellman-Ford — Shortest path with negative weights. Detects negative cycles.
24Graph Coloring / Bipartite — Check if graph can be 2-colored. Problems: Is Graph Bipartite, Possible Bipartition.

6Dynamic Programming Patterns

250/1 Knapsack — Choose items with weight/value constraints. Problems: Partition Equal Subset Sum, Target Sum.
26Unbounded Knapsack — Items can be reused. Problems: Coin Change, Perfect Squares, Ribbon Cut.
27Fibonacci Pattern — Current state depends on previous 1–2 states. Problems: Climbing Stairs, House Robber, Decode Ways.
28Longest Common Subsequence (LCS) — 2D DP on two strings. Problems: LCS, Edit Distance, Longest Palindromic Subsequence.
29Longest Increasing Subsequence (LIS) — O(n²) DP or O(n log n) binary search. Foundation for many sequence problems.
30Matrix Chain / Interval DP — Solve subproblems over intervals. Problems: Burst Balloons, Matrix Multiplication, Palindrome Partitioning.
31Bitmask DP — Use bits to represent subsets. Problems: Travelling Salesman, Partition to K Equal Sum Subsets.
32State Machine DP — Model problems with states and transitions. Problems: Best Time to Buy and Sell Stock (all variants).

7Binary Search Patterns

33Classic Binary Search — Search sorted array in O(log n).
34Binary Search on Answer — When the answer is monotonic, binary search the solution space. Problems: Koko Eating Bananas, Split Array Largest Sum, Minimum Days to Make Bouquets.
35Find Boundary — Find first/last occurrence, or boundary between true/false. Problems: First Bad Version, Search Insert Position.
36Search in Rotated Array — Modified binary search handling the rotation point.

8Heap & Greedy Patterns

37Top K Elements — Use a min-heap of size K. Problems: Top K Frequent, Kth Largest Element, K Closest Points.
38Merge K Sorted — Use a min-heap to merge K sorted lists/arrays.
39Two Heaps — Use max-heap + min-heap for median finding. Problems: Find Median from Data Stream, Sliding Window Median.
40Interval Scheduling — Greedy: sort by end time, pick non-overlapping. Problems: Non-overlapping Intervals, Meeting Rooms II.
41Huffman-style Greedy — Always process the smallest/largest first. Problems: Minimum Cost to Connect Sticks, Reorganize String.

9Backtracking & Advanced Patterns

42Subsets/Combinations — Generate all subsets or combinations of size k. Build decision tree with include/exclude.
43Permutations — Generate all arrangements. Use visited array or swap technique.
44Grid DFS/BFS — Traverse 2D grids. Problems: Number of Islands, Word Search, Shortest Path in Binary Matrix.
45Trie (Prefix Tree) — Efficient string prefix operations. Problems: Implement Trie, Word Search II, Auto-complete.
46Monotonic Stack — Maintain stack in increasing/decreasing order. Problems: Next Greater Element, Largest Rectangle in Histogram, Daily Temperatures.
47Segment Tree / BIT — Range queries and point updates in O(log n). Problems: Range Sum Query, Count of Smaller Numbers.
48Reservoir Sampling — Random sampling from a stream of unknown size.
49Bit Manipulation — XOR tricks, counting bits, subset enumeration. Problems: Single Number, Counting Bits, Power of Two.
50Math Patterns — GCD/LCM, modular arithmetic, prime sieve, combinatorics. Problems: Count Primes, Pow(x,n), Factorial Trailing Zeros.

10How to Study These Patterns

Don't memorize solutions. Understand patterns:

1Learn one pattern at a time. Solve 3–5 problems for each pattern.
2When stuck for 20 minutes, read the solution approach (not the code). Then implement it yourself.
3After solving, ask: "What pattern did I use? Where else could I apply it?"
4Review previously solved problems weekly to reinforce pattern recognition.
5Use FirstStep's coding practice resources to work through curated problem sets organized by pattern.

Recommended pace: 2–3 problems per day, 5 days per week. In 8–10 weeks, you'll cover all 50 patterns with enough practice.

11Final Thoughts

Coding interviews are pattern recognition tests, not IQ tests. The candidates who succeed aren't necessarily the smartest — they're the ones who've internalized the most patterns.

Master these 50 patterns, and you'll walk into any coding interview knowing that the problem in front of you is a variation of something you've already solved.

At FirstStep, we help candidates prepare for coding interviews with our structured Interview Prep tools and curated problem sets organized by pattern. Start practicing today — your FAANG offer is 50 patterns away.

Prepare with FirstStep

AI mock interviews, resume builder, and expert coaching — everything you need to land your dream role.