Famous problems collected in one place, each with the idea that solves it and the note that treats it. Puzzles get full write-ups in 25. Puzzles; algorithms by name are in 🐬 Named Algorithms.

ProblemKey ideaNote
Egg dropping ( eggs, floors)DP on (eggs, moves): floors covered Classic DP
0/1, unbounded, bounded knapsackDP over capacity; monotone deque for boundedKnapsack
Coin change (count / minimum)unbounded knapsack; greedy fails in generalKnapsack
Longest increasing subsequencepatience sorting Sequence DP
Longest common subsequence, edit distanceDP, Hirschberg, bit-parallelSequence DP
Matrix chain, optimal BST, stone merginginterval DP, Knuth, Garsia–WachsInterval DP
Travelling salesman, Hamiltonian pathHeld–Karp bitmask DPHamiltonian Paths and TSP
Domino / tromino tilingsprofile DP, transfer matrixProfile DP
Counting numbers with digit constraintsdigit DPDigit DP
Maximum subarray, max circular subarrayKadaneClassic Array Problems
Trapping rain water, largest rectangle in histogramtwo pointers, monotonic stackMonotonic Stack
Sliding window maximummonotonic dequeTwo Pointers
Majority element, Dutch national flagBoyer–Moore voting, 3-way partitionClassic Array Problems
Activity selection, interval schedulingearliest finish firstInterval Problems
Job sequencing with deadlines, Johnson’s ruleexchange argumentsScheduling
Huffman codingmerge the two smallestGreedy
Josephus problemrecurrence; by bit rotationClassic Puzzles
Tower of Hanoirecursion, movesTower of Hanoi
Water jugsBFS on states; gcd conditionWater Jug
Wolf, goat, cabbage; missionaries and cannibalsBFS on a small state spaceWolf, Goat, Cabbage
Bridge and torchgreedy over two strategiesBridge and Torch
100 prisonersfollow the permutation cycles100 Prisoners
Monty Hallconditional probability, switchMonty Hall
Secretary problemreject the first Secretary Problem
Poisoned winebinary encoding of testersPoisoned Wine
Celebrity problem eliminationCelebrity Problem
Two envelopes paradoxno proper prior gives for every amount; Cover’s random thresholdTwo Envelopes
Boy or girl, Bertrand’s box, three prisonersBayes with the protocol that produced the informationBoy or Girl
St. Petersburg paradoxinfinite expectation; capped bank, log utilitySt. Petersburg Paradox
Buffon’s needleintegral over position and angle; Buffon’s Needle
Blue-eyed islanders, muddy childreninduction on the count; common knowledgeBlue-Eyed Islanders
Rope burning, hourglassessearch over event times; gcd invariantRope Burning
Chomp, Hexstrategy stealing; Hex has no drawsChomp and Hex
Mutilated chessboard, strip tilingscolouring arguments; profile DP countsMutilated Chessboard
15 puzzle (optimal solving)parity solvability; IDA* with Manhattan + linear conflictsFifteen Puzzle
Rubik’s cube group orderSchreier–Sims on sticker permutationsRubik’s Cube
Peg solitairerule-of-three invariant; memoized searchPeg Solitaire
Sudokubitmask backtracking with MRV; exact coverSudoku
Magic squaresSiamese, doubly even, LUXMagic Squares
Euler’s 36 officersorthogonal Latin squares; none of order 6Latin Squares
Kirkman’s schoolgirlsresolvable Steiner triple systemsKirkman’s Schoolgirls
Fair cake cuttingcut and choose, Even–Paz, Selfridge–ConwayCake Cutting
Wheat and chessboard; overflowWheat and Chessboard
Ant on a rubber ropecovered fraction; harmonic series divergesAnt on a Rubber Rope
Zebra puzzle (Einstein’s riddle)permutation CSP with backtrackingZebra Puzzle
Knights and knaves, three godsboolean formulas; embedded question lemmaKnights and Knaves
Bulgarian solitaireenergy on diagonals; rotation and CRTBulgarian Solitaire
Gold chain paymentcomplete sequences; Gold Chain
Instant Insanitytwo edge-disjoint 2-regular subgraphsInstant Insanity
Jeep problem (desert crossing)fuel flux bound; harmonic depotsJeep Problem
Icosian gameHamiltonian cycles, bitmask DPIcosian Game
Pigeonhole classics (socks, handshakes, divisible block)choose the boxesPigeonhole Puzzles
Fitch Cheney five-card trickpigeonhole on suits; permutation encodes Fitch Cheney Trick
N-queens, Sudoku, knight’s tourbacktracking, exact cover, WarnsdorffBacktracking
8 / 15 puzzleA*, parity invariantInformed Search
Subset sum, partition, 4-summeet in the middle, bitset DPMeet in the Middle
Nim, Wythoff, Bash game, staircase nimSprague–Grundy, golden ratioCombinatorial Games
Coupon collector, birthday paradoxlinearity, thresholdProbability
Gambler’s ruin, pattern waiting time (ABRACADABRA)martingales, optional stoppingProbability
Stable marriage, stable roommatesGale–Shapley, IrvingStable Matching
Assignment problemHungarianAssignment Problem
Project selection, densest subgraphmin cut, closureFlow Modeling
Chinese postmanodd vertices + min-weight matchingEuler Tours
Königsberg bridges, de Bruijn sequencesEuler pathsEuler Tours
Graph colouring, chromatic numberinclusion–exclusion Graph Colouring
Closest pair of pointsdivide and conquer / sweepClosest Pair
Smallest enclosing circleWelzlMinimum Enclosing Circle
Art gallery, polygon area, point in polygonshoelace, ray castingPolygons
Range minimum / sum queriessparse table, Fenwick, segment tree8. Range Queries
Count inversionsmerge sort or FenwickSorting
Trailing zeros of , divisors of LegendreFactorials mod p
Frobenius coin problem (McNugget)Congruences and CRT
Derangements, mĂ©nage probleminclusion–exclusionInclusion-Exclusion
Necklaces and braceletsBurnsideBurnside and PĂłlya
Ballot problem, Dyck pathsreflection principleCatalan and Lattice Paths
Fibonacci -th term for huge matrix power, fast doublingMatrix Exponentiation DP
Longest palindromic substringManacherPalindromes
Number of distinct substringssuffix array / automatonSuffix Automaton
Word break from valid breaks of a dictionary-matched prefixClassic DP
Running median, median maintenancetwo heaps balanced in sizeHeaps
Skyline / building silhouettesweep line with a multiset of active heightsSweep Line
Gas station (circular tour)greedy restart after the tank goes negativeGas Station
Cryptarithmetic (SEND + MORE = MONEY)backtracking over digit assignments, pruned by partial column sumsBacktracking