20 Essential DSA Coding Patterns
Pattern FrameworkMaster the mental blueprints behind 95% of LeetCode & FAANG algorithmic interview problems.
0% syllabus completed
Instead of memorizing 500+ individual questions, recognizing these 20 patterns unlocks instant solution formulation during high-pressure live coding rounds.
Put these patterns to work on our curated 30-problem DSA sheets with full code walkthroughs.
1. Sliding Window
Problem asks for longest/shortest substring, sub-array with sum/target K, or contiguous elements.
2. Two Pointers
Sorted arrays or strings where you need pairs, triplets, or in-place swapping from opposite ends.
3. Fast & Slow Pointers (Hare & Tortoise)
Detecting cycles in a linked list, finding the middle node, or finding the start of a loop.
4. Merge Intervals
Problems involving overlapping intervals, calendar appointments, or ranges.
5. Cyclic Sort
Array contains numbers in a given range [1, N] or [0, N], asking to find missing, duplicate, or corrupted values.
6. In-place Reversal of a LinkedList
Reverse a sublist or full linked list without allocating auxiliary node storage.
7. Tree Breadth First Search (BFS)
Traverse trees level-by-level, find shortest paths, or connect level siblings.
8. Tree Depth First Search (DFS)
Path sums, height/diameter of tree, or sub-tree validation.
9. Two Heaps
Find median in a dynamic data stream or partition elements into two halves.
10. Subsets & Backtracking
Find all permutations, combinations, or power sets of elements.
11. Modified Binary Search
Searching for values in sorted or rotated arrays in O(log N) time.
12. Top "K" Elements
Find K largest, smallest, or most frequent items from an unsorted collection.
13. K-way Merge
Merging K sorted arrays or lists into a single consolidated sorted stream.
14. 0/1 Knapsack (Dynamic Programming)
Given items with weights and profits, find optimal combination under weight limit.
15. Topological Sort
Scheduling tasks with prerequisites, build order, or detecting cycles in directed graphs.
16. Monotonic Stack
Find the next greater or smaller element, daily temperatures, or largest rectangle in histogram.
17. Prefix Sum
Answering contiguous subarray sum queries in O(1) time, or counting subarrays with sum = K.
18. Union-Find (Disjoint Set Union)
Determining if two nodes belong to the same component, dynamic connectivity, or Kruskal minimum spanning tree.
19. Bit Manipulation
Numbers appearing twice except one, counting set bits, or subsets without recursion.
20. Trie (Prefix Tree)
Fast prefix lookups, dictionary word autocomplete, or prefix matching.