Stop watching 500 videos. Learn the patterns.
Every coding interview problem stems from fundamental algorithmic patterns. Master the core intuition, walkthrough, and C++ template for each category.
Roadmap Topics
(12 of 12)Arrays and Strings
Learn in-place updates and prefix sums first; nearly every later topic builds on them. Start with a quick read on Big-O (the idea only), then begin.
Hashing
Hashing turns a nested-loop O(n^2) search into one O(n) pass by remembering what you have seen. In C++ that means unordered_map and unordered_set.
Two Pointers and Sliding Window
Both patterns replace a nested loop with two indices that only move forward, giving O(n). Two pointers needs sorted or symmetric structure; a sliding window needs a contiguous range.
Stack and Queue
Use a stack when the most recent unfinished thing matters, and a queue when order of arrival matters. The monotonic stack is the pattern that shows up most often. In C++: stack, queue, deque.
Linked List
Linked list problems are about careful pointer handling, and four tools cover most of them: a dummy node, fast and slow pointers, in-place reversal, and merging. Draw the pointers on paper before coding.
Binary Search
Binary search works on any yes/no condition that flips once across an ordered range, not just on sorted arrays. Decide what lo and hi mean before you write code. In C++, know lower_bound and upper_bound, and compute mid as lo + (hi - lo) / 2.
Recursion and Backtracking
Backtracking is recursion that builds a candidate one choice at a time, undoes the choice, and tries the next. Every problem fits one template: choose, recurse, un-choose. Draw the decision tree for a tiny input before coding.
Trees and BST
A tree problem is almost always one recursive function; decide what each node returns to its parent and what it reports on the side. Do the easy depth and traversal problems until recursion feels natural, then move to BST rules and path problems.
Heap and Priority Queue
Reach for a heap whenever you repeatedly need the smallest or largest item from a changing collection. In C++, priority_queue<int> is a max-heap by default; use greater<int> for a min-heap, or a custom comparator for pairs and structs.
Greedy and Intervals
A greedy solution makes the locally best choice at each step and never revisits it; most interval problems become greedy once you sort. The skill is justifying the choice, so for each problem ask why the local pick cannot hurt the final answer.
Graphs
Most graph problems reduce to a handful of traversals; the real work is spotting the graph, such as a grid, a course list or a set of equations. In C++, store the graph as vector<vector<int>> adjacency lists and keep a visited array.
Dynamic Programming
DP is recursion that remembers its answers; do not try to see the table first. For every problem work in four steps: define the state in words, write the recursion, add memoization, then convert to a table and shrink the space if possible.
