Top 15 DSA Patterns for Interviews and Online
Coding Rounds
Mastering problem-solving patterns in Data Structures and Algorithms (DSA) helps to solve a wide
variety of coding interview questions efficiently. Below are 15 commonly asked patterns: 1. **Sliding
Window** - Used for problems involving subarrays or substrings (fixed or variable size). - Example:
Maximum sum subarray of size k, Longest substring without repeating characters. 2. **Two
Pointers** - Involves two pointers moving inward or outward in a sorted array or string. - Example:
Pair sum in sorted array, Valid palindrome check. 3. **Fast & Slow Pointers (Floyd’s Cycle
Detection)** - Detects cycles in linked lists or arrays. - Example: Detect cycle in linked list, Find
middle of linked list. 4. **Merge Intervals** - Used in scheduling and interval problems. - Example:
Merge overlapping intervals, Insert interval. 5. **Cyclic Sort** - Efficient for arrays containing
numbers in a given range. - Example: Find missing number, Find duplicate. 6. **In-place Reversal
of Linked List** - Reverses linked lists or sublists without extra space. - Example: Reverse a linked
list, Reverse nodes in k-group. 7. **Tree BFS** - Level-order traversal using a queue. - Example:
Binary tree level order traversal, Zigzag traversal. 8. **Tree DFS (Preorder, Inorder, Postorder)** -
Depth-first traversal for solving recursive tree problems. - Example: Path sum, Maximum depth of
binary tree. 9. **Two Heaps** - For problems involving median or scheduling. - Example: Find
median from data stream, Meeting rooms II. 10. **Subsets (Backtracking / Bitmasking)** - Generate
all combinations or subsets. - Example: Subsets, Permutations, Combination sum. 11. **Modified
Binary Search** - Variations of binary search for rotated or infinite arrays. - Example: Search in
rotated sorted array, Find first/last occurrence. 12. **Top K Elements (Heap / QuickSelect)** -
Extract top k largest/smallest elements efficiently. - Example: Kth largest element, Top K frequent
elements. 13. **K-way Merge** - Merge multiple sorted arrays/lists using heaps. - Example: Merge
k sorted lists, Smallest range in k lists. 14. **0/1 Knapsack (Dynamic Programming)** -
Fundamental DP pattern for optimization problems. - Example: Subset sum, Partition equal subset
sum. 15. **Topological Sort (Graph)** - Ordering of vertices in a Directed Acyclic Graph (DAG). -
Example: Course schedule, Alien dictionary. **Conclusion** These 15 patterns cover a majority of
coding interview problems. Instead of memorizing solutions, focus on recognizing which pattern
applies to a problem. This improves speed, accuracy, and confidence in interviews.