DSA Factory

Free DSA lessons

Each lesson teaches one idea, shows it with a visual, then gives you one problem built for it. Read any of them here, or solve the problem in your browser. No sign-up needed.

Programming basics

Full path
  1. A name for a valueStage 0 · Names for values7 min
  2. Changing a valueStage 0 · Names for values7 min
  3. Swapping two valuesStage 0 · Names for values8 min
  4. True or false valuesStage 0 · Names for values7 min
  5. Dividing and what's leftStage 1 · Numbers8 min
  6. Which part first?Stage 1 · Numbers7 min
  7. Peeling off digitsStage 1 · Numbers8 min
  8. Numbers have limitsStage 1 · Numbers8 min
  9. Two ways to goStage 2 · Making decisions8 min
  10. More than two casesStage 2 · Making decisions8 min
  11. And, or, notStage 2 · Making decisions9 min
  12. Decisions inside decisionsStage 2 · Making decisions9 min
  13. Doing it again and againStage 3 · Loops that count9 min
  14. Using the counterStage 3 · Loops that count8 min
  15. Counting the ones that countStage 3 · Loops that count9 min
  16. Jumps and countdownsStage 3 · Loops that count8 min
  17. Repeat untilStage 4 · Loops that wait8 min
  18. Stopping earlyStage 4 · Loops that wait9 min
  19. When you can't predict the lengthStage 4 · Loops that wait9 min
  20. Taking a number apartStage 4 · Loops that wait9 min
  21. A function you write yourselfStage 5 · Functions9 min
  22. Answering earlyStage 5 · Functions8 min
  23. Breaking a job into small jobsStage 5 · Functions10 min
  24. Names stay insideStage 5 · Functions9 min
  25. Letters by positionStage 6 · Text9 min
  26. Visiting every letterStage 6 · Text8 min
  27. Building new textStage 6 · Text9 min
  28. Comparing neighboursStage 6 · Text9 min
  29. A row of boxesStage 7 · Lists9 min
  30. Visiting every itemStage 7 · Lists8 min
  31. Looking for one itemStage 7 · Lists9 min
  32. Making a new listStage 7 · Lists9 min
  33. A loop inside a loopStage 8 · Loops inside loops10 min
  34. Rows, then columnsStage 8 · Loops inside loops9 min
  35. A grid of numbersStage 8 · Loops inside loops10 min
  36. Walking the gridStage 8 · Loops inside loops10 min
  37. Fizz and buzzStage 9 · Mastery12 min
  38. The runner-upStage 9 · Mastery12 min
  39. A row of Pascal's triangleStage 9 · Mastery12 min
  40. Roman numeralsStage 9 · Mastery14 min

Arrays

Full path
  1. Positions start at 0Stage 0 · What an array is4 min
  2. The length tells you where things areStage 0 · What an array is5 min
  3. Changing a value in placeStage 0 · What an array is6 min
  4. A loop visits every boxStage 1 · Traversal6 min
  5. Count what matchesStage 1 · Traversal6 min
  6. Stop when you find itStage 1 · Traversal7 min
  7. Walk backwardsStage 1 · Traversal7 min
  8. Remember the best so farStage 2 · Traversal with state7 min
  9. Two things at onceStage 2 · Traversal with state6 min
  10. Carry a total forwardStage 2 · Traversal with state7 min
  11. Compare with the previous boxStage 2 · Traversal with state9 min

Complexity

Full path
  1. One loop, countedStage 0 · Counting work7 min
  2. Loops inside loopsStage 0 · Counting work8 min
  3. Halving is fastStage 0 · Counting work6 min
  4. Will it be fast enough?Stage 0 · Counting work8 min

Math and bits

Full path
  1. Peel off the last digitStage 0 · Digits and divisibility6 min
  2. Build a number digit by digitStage 0 · Digits and divisibility7 min
  3. Divisors come in pairsStage 0 · Digits and divisibility9 min
  4. Euclid's shortcutStage 0 · Digits and divisibility8 min

Strings

Full path
  1. A string is a row of charactersStage 0 · Walking a string6 min
  2. Building a new stringStage 0 · Walking a string7 min
  3. Compare from both endsStage 0 · Walking a string7 min
  4. Letters are numbersStage 0 · Walking a string9 min

Hashing

