A progressive journey from absolute beginner to advanced competitor
Every chapter builds on the last. You'll start by reading input and writing output, then progress through loops, arrays, sorting, recursion, dynamic programming, graphs, and advanced techniques — all the way to grandmaster-level problem solving.
Code examples in C++ and Rust throughout each chapter.
stdin, stdout, multiple test cases — the foundation of every solution.
Chapter 2while and for loops, summation, counting, and accumulation patterns.
Chapter 3if/else, logical operators, ternary expressions — making decisions in code.
Chapter 4Indexing, iteration, vectors — storing collections of data.
Chapter 5Strings as character arrays, reading, reversing, counting characters.
Chapter 6Parameters, return values, reusability — breaking code into named blocks.
Chapter 7Single-responsibility, extracting helpers, naming — writing readable code.
Chapter 8Off-by-one, print debugging, compiler errors, common pitfalls.
Chapter 9Running totals, frequency counters, conditional counting.
Chapter 10Manual min/max, built-in helpers, single-pass both-at-once.
Linear search, find first occurrence, count occurrences.
Chapter 12Replacing nested ifs with early returns for cleaner code.
Chapter 13Understanding O(N²) sorts — and why you'll rarely write them.
Chapter 14One-liner sort with custom comparators. O(N log N).
Chapter 15Pair sum, remove duplicates — O(N²) → O(N) with two indices.
Chapter 16Fixed and variable-size windows for O(N) subarray problems.
Chapter 17Extracting the shrink-while loop into a reusable helper.
Trial division, √N optimisation — checking primality.
Chapter 19O(N log log N) sieve for finding all primes up to N.
Chapter 20Euclidean algorithm — O(log min(a,b)).
Chapter 21LCM from GCD, avoiding overflow, array LCM.
Chapter 22Add, multiply, subtract modulo M. Why 10⁹+7.
Chapter 23Binary exponentiation — O(log b) instead of O(b).
Chapter 24Generic template, recursive vs iterative approaches.
Chapter 25nCr via modular inverses and Fermat's little theorem.
Chapter 26O(1) nCr with precomputed fact & inv_fact arrays.
Dynamic resizing, push_back, reserve — your default array type.
Chapter 28LIFO data structure, push/pop/top, balanced parentheses.
Chapter 29Counter vs stack for multiple bracket types, index stacks.
Chapter 30FIFO, deque, and a preview of BFS on grids.
Chapter 31Key-value stores, unordered_map, HashMap, ordered vs unordered.
Chapter 32O(N²) nested loops → O(N) hash map — anagram checking.
Chapter 33Uniqueness, HashSet, unordered_set, duplicate detection.
Chapter 34Max-heap, min-heap, top K elements pattern.
Chapter 35O(N²) insert-and-shift → O(N log N) two-heap streaming median.
Base cases, stack frames, and the recursive leap of faith.
Chapter 37Linear recursion vs tree recursion — O(N) vs O(2^N).
Chapter 38Caching recursive results: O(2^N) Fibonacci → O(N).
Chapter 39Include/exclude decision tree and the power set.
Chapter 40Recursive subsets → iterative bitmask enumeration (2^N loop).
Chapter 41N! permutations, C(N,K) combinations, next_permutation.
Chapter 42Classic backtracking: row-by-row placement with O(1) conflict checks.
Chapter 43O(N) scan → O(1) boolean array lookup. Symmetry and forward checking.
Local vs global optima, when greedy works, and the coin change example.
Chapter 45Sort by finish time, greedily pick non-overlapping activities.
Chapter 46Brute force O(N×2^N) → greedy O(N log N) interval scheduling.
Chapter 47Sort by value/weight ratio, take as much of the best as you can.
Chapter 48Prefix-free codes, merge the two smallest frequencies greedily.
Chapter 49O(N²) linear scan → O(N log N) min-heap Huffman merge.
Optimal substructure, overlapping subproblems, top-down vs bottom-up.
Chapter 51Memoisation vs tabulation — O(2^N) to O(N).
Chapter 52O(N) array → O(1) rolling variables for linear DP.
Chapter 53Fibonacci in disguise — counting ways with 1 or 2 steps.
Chapter 54Take or leave each item — classic 2D DP with recurrence.
Chapter 55O(N×W) memory → O(W) with backward capacity iteration.
Chapter 562D DP for string comparison — match extends, mismatch skips.
Chapter 57O(N×M) → O(M) memory with two-row rolling technique.
Chapter 58Levenshtein distance — insert, delete, replace operations.
Chapter 59Unbounded knapsack — minimum coins and counting ways.
Chapter 60Choosing between memoisation and tabulation in contests.
Chapter 612D grid DP — from above + from left, obstacles, space optimisation.
Chapter 62DFS post-order DP — subtree properties computed bottom-up.
Chapter 63Counting numbers with properties in a range using the tight flag.
Chapter 64Bitmask DP for TSP — O(N² × 2^N) set-DP template.
O(V+E) graph representation — the standard for sparse graphs.
Chapter 66O(V²) representation — O(1) edge queries for dense graphs.
Chapter 67When to use list vs matrix — decision framework with conversion.
Chapter 68Recursive and iterative DFS — O(V+E) graph exploration.
Chapter 69Queue-based level-order traversal and shortest path in unweighted graphs.
Chapter 70DFS from each unvisited node — find and label components.
Chapter 71Near-O(1) dynamic connectivity with path compression.
Chapter 72Shortest path — O(V²) naive version for dense graphs.
Chapter 73O((V+E) log V) — the standard Dijkstra for sparse graphs.
Chapter 74Shortest paths with negative edges and cycle detection.
Chapter 75O(V+E) shortest path using topological order — no heap needed.
Chapter 76Sort edges by weight, add non-cycle edges.
Chapter 77O(E log V) MST — DSU makes cycle check near-O(1).
Chapter 78Grow the tree with a priority queue — O((V+E) log V).
Chapter 79Kahn's algorithm — O(V+E) DAG ordering with cycle detection.
Chapter 80Two-pass DFS for strongly connected components.
Chapter 81Single-pass SCC with low-link values and a stack.
O(log N) search on sorted arrays — the classic divide-and-conquer.
Chapter 83C++ lower_bound/upper_bound and Rust partition_point.
Chapter 84Search the solution space with monotonic predicates.
Chapter 85Finding max/min of unimodal functions in O(log range).
Chapter 862^N → 2 × 2^(N/2) — subset sum for N ≤ 40.
Chapter 87Essential bit tricks — LSB, popcount, power-of-two check.
Chapter 88sub = (sub-1) & mask — enumerate subsets of a bitmask.
Chapter 89Count unions with bitmask — add odd subsets, subtract even.
Chapter 90O(K³ log N) linear recurrences — Fibonacci for N=10¹⁸.
Chapter 91Cache-friendly i-k-j loops and zero-skip optimisations.
Chapter 92O(√N) range queries with blocks of size √N.
Chapter 93Offline range queries in O((N+Q)√N).
DFS pre/post-order — the foundation of all tree algorithms.
Chapter 95BST properties and using std::set/map as ordered containers.
Chapter 96Finding LCA with naive walk-up — O(N) per query.
Chapter 97O(N log N) preprocess, O(log N) LCA queries.
Chapter 98O(log N) range queries and point updates.
Chapter 99O(log N) range updates with deferred propagation.
Chapter 100O(log N) prefix sums — simpler and faster than segment tree.
Chapter 101Two BITs for O(log N) range update + range query.
Chapter 102Prefix tree — O(L) string search and prefix queries.
Chapter 103Sorted suffixes for pattern matching and stringology.
Chapter 104Path queries in O(log² N) using heavy path decomposition.
O(N+M) string matching with the LPS prefix function.
Chapter 106O(N) pattern matching via Z-array on concatenated string.
Chapter 107O(N+M) average string matching with rolling hash.
Chapter 108Eliminating hash collisions with two moduli.
Chapter 109O(N) longest palindromic substring — all radii at once.
Chapter 110Multi-pattern matching — trie + KMP failure links.
DFS-based max flow with residual graphs.
Chapter 112BFS-based Ford-Fulkerson — O(V×E²) max flow.
Chapter 113The standard max flow — level graph + blocking flow.
Chapter 114Max flow = min cut. Finding the cut from residual graph.
Chapter 115Kuhn's DFS augmenting paths — O(V×E) matching.
Chapter 116O(E√V) bipartite matching with BFS + DFS phases.
Dot product, cross product, orientation — geometry primitives.
Chapter 118Convex hull via polar angle sorting.
Chapter 119Andrew's algorithm — integer-only convex hull.
Chapter 120Checking segment intersection with orientation tests.
Chapter 121Ray casting — O(N) point-in-polygon test.
Chapter 122O(N log N) divide-and-conquer closest pair of points.
Chapter 123Plane sweep paradigm for geometric intersection problems.
φ(n) = count of coprimes ≤ n — O(√N) computation.
Chapter 125All φ(1..N) in O(N log log N).
Chapter 126Fermat (prime M) and extended Euclidean (any M).
Chapter 127Solving systems of congruences with coprime moduli.
Chapter 128Incremental CRT avoiding large intermediate products.
Chapter 129Multiplicative function for divisibility inclusion-exclusion.
Chapter 130FFT over finite fields — O(N log N) polynomial multiplication.
XOR of pile sizes determines the winner.
Chapter 132Every impartial game = Nim heap. mex of reachable states.
Chapter 133Top-down Grundy computation for sparse state spaces.
Chapter 134Linearity of expectation and indicator random variables.
Chapter 135Estimating values through random sampling.
Chapter 136Variance reduction by sampling from skewed distributions.
Extracting the core problem in 30 seconds.
Chapter 138Constraint → algorithm guide — which O matches which N.
Chapter 139Pre-submission checklist to catch TLE/MLE/WA bugs.
Chapter 140Random test generation with brute-force comparison.
Chapter 141Top 5 bugs — off-by-one, overflow, uninitialised, modulo, reset.
Chapter 142Writing code that prevents bugs with assertions and safe patterns.
Chapter 143Building a lean contest template — I/O, aliases, debug helpers.
Chapter 144Time management — problem order and the 20-minute rule.
Chapter 145ICPC roles — reader, thinker, coder. Communication is everything.
Chapter 146Combining techniques — the mindset for advanced problem solving.
16 phases · 146 chapters · From zero to grandmaster
Built with Tailwind CSS · Edited in LazyVim on macOS