12 DSA Patterns That Solve Most Coding Interview Problems
There are thousands of coding problems online, and nobody can solve them all before an interview. The good news is that most interview questions are variations of a small number of patterns. Once you recognise the pattern, the problem becomes much more familiar.
Quick answer: The DSA patterns that cover most coding interview questions are hashing, two pointers, sliding window, prefix sums, binary search, stacks, heaps, linked list techniques, tree traversal (BFS and DFS), graph traversal, backtracking and dynamic programming. Learn to spot the signal for each one and practise five to ten problems per pattern.
1. Hashing (hash maps and sets)
Signal: you need to check if something has been seen before, count occurrences, or find pairs quickly.
Classic problems: two sum, first non-repeating character, group anagrams, longest consecutive sequence.
Idea: trade memory for speed. Store what you've seen so lookups are constant time on average.
2. Two pointers
Signal: a sorted array or string, and you need pairs, triplets, or to compare from both ends.
Classic problems: pair with target sum in a sorted array, three sum, container with most water, valid palindrome, removing duplicates in place.
Idea: one pointer at each end, or a slow and fast pointer, moving based on a condition.
3. Sliding window
Signal: "longest", "shortest" or "maximum" for a contiguous subarray or substring.
Classic problems: longest substring without repeating characters, maximum sum subarray of size k, minimum window substring.
Idea: expand the right edge, shrink the left edge when a condition breaks, and track the best window.
4. Prefix sums
Signal: many queries about the sum of a range, or subarrays that sum to a value.
Classic problems: range sum query, subarray sum equals k, product of array except self.
Idea: precompute running totals so any range sum is one subtraction.
5. Binary search
Signal: sorted data, or a question like "find the minimum value that works" where the answer space is ordered.
Classic problems: search in rotated sorted array, first and last position of an element, koko eating bananas, minimum capacity to ship packages.
Idea: cut the search space in half each step. Binary search on the answer is the version people miss most often.
6. Stack
Signal: matching pairs, "next greater" or "previous smaller" element, or undo-like behaviour.
Classic problems: valid parentheses, next greater element, daily temperatures, largest rectangle in histogram.
Idea: keep items waiting for their match. A monotonic stack keeps elements in sorted order as you push and pop.
7. Heap (priority queue)
Signal: "top k", "kth largest", or repeatedly needing the smallest or largest item.
Classic problems: kth largest element, top k frequent elements, merge k sorted lists, find median from a data stream.
Idea: a heap gives you the min or max in constant time and inserts in log time.
8. Linked list techniques
Signal: any linked list problem.
Classic problems: reverse a linked list, detect a cycle, find the middle node, merge two sorted lists.
Idea: a dummy head node, slow and fast pointers, and careful pointer rewiring. Draw it out.
9. Tree traversal (DFS and BFS)
Signal: binary trees and binary search trees.
Classic problems: maximum depth, level order traversal, validate a BST, lowest common ancestor, path sum.
Idea: DFS with recursion for most problems. BFS with a queue when you need levels or the shortest path.
10. Graph traversal
Signal: grids, networks, dependencies, "number of islands", or "can you reach X".
Classic problems: number of islands, course schedule (topological sort), clone graph, rotting oranges, shortest path in a grid.
Idea: turn the problem into nodes and edges, then use BFS or DFS with a visited set.
11. Backtracking
Signal: "all combinations", "all permutations", "all ways", or puzzles like N-Queens and Sudoku.
Classic problems: subsets, permutations, combination sum, word search, N-Queens.
Idea: make a choice, recurse, undo the choice. Prune early when a path can't work.
12. Dynamic programming
Signal: "number of ways", "minimum cost", "maximum profit", and the problem breaks into overlapping subproblems.
Classic problems: climbing stairs, house robber, coin change, longest common subsequence, 0/1 knapsack, edit distance.
Idea: define what the state means, write the recurrence, then memoise or build a table. Start with the recursive solution and cache it before trying bottom-up.
A practice order that saves time
- Hashing, two pointers, sliding window, prefix sums
- Binary search, stack
- Linked lists, trees
- Heaps, graphs
- Backtracking, dynamic programming
Do five to ten problems per pattern before moving on. When you solve a problem, write one line on which pattern it was and what the signal was. That note is what builds recognition.
Explaining your pattern in the interview
Naming the pattern out loud ("this looks like a sliding window because we want the longest contiguous substring") shows structured thinking. Our guide on thinking out loud in a coding interview covers how to walk the interviewer through it.
If you blank on which pattern applies during a live round, SilentlyAI can show a suggested approach on your screen when you ask for it, so you can get moving again.
Frequently asked questions
How many DSA problems should I solve before interviews?
Quality matters more than count. Around 150 to 250 problems spread across the main patterns, with notes on each, is a solid base for most interviews.
Which DSA topics are most important for interviews?
Arrays with hashing, two pointers and sliding window come up most often, followed by trees, graphs and dynamic programming.
Is dynamic programming asked in every interview?
No. It's common at product companies, especially for experienced roles, but many interviews focus on arrays, strings, trees and hashing.
Which language is best for coding interviews?
The one you know best. Python, Java and C++ are all widely accepted.



