Algorithms Eleven classic programming puzzles that teach you to think about a solution before you write it: why it works, and what it costs in time and memory. Every piece of code here was actually run, and every output under it is real.
Lessons 0 Overview Five projects you completed, explained from scratch: why the solution is the solution, not just how to type it. Every piece of code here was actually run, and every output below is real. 1 Pascal's Triangle How to build a list of lists one row at a time, why every number is the sum of the two above it, and where the off-by-one mistakes at the edges come from. 2 Lockboxes A puzzle that looks like keys and boxes and is really your first graph search: starting from box zero, what can you reach? 3 Minimum Operations The "copy all and paste" puzzle, which after two lines of thought turns into factoring a number into its primes. 4 Log Parsing Your first time reading an endless stream instead of a file: line by line, skipping the broken ones, printing statistics every ten lines and on interrupt. 5 UTF-8 Validation Your first serious meeting with bits: how UTF-8 encodes a character in one to four bytes, and how a small state machine validates it. 6 N Queens Your first real backtracking: build a solution step by step and back out the moment it becomes impossible, instead of trying every arrangement and waiting forever. 7 Rotating a 2D matrix A classic interview problem: rotate an n×n grid by ninety degrees. We derive the rule from coordinates and see the elegant trick: swap rows with columns, then reverse each row. 8 Making change and dynamic programming How many coins do you need to make an amount? Why the greedy answer sometimes fails, and how dynamic programming builds the answer from smaller amounts, solving the "number of ways" problem step by step. 9 Sequential API requests in order Fetching a list of links from a public API, then requesting each one while keeping the order. Promises and async/await in Node, why the order gets scrambled, and three correct ways to fix it. 10 Islands in a grid: neighbours and edges A grid of 0 (water) and 1 (land): how to walk the cells and check the four neighbours, count islands with depth-first search, compute the area, then an exercise on the perimeter using the edge rule. 11 Prime numbers and a removal game The Sieve of Eratosthenes to find every prime up to n quickly, prefix sums to count them in any range instantly, then how to analyse a two-player game taking turns to remove primes and their multiples. 12 Wrap-up and resources The best outside resources for these lessons, classified by kind and level. All are open to everyone and need no account on any platform. Use the filters to narrow the list.