DSA for AI/ML
The coding round still decides ML interviews. You don't need hundreds of problems: you need four structures, the patterns that repeat, where each one shows up in real ML systems, and the habit of thinking from first principles out loud.
The roadmap
Each stage builds on the last. Every module says what you'll be able to do and where it shows up in real ML systems.
Stage 1
The method you will use on every problem, and how to size a solution.
Stage 2
The two structures behind most interview problems.
Arrays and strings
Index, slice, accumulate and rearrange in place without extra passes.
In ML · Batching and slicing tensors, time-series windows, parsing raw text.
16 lessons
Hashing
Trade memory for constant-time lookups: count, group and remember what you have seen.
In ML · Tokenizer vocabularies, feature dictionaries, frequency counts, caches.
12 lessons
Stage 3
Order and contiguity: the shapes most solutions take.
Two pointers
Use order to cut a quadratic search down to one pass.
In ML · Merging sorted predictions, de-duplicating sorted IDs, sweeping sorted scores for AUC.
10 lessons
Sliding window
Answer questions about every contiguous range while touching each element twice at most.
In ML · Rolling loss and metric averages, n-grams, windowed time-series features.
10 lessons
Binary search
Halve the search space, on arrays and on the answer itself.
In ML · Thresholds, quantiles and the largest batch size that still fits in memory.
10 lessons
Stage 4
Remember the right past; explore choices.
Stacks and queues
Keep exactly the past you still need, including monotonic stacks and deques.
In ML · Parsing expressions and configs, rolling maxima over metric streams.
10 lessons
Linked lists and caches
Re-wire pointers safely and build caches with constant-time eviction.
In ML · Least-recently-used caches for embeddings, results and model weights.
8 lessons
Recursion and backtracking
Draw the recursion tree, then explore it and prune what cannot win.
In ML · Search over configurations, constraint solving, tree-shaped computations.
10 lessons
Stage 5
The best few, and data shaped like trees.
Heaps and top-k
Always know the best few items without sorting everything.
In ML · Top-k retrieval in recommenders, nearest neighbours, beam search decoding.
12 lessons
Trees and BSTs
Think recursively about subtrees and use ordering to search fast.
In ML · Decision trees and tree ensembles, hierarchical labels, index structures.
14 lessons
Stage 6
Graphs and dynamic programming.
Graphs
Traverse, order and connect: BFS, DFS, topological sort, shortest paths and union-find.
In ML · Autograd computation graphs, pipeline DAGs, user and item graphs.
16 lessons
Dynamic programming
Name the subproblem, write the recurrence, fill the table in the right order.
In ML · Edit distance for text similarity, Viterbi decoding, sequence alignment.
16 lessons
Stage 7
Prefix structures and greedy proofs.
Tries and strings
Share prefixes to search many strings at once.
In ML · Autocomplete, tokenizers and prefix-based lookups.
6 lessons
Greedy and intervals
Make the locally best choice, and prove why it stays globally best.
In ML · Scheduling jobs and GPUs, merging time ranges, packing requests.
6 lessons
Stage 8
From-scratch NumPy, judged like the real round.
Every problem, the same six steps
Clarify
What are the inputs, limits and edge cases?
Brute force
What is the simplest correct answer, and what does it cost?
Optimise
What work is repeated, and what can I remember instead?
Code
Can I write it cleanly in Python, one idea per line?
Test
Does it survive empty, tiny, duplicate and extreme inputs?
Complexity
What are time and space, and why?
All lessons, in order
Each module opens with a first-principles concept lesson, then climbs from easy to hard. Lessons marked ML are ML twins of a classic pattern. Lessons publish in this order, starting with module 00.
Run the six-step interview loop and size any solution before you write it.
In ML: Deciding if a feature pipeline, a retrieval step or a training loop will fit in time and memory.
Index, slice, accumulate and rearrange in place without extra passes.
In ML: Batching and slicing tensors, time-series windows, parsing raw text.
Trade memory for constant-time lookups: count, group and remember what you have seen.
In ML: Tokenizer vocabularies, feature dictionaries, frequency counts, caches.
Use order to cut a quadratic search down to one pass.
In ML: Merging sorted predictions, de-duplicating sorted IDs, sweeping sorted scores for AUC.
Answer questions about every contiguous range while touching each element twice at most.
In ML: Rolling loss and metric averages, n-grams, windowed time-series features.
Halve the search space, on arrays and on the answer itself.
In ML: Thresholds, quantiles and the largest batch size that still fits in memory.
Keep exactly the past you still need, including monotonic stacks and deques.
In ML: Parsing expressions and configs, rolling maxima over metric streams.
Re-wire pointers safely and build caches with constant-time eviction.
In ML: Least-recently-used caches for embeddings, results and model weights.
Draw the recursion tree, then explore it and prune what cannot win.
In ML: Search over configurations, constraint solving, tree-shaped computations.
Always know the best few items without sorting everything.
In ML: Top-k retrieval in recommenders, nearest neighbours, beam search decoding.
Think recursively about subtrees and use ordering to search fast.
In ML: Decision trees and tree ensembles, hierarchical labels, index structures.
Traverse, order and connect: BFS, DFS, topological sort, shortest paths and union-find.
In ML: Autograd computation graphs, pipeline DAGs, user and item graphs.
Name the subproblem, write the recurrence, fill the table in the right order.
In ML: Edit distance for text similarity, Viterbi decoding, sequence alignment.
Share prefixes to search many strings at once.
In ML: Autocomplete, tokenizers and prefix-based lookups.
Make the locally best choice, and prove why it stays globally best.
In ML: Scheduling jobs and GPUs, merging time ranges, packing requests.
Implement core ML algorithms from scratch in NumPy: vectorised, stable and tested.
In ML: The from-scratch round some ML interviews add after the algorithm round.
Modules 00–04 are free.
The rest of the roadmap is included with Pro, alongside the full curriculum.
See plans