Full path
  1. A set remembersStage 0 · Seen before?7 min
  2. A map countsStage 0 · Seen before?8 min
  3. Count as you goStage 0 · Seen before?8 min
  4. Look up the partnerStage 0 · Seen before?9 min

Sorting

Full path
  1. Position is rankStage 0 · Sort it first7 min
  2. Neighbours after sortingStage 0 · Sort it first8 min
  3. Choose what to sort byStage 0 · Sort it first10 min
  4. Sort, then two pointersStage 0 · Sort it first10 min

Recursion

Full path
  1. Sum of digitsStage 0 · A function that calls itself8 min
  2. Reverse a stringStage 0 · A function that calls itself9 min
  3. Same both waysStage 0 · A function that calls itself10 min
  4. Power in a few stepsStage 0 · A function that calls itself12 min

Linked lists

Full path
  1. Count the nodesStage 0 · Walking nodes8 min
  2. Find first occurrenceStage 0 · Walking nodes8 min
  3. Value at indexStage 0 · Walking nodes8 min
  4. Check if sortedStage 0 · Walking nodes9 min

Stacks and queues

Full path
  1. An undo buttonStage 0 · Last in, first out8 min
  2. Typing with backspaceStage 0 · Last in, first out8 min
  3. Brackets that matchStage 0 · Last in, first out10 min
  4. A queue: first in, first outStage 0 · Last in, first out10 min
  1. Count the nodesStage 0 · Nodes and depth8 min
  2. Maximum depthStage 0 · Nodes and depth8 min
  3. Search a binary treeStage 0 · Nodes and depth8 min
  4. Same treeStage 0 · Nodes and depth9 min

Binary search trees

Full path
  1. Search a BSTStage 0 · Search and insert8 min
  2. Minimum value in BSTStage 0 · Search and insert7 min
  3. Insert into a BSTStage 0 · Search and insert8 min
  4. Closest value in BSTStage 0 · Search and insert9 min
  1. Extract smallest elementsStage 0 · Smallest first8 min
  2. Connect ropesStage 0 · Smallest first8 min
  3. Last stone weightStage 0 · Smallest first8 min
  4. Reduce largest pilesStage 0 · Smallest first8 min

Backtracking

Full path
  1. Generate binary stringsStage 0 · Build, check, undo8 min
  2. Generate all subsetsStage 0 · Build, check, undo9 min
  3. Generate valid parenthesesStage 0 · Build, check, undo9 min
  4. Root-to-leaf path sumStage 0 · Build, check, undo8 min

Greedy

Full path
  1. Making changeStage 0 · Take the best now7 min
  2. Assign cookiesStage 0 · Take the best now8 min
  3. Change at the chai stallStage 0 · Take the best now8 min
  4. Maximum units on truckStage 0 · Take the best now8 min

Intervals

Full path
  1. Do they overlap?Stage 0 · Overlap and merge7 min
  2. Merge twoStage 0 · Overlap and merge8 min
  3. Merge a whole listStage 0 · Overlap and merge12 min
  4. Insert into a sorted listStage 0 · Overlap and merge12 min

Graphs

Full path
  1. Who is next to whomStage 0 · Edges and neighbours10 min
  2. Count the connectionsStage 0 · Edges and neighbours7 min
  3. Mutual friendsStage 0 · Edges and neighbours9 min
  4. Everyone follows themStage 0 · Edges and neighbours10 min

Dynamic programming

Full path
  1. Climbing stairsStage 0 · Remember answers11 min
  2. Tiling a 2×n boardStage 0 · Remember answers10 min
  3. Minimum cost to climbStage 0 · Remember answers10 min
  4. One, two or three steps at a timeStage 0 · Remember answers10 min
  1. Does this exact word exist?Stage 0 · Words as paths10 min
  2. Starts withStage 0 · Words as paths8 min
  3. How many words start with this?Stage 0 · Words as paths9 min
  4. The longest prefix that is a wordStage 0 · Words as paths9 min

Union-find

Full path
  1. Are they in the same group?Stage 0 · Groups that merge9 min
  2. Count the groupsStage 0 · Groups that merge7 min
  3. Largest groupStage 0 · Groups that merge8 min
  4. Spotting a redundant linkStage 0 · Groups that merge8 min
Start the full path freeSee the curriculum