VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled

DSA for AI/ML

Fewer problems. Deeper patterns.

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.

modules
16
modules
problems
154
problems
every solution
Python
every solution
modules free
0–4
modules free

The roadmap

Eight stages, one path

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.

Every problem, the same six steps

  1. 1

    Clarify

    What are the inputs, limits and edge cases?

  2. 2

    Brute force

    What is the simplest correct answer, and what does it cost?

  3. 3

    Optimise

    What work is repeated, and what can I remember instead?

  4. 4

    Code

    Can I write it cleanly in Python, one idea per line?

  5. 5

    Test

    Does it survive empty, tiny, duplicate and extreme inputs?

  6. 6

    Complexity

    What are time and space, and why?

All lessons, in order

174 lessons across 16 modules

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.

00

The method and Big-O

MethodFree

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.

  1. 0.1The six-step interview loopConcept
  2. 0.2Big-O from first principlesConcept
  3. 0.3What the constraints tell you about nConcept
  4. 0.4Space complexity: what you choose to rememberConcept
  5. 0.5Python costs you must know: list, dict, set, deque, heapqConcept
  6. 0.6Two Sum, the six steps out loudEasy
01

Arrays and strings

StructureFree

Index, slice, accumulate and rearrange in place without extra passes.

In ML: Batching and slicing tensors, time-series windows, parsing raw text.

  1. 1.1Arrays, slicing and the tensor mindsetConcept
  2. 1.2Prefix sums: answer range questions in O(1)Concept
  3. 1.3Two SumEasy
  4. 1.4Best Time to Buy and Sell StockEasy
  5. 1.5Move ZeroesEasy
  6. 1.6Majority ElementEasy
  7. 1.7Valid AnagramEasy
  8. 1.8Product of Array Except SelfMedium
  9. 1.9Maximum SubarrayMedium
  10. 1.10Rotate ArrayMedium
  11. 1.11Rotate MatrixMedium
  12. 1.12Spiral MatrixMedium
  13. 1.13Set Matrix ZeroesMedium
  14. 1.14Sort ColorsMedium
  15. 1.15Next PermutationMedium
  16. 1.16Normalise a batch of feature vectorsMLEasy
02

Hashing

StructureFree

Trade memory for constant-time lookups: count, group and remember what you have seen.

In ML: Tokenizer vocabularies, feature dictionaries, frequency counts, caches.

  1. 2.1Hash maps and sets from first principlesConcept
  2. 2.2Contains DuplicateEasy
  3. 2.3Isomorphic StringsEasy
  4. 2.4Word PatternEasy
  5. 2.5Group AnagramsMedium
  6. 2.6Valid SudokuMedium
  7. 2.7Longest Consecutive SequenceMediumSoon
  8. 2.8Subarray Sum Equals KMediumSoon
  9. 2.9Longest Subarray with Sum KMediumSoon
  10. 2.10Encode and Decode StringsMediumSoon
  11. 2.11Build a tokenizer vocabulary with countsMLEasySoon
  12. 2.12Find the most frequent adjacent token pairMLMediumSoon
03

Two pointers

PatternFree

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.

  1. 3.1Two pointers: why sorted order is a superpowerConceptSoon
  2. 3.2Valid PalindromeEasySoon
  3. 3.3Remove Duplicates from Sorted ArrayEasySoon
  4. 3.4Merge Sorted ArrayEasySoon
  5. 3.5Two Sum II (sorted input)MediumSoon
  6. 3.63SumMediumSoon
  7. 3.7Container With Most WaterMediumSoon
  8. 3.8Trapping Rain WaterHardSoon
  9. 3.9Merge two sorted prediction listsMLEasySoon
  10. 3.10Compute AUC by sweeping sorted scoresMLMediumSoon
04

Sliding window

PatternFree

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.

  1. 4.1Fixed and variable windowsConceptSoon
  2. 4.2Maximum Sum Subarray of Size KEasySoon
  3. 4.3Longest Substring Without Repeating CharactersMediumSoon
  4. 4.4Longest Repeating Character ReplacementMediumSoon
  5. 4.5Permutation in StringMediumSoon
  6. 4.6Max Consecutive Ones IIIMediumSoon
  7. 4.7Fruit Into BasketsMediumSoon
  8. 4.8Minimum Window SubstringHardSoon
  9. 4.9Rolling mean of training lossMLEasySoon
  10. 4.10Count n-grams in a token streamMLMediumSoon
05

Binary search

