I invested 4+ hours to create this pattern recognition cheatsheet for DSA and coding interviews. This will help you solve 90% of all DSA problems in interviews (based on my mentoring experience over the last 8+ years) ◄ Array / String Inputs 1. Is the array sorted? → Use Binary Search, Two Pointers, or Prefix Sums 2. Optimization problems (Max/Min/Subarray)? → Think Sliding Window, Dynamic Programming, or Greedy 3. Looking for duplicates / counts / frequencies? → Use HashMap, HashSet, or Counting Array 4. Need substrings or fixed-size subarrays? → Apply Sliding Window with Two Pointers 5. Frequent min/max in window? → Use Monotonic Queue, Deque, or Heap 6. Generating subsets, permutations, combinations? → Use Backtracking 7. Matching / parsing characters? → Use Stack, especially for Balanced Parentheses, Infix/Postfix Most people struggle with DSA because they think they have weak logic. But mostly, it’s because their approach is completely wrong. If you want to solve problems fast and with solid accuracy, you need to think in patterns. Without patterns, you can solve every problem in an interview that you’ve seen once, but once you see a new problem, you will get stuck. That’s why I’ve put together this DSA Pattern Sheet, which helps you: ✅ identify key patterns and learn when to apply them. ✅ understand scenarios and clues that signal which approach to use. ✅ practice with 5-6 leetcode problems per pattern to solidify learning. ✅ cover 250-300 essential problems, ensuring you master every core concept. ✅ customize the sheet to track progress and adapt it to your needs. Link: https://lnkd.in/g94khGEh ◄ Graph Inputs 1. Shortest path in unweighted graph? → Use Breadth-First Search (BFS) 2. Weighted shortest path? → Use Dijkstra, Bellman-Ford, or A\ 3. Connected components / cycle detection? → Use DFS, Union-Find (DSU) 4. Topological ordering? → Use Kahn’s Algorithm or DFS + visited set 5. Optimization like MST? → Use Kruskal or Prim’s Algorithm ◄ Tree Inputs (Often Binary Trees) 1. Traversals? → Use Inorder, Preorder, Postorder, or Level-order (BFS) 2. Balanced checks or diameter calculations? → Use Postorder + height calculations 3. Lowest Common Ancestor? → Use Recursive DFS or Parent Map + Ancestor Set ◄ Linked List Inputs 1. Detecting cycles? → Use Slow and Fast Pointers (Floyd’s Algorithm) 2. Reversals / partial changes? → Use pointer juggling: prev, curr, next 3. Intersection or middle node? → Use Two Pointers ◄ Dynamic Programming Use-Cases 1. Optimal choices / Overlapping subproblems? → Use DP with Memoization (Top Down) or Tabulation (Bottom Up) 2. Subset or knapsack problems? → Use 1D/2D DP Arrays 3. String matching or edits? → Use DP Matrix (e.g., Edit Distance, LCS) Continued in first comment ↓
Solving 3663 problems doesn’t make sense: Focusing on the most common patterns and developing your own logic around them does. Work smarter > work harder. Thanks Parikh!
This is such a comprehensive and practical summary! The way you've mapped problem types to specific techniques makes it easier to build the right intuition. Thanks for generously sharing this with the community — much appreciated!
Continued ↓ ◄ Range Queries / Updates 1. Many sum queries, no updates? → Use Prefix Sums 2. Many sum queries + updates? → Use Segment Tree or Fenwick Tree (Binary Indexed Tree) ◄ Bit Manipulation 1. Set-based subsets or XOR logic? → Use Bit Masks or XOR 2. Need to check even/odd, set/unset bits? → Use `&`, `|`, `^`, `>>`, `<<` operators ◄ When Recursion is Banned or Stack Overflow Risk → Convert to Iterative using Stack ◄ Top K / Least K Elements → Use Heap → For exact K-th value, use Quick Select ◄ Special Techniques Sliding Window → For subarray with fixed or dynamic size Monotonic Stack → Next Greater / Smaller Element Greedy → Only when local optimum leads to global optimum Trie → For prefix-based string problems