The DSA Patterns That Cover Most Coding Interview Questions
Loading…
Loading…
Grinding hundreds of random problems is the slowest way to prepare for coding interviews. Strong candidates study patterns, not problems. A small set of recurring techniques accounts for the large majority of questions asked at FAANG-tier companies. Learn the pattern and you can solve every problem in its family.
Interview questions are remixes. "Find a pair summing to a target", "longest substring without repeating characters", and "minimum window substring" look unrelated but are all the same two-pointer/sliding-window idea applied differently. Once you recognise the pattern, the question becomes about edge cases and clean code rather than a fresh insight under stress.
Two indices moving through a sorted array or string. Use it for pair/triplet sums, palindrome checks, and partitioning. Signal: a sorted input and "find elements that satisfy a relationship."
A moving subarray/substring whose bounds expand and contract. Use it for "longest/shortest contiguous segment satisfying a constraint." Signal: contiguous subarray or substring with a min/max/condition.
Two pointers at different speeds. Use it for cycle detection in linked lists and finding a middle node. Signal: linked list cycles or "find the midpoint in one pass."
A hash map/set to trade space for time. Use it for frequency counts, deduplication, and "have I seen this before?" Signal: "count", "unique", or membership checks.
Halving a search space, and not only on sorted arrays. "Binary search on the answer" solves many optimisation problems ("minimum capacity such that…"). Signal: a monotonic search space.
Level-order traversal (BFS, a queue) vs. depth traversal (DFS, recursion/stack). Use BFS for shortest path in unweighted graphs and level problems. Use DFS for path sums, subtree properties, and backtracking.
Build candidates incrementally and abandon a path the moment it can't lead to a solution. Use it for permutations, combinations, subsets, and constraint problems like N-Queens.
A priority queue for "K largest/smallest" or streaming medians without sorting everything. Signal: "top K", "K closest", or a running order statistic.
Optimal substructure plus overlapping subproblems. Use it for counting paths, knapsack-style optimisation, and edit distance. Signal: "number of ways", "minimum/maximum cost", or a choice repeated over a sequence.
Traversal (BFS/DFS), topological sort for dependency ordering, and union-find for connectivity. Signal: explicit nodes/edges, or implicit ones (grid cells, course prerequisites).
Aim for recognition speed. In a 35-minute interview, spending 10 minutes identifying the approach leaves no time for clean implementation and edge cases.
You can recognise every pattern silently and still fail the interview, because the interview also scores how you communicate while coding: stating the approach before typing, talking through complexity, and handling the follow-up ("now do it in O(1) space"). That only improves by practising out loud with someone interrupting you, which is what a mock interview is for. See pricing for bundles.