DSA Patterns Sheet
The DSA Patterns Sheet organises 410 data structures and algorithms problems by the technique that solves them, not by the data structure they happen to mention: 16 pattern families broken into 100 subpatterns, each with the problems that drill it.
A pattern is a reusable line of reasoning. Recognising that a question is a sliding window question is most of the work; the code that follows is short and nearly always the same shape. That is why a candidate who has solved two hundred problems at random can still be beaten by one who has worked through 16 patterns deliberately — the second one recognises the unseen question, and the first only recognises the seen one.
How to use the sheet
Take one pattern at a time. Read the pattern page, solve the easiest problem under it without help, then the medium ones until the setup stops feeling like a decision. Mark each row done, bookmark the ones you fumbled, and come back to the bookmarks a week later rather than to the whole list. Every row links to the problem in the browser editor, to its editorial, and to an AI mock interview on that specific pattern; code runs in 6 languages — Python, C++, Java, JavaScript, Go, C#.
Progress is stored against your account, so the sheet doubles as the record of what you have covered. You can filter it by company to see how a target company's evidenced questions land across the same patterns.
The 16 pattern families
- Array & Matrix Manipulation Patterns10 subpatterns — Merge Sorted Array (In-place from End), Spiral Traversal, Set Matrix Zeroes (In-place Marking), Hashing - Frequency Map / Counting, Prefix Sum - Subarray Sum / Range Query, Product Except Self (Prefix/Suffix Products), Plus One (Handling Carry), Array - Cyclic Sort, Hashing - Previously Seen / Existence Check, In-place Rotation
- Linked List Manipulation Patterns5 subpatterns — Reordering / Partitioning, In-place Reversal, Merging Two Sorted Lists, Addition of Numbers, Intersection Detection
- Two Pointers Pattern7 subpatterns — Fast & Slow (Cycle Detection), Converging (Sorted Array Target Sum), Expanding From Center (Palindromes), String Comparison with Backspaces, String Reversal, In-place Array Modification, Fixed Separation (Nth Node from End)
- Sliding Window Pattern4 subpatterns — Fixed Size (Subarray Calculation), Monotonic Queue for Max/Min, Variable Size (Condition-Based), Character Frequency Matching
- Binary Search Patterns5 subpatterns — On Sorted Array/List, Find First/Last Occurrence, Find Min/Max in Rotated Sorted Array, Median and Kth of Two Sorted Arrays, On Answer / Condition Function
- Stack Patterns6 subpatterns — Valid Parentheses Matching, Monotonic Stack, Largest Rectangle in Histogram, Stack - Min Stack Design, Simulation / Backtracking Helper, Expression Evaluation (RPN/Infix)
- String Manipulation Patterns7 subpatterns — Repeated Substring Pattern Detection, Naive / KMP / Rabin-Karp, Palindrome Check (Two Pointers / Reverse), Integer and Roman Conversion, Multiply Strings (Manual Simulation), String to Integer (atoi), Anagram Check (Frequency Count/Sort)
- Heap and Priority Queue Patterns4 subpatterns — K-way Merge, Top K Elements (Selection/Frequency), Scheduling / Minimum Cost (Greedy with Priority Queue), Two Heaps for Median Finding
- Tree Traversal Patterns - DFS and BFS6 subpatterns — Recursive Preorder Traversal, Recursive Inorder Traversal, Level Order Traversal, Recursive Postorder Traversal, Serialization and Deserialization, Lowest Common Ancestor (LCA) Finding
- Graph Traversal Patterns - DFS and BFS12 subpatterns — Graph DFS - Connected Components / Island Counting, Graph BFS - Connected Components / Island Counting, Graph BFS - Topological Sort (Kahn's Algorithm), Graph DFS - Cycle Detection (Directed Graph), Shortest Path (Bellman-Ford / BFS+K), Shortest Path (Dijkstra's Algorithm), Deep Copy / Cloning, Bidirectional BFS (BFS optimization for known source & target), Bridges & Articulation Points (Tarjan low-link), Union-Find (Disjoint Set Union - DSU), Minimum Spanning Tree (Kruskal / Prim / DSU + heap), Strongly Connected Components (Kosaraju / Tarjan)
- Greedy Algorithm Patterns7 subpatterns — Jump Game Reachability/Minimization, Sorting Based, Task Scheduling (Frequency Based), Interval Merging/Scheduling, Line Sweep, Gas Station Circuit, Buy/Sell Stock
- Backtracking Patterns7 subpatterns — Word Search / Path Finding in Grid, N-Queens / Constraint Satisfaction, Permutations, Palindrome Partitioning, Combination Sum, Subsets (Include/Exclude), Parentheses Generation
- Dynamic Programming Patterns12 subpatterns — 2D Array (Edit Distance / Levenshtein Distance), 1D Array (Kadane's Algorithm for Max/Min Subarray), Interval DP, 2D Array (Unique Paths on Grid), 1D Array (Fibonacci Style), 1D Array (0/1 Knapsack Subset Sum Style), 2D Array (Longest Common Subsequence - LCS), Catalan Numbers, 1D Array (Word Break Style), Stock problems, 1D Array (Coin Change / Unbounded Knapsack Style), Longest Increasing Subsequence (LIS)
- Bit Manipulation Patterns4 subpatterns — Bitwise Operations - Power of Two/Four Check, Bitwise XOR - Finding Single/Missing Number, Bitwise DP - Counting Bits Optimization, Bitwise AND - Counting Set Bits (Hamming Weight)
- Design Patterns - Data Structure Implementation2 subpatterns — Tries, Design (General/Specific)
- Segment Tree and Fenwick Tree Patterns2 subpatterns — Fenwick Tree (BIT) - Prefix Queries / Inversions, Segment Tree - Range Sum with Point Update
All 404 problems by pattern
Graph Traversal Patterns (DFS & BFS) (60)
- Accounts Merge
- Alien Dictionary
- All Paths from Source Lead to Destination
- Build a Matrix With Conditions
- Bus Routes
- Cheapest Flights Within K Stops
- Clone Graph
- Clone N-ary Tree
- Connecting Cities With Minimum Cost
- Copy List with Random Pointer
- Count Sub Islands
- Course Schedule
- Course Schedule II
- Critical Connections in a Network
- Detonate the Maximum Bombs
- Find All Possible Recipes from Given Supplies
- Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree
- Find Eventual Safe States
- Find the City With the Smallest Number of Neighbors at a Threshold Distance
- Find the Safest Path in a Grid
- Flood Fill
- Graph Valid Tree
- Keys and Rooms
- Largest Color Value in a Directed Graph
- Largest Component Size by Common Factor
- 01 Matrix
- Max Area of Island
- Min Cost to Connect All Points
- Minimum Height Trees
- Minimum Obstacle Removal to Reach Corner
- Minimum Time to Visit a Cell In a Grid
- Minimum Weighted Subgraph With the Required Paths
- Most Stones Removed with Same Row or Column
- Network Delay Time
- Number of Closed Islands
- Number of Connected Components in an Undirected Graph
- Number of Enclaves
- Number of Islands
- Number of Islands II
- Number of Provinces
- Number of Ways to Arrive at Destination
- Optimize Water Distribution in a Village
- Pacific Atlantic Water Flow
- Parallel Courses
- Parallel Courses III
- Path with Maximum Probability
- Path With Minimum Effort
- Redundant Connection
- Regions Cut By Slashes
- Rotting Oranges
- Second Minimum Time to Reach Destination
- Sentence Similarity II
- Sequence Reconstruction
- Shortest Path in Binary Matrix
- Shortest Path with Alternating Colors
- Surrounded Regions
- Swim in Rising Water
- The Earliest Moment When Everyone Become Friends
- Word Ladder
- Word Ladder II
Array/Matrix Manipulation Patterns (24)
- Add Binary
- Add to Array-Form of Integer
- Diagonal Traverse
- Find All Duplicates in an Array
- Find All Numbers Disappeared in an Array
- First Missing Positive
- Game of Life
- Group Anagrams
- Longest Mountain in Array
- Merge Sorted Array
- Multiply Strings
- Plus One
- Product of Array Except Self
- Product of the Last K Numbers
- Rotate Array
- Rotate Image
- Set Matrix Zeroes
- Spiral Matrix
- Spiral Matrix II
- Spiral Matrix III
- Spiral Matrix IV
- Transpose Matrix
- Two Sum
- Valid Anagram
Linked List Manipulation Patterns (16)
- Add Two Numbers
- Intersection of Two Linked Lists
- Merge Two Sorted Lists
- Minimum Index Sum of Two Lists
- Odd Even Linked List
- Palindrome Linked List
- Partition List
- Plus One Linked List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List II
- Reorder List
- Reverse a Linked List
- Reverse Linked List II
- Reverse Nodes in k-Group
- Rotate List
- Swap Nodes in Pairs
Tree Traversal Patterns (DFS & BFS) (33)
- All Nodes Distance K in Binary Tree
- Balanced Binary Tree
- Binary Search Tree Iterator
- Binary Tree Inorder Traversal
- Binary Tree Level Order Traversal
- Binary Tree Maximum Path Sum
- Binary Tree Paths
- Binary Tree Postorder Traversal
- Binary Tree Right Side View
- Binary Tree Zigzag Level Order Traversal
- Construct Binary Tree from Preorder and Inorder Traversal
- Delete Nodes And Return Forest
- Diameter of Binary Tree
- Find Duplicate Subtrees
- Find Largest Value in Each Tree Row
- Find Leaves of Binary Tree
- Find Mode in Binary Search Tree
- Flatten Binary Tree to Linked List
- Height of Binary Tree After Subtree Removal Queries
- House Robber III
- Invert Binary Tree
- Kth Smallest Element in a BST
- Lowest Common Ancestor of a Binary Search Tree
- Lowest Common Ancestor of a Binary Tree
- Maximum Depth of Binary Tree
- Maximum Level Sum of a Binary Tree
- Minimum Absolute Difference in BST
- Same Tree
- Serialize and Deserialize Binary Tree
- Smallest String Starting From Leaf
- Subtree of Another Tree
- Symmetric Tree
- Validate Binary Search Tree
Design Patterns (35)
- All O`one Data Structure
- Design Add and Search Words Data Structure
- Design a Stack With Increment Operation
- Design a Text Editor
- Design Circular Deque
- Design Circular Queue
- Design Compressed String Iterator
- Design HashMap
- Design Hit Counter
- Design Most Recently Used Queue
- Design Phone Directory
- Design Search Autocomplete System
- Design Snake Game
- Detect Squares
- Encode and Decode Strings
- Flatten 2D Vector
- Flatten Nested List Iterator
- Implement Queue using Stacks
- Implement Stack using Queues
- Implement Trie (Prefix Tree)
- Insert Delete GetRandom O(1)
- LFU Cache
- Logger Rate Limiter
- Longest Word in Dictionary
- LRU Cache
- Prefix and Suffix Search
- Range Module
- Replace Words
- RLE Iterator
- Smallest Number in Infinite Set
- Snapshot Array
- Stock Price Fluctuation
- Time Based Key-Value Store
- Tweet Counts Per Frequency
- Word Squares
Greedy Patterns (14)
Stack Patterns (25)
- Asteroid Collision
- Basic Calculator
- Basic Calculator II
- Basic Calculator III
- Daily Temperatures
- Decode String
- Evaluate Reverse Polish Notation
- Final Prices With a Special Discount in a Shop
- Find the Most Competitive Subsequence
- Largest Rectangle in Histogram
- Longest Valid Parentheses
- Maximal Rectangle
- Maximum Frequency Stack
- Maximum Width Ramp
- Minimum Add to Make Parentheses Valid
- Minimum Number of Swaps to Make the String Balanced
- Minimum Remove to Make Valid Parentheses
- Min Stack
- Next Greater Element I
- Next Greater Element II
- Online Stock Span
- Remove K Digits
- Simplify Path
- Sum of Subarray Minimums
- Valid Parentheses
Two Pointers (34)
- Backspace String Compare
- Boats to Save People
- Container With Most Water
- Crawler Log Folder
- Delete the Middle Node of a Linked List
- Find the Duplicate Number
- 4Sum
- Happy Number
- Intersection of Two Arrays
- Is Subsequence
- Linked List Cycle
- Longest Palindromic Substring
- Middle of the Linked List
- Move Pieces to Obtain a String
- Move Zeroes
- Palindromic Substrings
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array II
- Remove Element
- Remove Nth Node From End of List
- Removing Stars From a String
- Reverse String
- Reverse String II
- Reverse Vowels of a String
- Reverse Words in a String
- Separate Black and White Balls
- Sort Array By Parity
- Sort Colors
- Squares of a Sorted Array
- String Compression
- 3Sum Closest
- 3Sum Smaller
- 3Sum
- Two Sum II - Input Array Is Sorted
Dynamic Programming (DP) Patterns (45)
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock III
- Best Time to Buy and Sell Stock IV
- Best Time to Buy and Sell Stock with Cooldown
- Burst Balloons
- Climbing Stairs
- Coin Change
- Coin Change II
- Combination Sum IV
- Count Square Submatrices with All Ones
- Decode Ways
- Delete and Earn
- Delete Operation for Two Strings
- Different Ways to Add Parentheses
- Edit Distance
- Fibonacci Number
- House Robber
- House Robber II
- Longest Common Subsequence
- Longest Increasing Subsequence
- Longest Increasing Subsequence II
- Maximal Square
- Maximum Absolute Sum of Any Subarray
- Maximum Product Subarray
- Maximum Subarray
- Maximum Sum Circular Subarray
- Min Cost Climbing Stairs
- Minimum ASCII Delete Sum for Two Strings
- Minimum Falling Path Sum
- Minimum Insertion Steps to Make a String Palindrome
- Minimum Number of Removals to Make Mountain Array
- Minimum Path Sum
- Partition Equal Subset Sum
- Remove Boxes
- Russian Doll Envelopes
- Shortest Common Supersequence
- Target Sum
- Triangle
- Unique Binary Search Trees
- Unique Binary Search Trees II
- Unique Paths
- Unique Paths II
- Word Break
- Word Break II
Binary Search Patterns (26)
- Binary Search
- Capacity To Ship Packages Within D Days
- Find First and Last Position of Element in Sorted Array
- Find in Mountain Array
- Find K Closest Elements
- Find K-th Smallest Pair Distance
- Find Minimum in Rotated Sorted Array
- Find Peak Element
- First Bad Version
- Guess Number Higher or Lower
- Koko Eating Bananas
- Kth Missing Positive Number
- Maximum Candies Allocated to K Children
- Median of Two Sorted Arrays
- Minimized Maximum of Products Distributed to Any Store
- Minimize Max Distance to Gas Station
- Minimum Limit of Balls in a Bag
- Minimum Number of Days to Make m Bouquets
- Peak Index in a Mountain Array
- Search a 2D Matrix
- Search in Rotated Sorted Array
- Search in Rotated Sorted Array II
- Search Insert Position
- Single Element in a Sorted Array
- Split Array Largest Sum
- Sqrt(x)
Sliding Window (30)
- Calculate Compressed Mean
- Contains Duplicate II
- Continuous Subarrays
- Find All Anagrams in a String
- Find Longest Special Substring That Occurs Thrice I
- Find the Power of K-Size Subarrays I
- Find X-Sum of All K-Long Subarrays I
- Frequency of the Most Frequent Element
- Fruit Into Baskets
- Jump Game VI
- Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
- Longest Repeating Character Replacement
- Longest Subarray of 1's After Deleting One Element
- Longest Substring Without Repeating Characters
- Max Consecutive Ones III
- Maximum Average Subarray I
- Maximum Beauty of an Array After Applying Operation
- Maximum Frequency of an Element After Performing Operations I
- Maximum Frequency of an Element After Performing Operations II
- Maximum Good Subarray Sum
- Maximum Sum of Distinct Subarrays With Length K
- Minimum Operations to Reduce X to Zero
- Minimum Size Subarray Sum
- Minimum Window Substring
- Moving Average from Data Stream
- Permutation in String
- Shortest Subarray with Sum at Least K
- Sliding Window Maximum
- Subarray Product Less Than K
- Take K of Each Character From Left and Right
Backtracking Patterns (19)
- Check if Word Can Be Placed In Crossword
- Combinations
- Combination Sum
- Combination Sum II
- Generate Parentheses
- Letter Combinations of a Phone Number
- Next Permutation
- N-Queens
- Palindrome Partitioning
- Palindrome Partitioning II
- Permutations
- Permutation Sequence
- Pseudo-Palindromic Paths in a Binary Tree
- Remove Invalid Parentheses
- Subsets
- Subsets II
- Sudoku Solver
- Word Search
- Word Search II
Heap (Priority Queue) Patterns (22)
- Finding MK Average
- Find K Pairs with Smallest Sums
- Find Median from Data Stream
- Furthest Building You Can Reach
- K Closest Points to Origin
- Kth Largest Element in an Array
- Kth Largest Element in a Stream
- Kth Smallest Element in a Sorted Matrix
- Last Stone Weight
- Maximum Average Pass Ratio
- Meeting Rooms II
- Meeting Rooms III
- Merge k Sorted Lists
- Minimum Cost to Hire K Workers
- Relative Ranks
- Reorganize String
- Single-Threaded CPU
- Smallest Range Covering Elements from K Lists
- Sort Characters By Frequency
- Take Gifts From the Richest Pile
- The Number of the Smallest Unoccupied Chair
- Top K Frequent Elements