Pattern Pro

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.

  1. 5.1Binary search, and searching on the answerConceptSoon
  2. 5.2Binary SearchEasySoon
  3. 5.3Search Insert PositionEasySoon
  4. 5.4First and Last Position of an ElementMediumSoon
  5. 5.5Search in Rotated Sorted ArrayMediumSoon
  6. 5.6Find Minimum in Rotated Sorted ArrayMediumSoon
  7. 5.7Find Peak ElementMediumSoon
  8. 5.8Koko Eating BananasMediumSoon
  9. 5.9Median of Two Sorted ArraysHardSoon
  10. 5.10Largest batch size that fits in memoryMLMediumSoon
06

Stacks and queues

Structure Pro

Keep exactly the past you still need, including monotonic stacks and deques.

In ML: Parsing expressions and configs, rolling maxima over metric streams.

  1. 6.1Stacks, queues and monotonic structuresConceptSoon
  2. 6.2Valid ParenthesesEasySoon
  3. 6.3Implement Queue using StacksEasySoon
  4. 6.4Next Greater ElementEasySoon
  5. 6.5Min StackMediumSoon
  6. 6.6Evaluate Reverse Polish NotationMediumSoon
  7. 6.7Daily TemperaturesMediumSoon
  8. 6.8Largest Rectangle in HistogramHardSoon
  9. 6.9Sliding Window MaximumHardSoon
  10. 6.10Rolling maximum of GPU memory useMLMediumSoon
07

Linked lists and caches

Structure Pro

Re-wire pointers safely and build caches with constant-time eviction.

In ML: Least-recently-used caches for embeddings, results and model weights.

  1. 7.1Nodes, pointers and the dummy-head trickConceptSoon
  2. 7.2Reverse Linked ListEasySoon
  3. 7.3Middle of the Linked ListEasySoon
  4. 7.4Linked List CycleEasySoon
  5. 7.5Merge Two Sorted ListsEasySoon
  6. 7.6Remove Nth Node From End of ListMediumSoon
  7. 7.7LRU CacheMediumSoon
  8. 7.8Cache recent embeddings with evictionMLMediumSoon
08

Recursion and backtracking

Pattern Pro

Draw the recursion tree, then explore it and prune what cannot win.

In ML: Search over configurations, constraint solving, tree-shaped computations.

  1. 8.1Recursion trees and backtrackingConceptSoon
  2. 8.2Pow(x, n)MediumSoon
  3. 8.3SubsetsMediumSoon
  4. 8.4Subsets IIMediumSoon
  5. 8.5Combination SumMediumSoon
  6. 8.6PermutationsMediumSoon
  7. 8.7Generate ParenthesesMediumSoon
  8. 8.8Word SearchMediumSoon
  9. 8.9N-QueensHardSoon
  10. 8.10Enumerate a hyperparameter grid with pruningMLMediumSoon
09

Heaps and top-k

Structure Pro

Always know the best few items without sorting everything.

In ML: Top-k retrieval in recommenders, nearest neighbours, beam search decoding.

  1. 9.1Heaps from first principlesConceptSoon
  2. 9.2Last Stone WeightEasySoon
  3. 9.3Kth Largest Element in an ArrayMediumSoon
  4. 9.4K Closest Points to OriginMediumSoon
  5. 9.5Top K Frequent ElementsMediumSoon
  6. 9.6Task SchedulerMediumSoon
  7. 9.7Merge K Sorted ListsHardSoon
  8. 9.8Find Median from Data StreamHardSoon
  9. 9.9Top-k tokens from a logits arrayMLEasySoon
  10. 9.10k nearest neighbours by distanceMLMediumSoon
  11. 9.11Merge k sorted posting listsMLMediumSoon
  12. 9.12Beam search with a heapMLHardSoon
10

Trees and BSTs

Structure Pro

Think recursively about subtrees and use ordering to search fast.

In ML: Decision trees and tree ensembles, hierarchical labels, index structures.

  1. 10.1Trees, traversals and recursive thinkingConceptSoon
  2. 10.2Maximum Depth of Binary TreeEasySoon
  3. 10.3Invert Binary TreeEasySoon
  4. 10.4Same TreeEasySoon
  5. 10.5Diameter of Binary TreeEasySoon
  6. 10.6Balanced Binary TreeEasySoon
  7. 10.7Binary Tree Level Order TraversalMediumSoon
  8. 10.8Lowest Common Ancestor of a Binary TreeMediumSoon
  9. 10.9Validate Binary Search TreeMediumSoon
  10. 10.10Kth Smallest Element in a BSTMediumSoon
  11. 10.11Construct Binary Tree from Preorder and InorderMediumSoon
  12. 10.12Binary Tree Maximum Path SumHardSoon
  13. 10.13Serialize and Deserialize Binary TreeHardSoon
  14. 10.14Predict with a decision treeMLEasySoon
