DSA
Learn patterns, not hundreds of problems. Once you can spot the pattern, most questions stop feeling new.
Every problem goes from a simple solution to the best one, with the reason for each step. You can write and test your code right in the page.
How to use this roadmap
Section titled “How to use this roadmap”- Topics are in teaching order. “Builds on” links show what to know first, even from other tracks.
- New? Start at the top. Know some already? Jump to a level, or skip any topic you can already explain.
- Short on time? Tick “Asked often only” to see what interviews ask most.
- Your progress is saved in this browser.
Best after: Python. Do Python foundations first. Every answer here is written in Python.
30 topics in 4 levels, about 16 h of reading. With practice, plan 2 to 3 times that. 9 of 30 topics have lessons so far.
34 practice problems from this track’s lessons, in one list.
Foundations
Know this level already? Check what you know: 9 questions, about 5 minutes. Topics you get right are marked Known.
- 1. Big-O for time and spaceAsked oftenNot started
Say how work grows as the input grows, so you can compare solutions.
Watch it run: Counting the work
Start30 min read, about 1 h 15 min with practiceBuilds on: Your first functions: def and return (Python)
- 2. Arrays and stringsAsked oftenNot started
Index, slice and loop over lists and text, and what each step costs.
Watch it run: Reversing a list
Start25 min read, about 1 h 15 min with practiceBuilds on: Big-O for time and space · list, tuple, dict and set, and what each operation costs (Python)
- 3. Hashing and hash mapsAsked oftenNot started
Find anything in about one step with a dict, the most useful tool in interviews.
Watch it run: Hash map lookup · Anagram check
Start50 min read, about 3 h with practiceBuilds on: Arrays and strings
- 4. RecursionAsked oftenNot started
A function that solves a problem by calling itself on a smaller piece.
Watch it run: Merge sort · Call trees
Start25 min read, about 1 h 15 min with practiceBuilds on: Your first functions: def and return (Python)
- 5. Basic sortingNot started
How sorting works, and when sorting first makes a problem easy.
Watch it run: Selection sort · Insertion sort · Merge sort
Start25 min read, about 1 h 15 min with practiceBuilds on: Big-O for time and space
- 6. Stacks and queuesAsked oftenNot started
Last in, first out and first in, first out, with Python lists and deque.
Watch it run: Breadth-first search · Bracket check · Rate limiter
Start50 min read, about 3 h with practiceBuilds on: list, tuple, dict and set, and what each operation costs (Python)
Core
- 1. Two pointersAsked oftenNot started
Walk from both ends to find pairs without a nested loop.
Watch it run: Two pointers · Most water
Start25 min read, about 1 h 30 min with practiceBuilds on: Arrays and strings
- 2. Sliding windowAsked oftenNot started
Slide a window along a list to check every stretch in one pass.
Watch it run: Sliding window · No repeats
Start25 min read, about 1 h 30 min with practiceBuilds on: Two pointers
- 3. Prefix sumsComing soon
Keep running totals so any range sum takes one step.
20 min readBuilds on: Arrays and strings
- 4. Binary search on an index and on the answerAsked oftenNot started
Halve the search space each step, on sorted data or on the answer itself.
Watch it run: Binary search · A turned list
Start30 min read, about 1 h 30 min with practiceBuilds on: Basic sorting
- 5. Fast and slow pointersComing soon
One pointer moves twice as fast as the other, to find loops and middles.
15 min readBuilds on: Two pointers
- 6. Linked-list techniquesComing soon
Reverse, merge and reorder chains of nodes by moving pointers.
25 min readBuilds on: Classes: inheritance, MRO, super() and dunder methods (Python)
- 7. Monotonic stack and queueComing soon
Keep a stack in sorted order to find the next bigger item fast.
25 min readBuilds on: Stacks and queues
- 8. IntervalsComing soon
Merge, insert and compare time ranges, usually after sorting.
20 min readBuilds on: Basic sorting
- 9. Heaps: top-k, k-way merge, two heapsAsked oftenComing soon
Always take the smallest or largest item fast, for top-k and merging.
25 min read
- 10. Trees: traversals, BST operations, LCAAsked oftenComing soon
Visit every node of a tree, search a sorted tree and find common ancestors.
45 min readBuilds on: Recursion · Classes: inheritance, MRO, super() and dunder methods (Python)
- 11. TriesComing soon
A tree of letters for fast prefix search, like autocomplete.
20 min readBuilds on: Trees: traversals, BST operations, LCA
- 12. Graphs: BFS, DFS, topological sort, union-find, Dijkstra, cyclesAsked oftenComing soon
Explore connected things, find shortest paths and order tasks that depend on each other.
Watch it run: Breadth-first search
60 min readBuilds on: Stacks and queues · Recursion
- 13. BacktrackingAsked oftenComing soon
Try a choice, go deeper, undo it and try the next, to list every option.
40 min readBuilds on: Recursion
- 14. GreedyComing soon
Take the best-looking step each time, and how to tell when that is safe.
20 min readBuilds on: Basic sorting
Advanced
- 1. Dynamic programming: recursion to memoization to tabulation to space-optimizedAsked oftenComing soon
Save answers to smaller problems so you never solve the same one twice.
60 min readBuilds on: Recursion
- 2. DP families: 1D, grid, knapsack, LIS, LCS, edit distance, interval, tree, bitmaskComing soon
The common dynamic programming shapes, so new problems look familiar.
60 min readBuilds on: Dynamic programming: recursion to memoization to tabulation to space-optimized
- 3. Bit manipulationComing soon
Tricks with 0s and 1s, like spotting the one number without a pair.
20 min readBuilds on: Big-O for time and space
- 4. Segment and Fenwick treesComing soon
Answer range questions fast while the values keep changing.
30 min readBuilds on: Prefix sums · Trees: traversals, BST operations, LCA
- 5. MST, Bellman-Ford and Floyd-WarshallComing soon
Cheapest networks, and shortest paths when some costs are negative.
30 min readBuilds on: Graphs: BFS, DFS, topological sort, union-find, Dijkstra, cycles
- 6. String matching: KMP and Rabin-KarpComing soon
Find a word in a long text without re-checking every position.
25 min readBuilds on: Hashing and hash maps
- 7. Designing data structures: LRU and LFU caches, min stack, randomized setAsked oftenComing soon
Build an LRU cache and other custom structures from dicts and lists.
30 min readBuilds on: Hashing and hash maps · Linked-list techniques · Classes: inheritance, MRO, super() and dunder methods (Python)
Interview-ready
- 1. Which pattern is this? Recognition guide and trainerComing soon
Read a problem and pick the right pattern from its clues.
30 min read
- 2. Timed mixed setsComing soon
Mixed problems against the clock, like the real round.
45 min readBuilds on: The coding-round method: clarify, examples, brute force, optimize, code, test, analyze (Interview Playbook) · Which pattern is this? Recognition guide and trainer
- 3. Think-aloud drillsComing soon
Practise explaining your thinking while you code.
20 min readBuilds on: The coding-round method: clarify, examples, brute force, optimize, code, test, analyze (Interview Playbook)