Top DSA Questions —
The problems that show up again and again.
A curated study guide, not a random list — every problem here is grouped by pattern, because interviewers reuse patterns far more than they reuse exact problems. Learn the pattern once and a dozen "new" questions stop feeling new. Every entry links to a full LearnBug walkthrough where one exists.
Why patterns, not problems?
Interviewers rarely invent a brand-new type of problem — they draw from a known pool of patterns (two pointers, sliding window, BFS/DFS, DP) and change the surface details. Once you recognize "this is a sliding window problem" or "this is a graph traversal in disguise," the actual coding becomes the easy part.
Why visualization helps
Reading a solution and understanding why it works are different skills — you can follow an explanation and still freeze when asked to derive it live. Every problem below links to a LearnBug page where you can run the actual code and watch the state change step by step, which is what makes the pattern stick under interview pressure.
Most interview problems reduce to one of these
Hash map / array patterns
Two Sum, duplicate detection, frequency counting — trade extra space for O(1) lookups instead of nested loops.
Binary search on a sorted range
Not just "search a sorted array" — also applies to search-the-answer problems where the answer space itself is monotonic.
Tree/graph traversal
BFS for shortest-path/level problems, DFS for exhaustive exploration, cycle detection, and connected components.
The 12 problems, grouped by pattern
Two Sum — hash map pattern
Given an array and a target, find two numbers that add up to it. Brute force is O(n²); a hash map of value→index gets it to O(n) in one pass — check if the complement exists before adding the current number. Full walkthrough →
Contains Duplicate — hash set pattern
Determine if any value appears more than once. A hash set gives O(n) time, O(n) space: walk the array once, and if a value is already in the set, return true immediately. The brute-force nested-loop version is O(n²) and rarely accepted in an interview once the hash set approach is known.
Binary Search — the classic O(log n) search
Find a target in a sorted array by repeatedly halving the search range. The interview trap is almost always in the boundary conditions — off-by-one errors in left/right updates are the most common mistake candidates make live. Full walkthrough →
BFS / DFS Traversal — the graph foundation
Almost every graph problem builds on one of these two. BFS (queue) finds shortest paths in unweighted graphs; DFS (stack/recursion) explores exhaustively and underlies cycle detection and topological sort. Know both cold before attempting graph problems. BFS walkthrough → / DFS walkthrough →
Number of Islands — grid BFS/DFS
Count connected groups of land cells in a grid. The insight: a grid is just a graph where each cell connects to up to 4 neighbors — scan every cell, flood-fill from each unvisited land cell, and count how many flood fills you needed. Full walkthrough →
Detect Cycle in a Graph — 3-color DFS
A back edge to a node currently "in progress" (grey, not yet fully explored) reveals a cycle. This exact pattern also underlies deadlock detection and course-prerequisite validation. Full walkthrough →
Topological Sort — ordering a DAG
Order tasks so every prerequisite comes before what depends on it. Kahn's algorithm (BFS with in-degree counting) is the most common interview-friendly approach, and it doubles as a cycle detector — if the final order is shorter than the total node count, a cycle exists. Full walkthrough →
Merge Sort / Quick Sort — sorting from scratch
Interviewers sometimes ask you to implement a sort from memory to check you understand divide-and-conquer. Merge sort is always O(n log n) but needs O(n) space; quick sort is usually faster in practice but can degrade to O(n²) with a bad pivot. Merge sort → / Quick sort →
Climbing Stairs — the DP "hello world"
Count the ways to reach step n taking 1 or 2 steps at a time. It's almost always the first DP problem asked, because the recurrence (dp[i] = dp[i-1] + dp[i-2]) is simple enough to derive live but still tests whether you can recognize overlapping subproblems. Full walkthrough →
Coin Change — unbounded knapsack—style DP
Find the minimum coins to make a target amount. The trap: a greedy "biggest coin first" approach fails on some coin sets — this problem specifically tests whether you reach for DP instead of greedy when greedy isn't provably optimal. Full walkthrough →
0/1 Knapsack — the 2D DP table
Maximize value within a weight limit, each item usable at most once. This is the problem that introduces 2D DP tables to most candidates — rows for items considered, columns for remaining capacity, each cell choosing between "include" and "skip." Full walkthrough →
Backtracking (Permutations/Subsets) — the exploration pattern
Generate all permutations, subsets, or valid combinations by choosing, recursing, and explicitly undoing each choice before trying the next. This same choose/explore/un-choose shape solves N-Queens, Sudoku, and combination-sum style problems. Full walkthrough →
Pattern → Complexity Cheat Sheet
Start with the most common one — Two Sum
Paste it into LearnBug and watch the hash map build and the lookup fire.