11

Graphs

Structure Pro

Traverse, order and connect: BFS, DFS, topological sort, shortest paths and union-find.

In ML: Autograd computation graphs, pipeline DAGs, user and item graphs.

  1. 11.1Graphs, BFS and DFSConceptSoon
  2. 11.2Flood FillEasySoon
  3. 11.3Number of IslandsMediumSoon
  4. 11.4Clone GraphMediumSoon
  5. 11.5Rotting OrangesMediumSoon
  6. 11.6Course ScheduleMediumSoon
  7. 11.7Course Schedule IIMediumSoon
  8. 11.8Number of ProvincesMediumSoon
  9. 11.9Redundant ConnectionMediumSoon
  10. 11.10Network Delay TimeMediumSoon
  11. 11.11Cheapest Flights Within K StopsMediumSoon
  12. 11.12Word LadderHardSoon
  13. 11.13Alien DictionaryHardSoon
  14. 11.14Order the layers of a computation graphMLMediumSoon
  15. 11.15Group near-duplicate records with union-findMLMediumSoon
  16. 11.16Find connected users in an interaction graphMLMediumSoon
12

Dynamic programming

Pattern Pro

Name the subproblem, write the recurrence, fill the table in the right order.

In ML: Edit distance for text similarity, Viterbi decoding, sequence alignment.

  1. 12.1Dynamic programming from first principlesConceptSoon
  2. 12.2Climbing StairsEasySoon
  3. 12.3House RobberMediumSoon
  4. 12.4Coin ChangeMediumSoon
  5. 12.5Longest Increasing SubsequenceMediumSoon
  6. 12.6Partition Equal Subset SumMediumSoon
  7. 12.7Unique PathsMediumSoon
  8. 12.8Minimum Path SumMediumSoon
  9. 12.9Word BreakMediumSoon
  10. 12.10Decode WaysMediumSoon
  11. 12.11Longest Common SubsequenceMediumSoon
  12. 12.12Edit DistanceMediumSoon
  13. 12.13Longest Palindromic SubstringMediumSoon
  14. 12.14Best Time to Buy and Sell Stock with CooldownMediumSoon
  15. 12.15Fuzzy-match a label to a vocabularyMLMediumSoon
  16. 12.16Toy Viterbi decodingMLHardSoon
13

Tries and strings

Structure Pro

Share prefixes to search many strings at once.

In ML: Autocomplete, tokenizers and prefix-based lookups.

  1. 13.1Tries: share the beginning, save the workConceptSoon
  2. 13.2Implement TrieMediumSoon
  3. 13.3Design Add and Search WordsMediumSoon
  4. 13.4Word Search IIHardSoon
  5. 13.5Autocomplete from a prefixMLMediumSoon
  6. 13.6One step of byte-pair encodingMLMediumSoon
14

Greedy and intervals

Pattern Pro

Make the locally best choice, and prove why it stays globally best.

In ML: Scheduling jobs and GPUs, merging time ranges, packing requests.

  1. 14.1Greedy choices and how to prove themConceptSoon
  2. 14.2Merge IntervalsMediumSoon
  3. 14.3Insert IntervalMediumSoon
  4. 14.4Non-overlapping IntervalsMediumSoon
  5. 14.5Jump GameMediumSoon
  6. 14.6Meeting Rooms IIMediumSoon
15

The ML coding round

ML round Pro

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.

  1. 15.1k-nearest neighbours classifierMLEasySoon
  2. 15.2Cosine-similarity searchMLEasySoon
  3. 15.3Mini-batches with shuffling and paddingMLEasySoon
  4. 15.4k-means from scratchMLMediumSoon
  5. 15.5Logistic regression with gradient descentMLMediumSoon
  6. 15.6Softmax and cross-entropy, numerically stableMLMediumSoon
  7. 15.7Scaled dot-product attention with maskingMLMediumSoon
  8. 15.8AUC by sortingMLMediumSoon
  9. 15.9Top-k and top-p samplingMLMediumSoon
  10. 15.10Batch normalisation forward passMLMediumSoon
  11. 15.11Linear regression: closed form and gradient descentMLMediumSoon
  12. 15.12Byte-pair encoding mergesMLHardSoon

Modules 00–04 are free.

The rest of the roadmap is included with Pro, alongside the full curriculum.

See plans