~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
85 problems
Advanced & competitive
Range queries Fenwick trees, segment trees, sparse tables.
Fenwick tree (BIT) guide
- Basics: which cells a Fenwick tree touches basics easy
- Deli counter: people ahead of you py · c++ · java easy
- Range sums with point updates py · c++ · java easy
Segment tree (+ lazy propagation) guide
- Basics: build and update a bottom-up segment tree basics easy
- Greenhouse: hottest sensor in a range py · c++ · java easy
- Falling squares py · c++ · java hard
Sparse table (static RMQ)
- Basics: build a sparse table basics py · c++ · java easy
- Tide gauge: rise and fall between two hours py · c++ · java easy
Tree techniques Binary lifting, LCA, Euler tours.
Binary lifting / LCA
- Basics: build the jump table basics py · c++ · java easy
- Earliest ancestor born since a year py · c++ · java easy
- K-th ancestor queries py · c++ · java medium
Euler tour of a tree
- Basics: entry and exit times (tin / tout) basics py · c++ · java easy
- Upstream or downstream? py · c++ · java easy
- Subtree sums with updates medium
More shortest paths Bellman-Ford, Floyd-Warshall, 0-1 BFS.
- Basics: Bellman-Ford with negative edges basics py · c++ · java easy
- Fewest climbs on the hiking trails py · c++ · java easy
- Minimum Cost to Make at Least One Valid Path in a Grid py · c++ · java medium
Advanced DP Bitmask and digit DP.
Bitmask DP
- Basics: cheapest one-to-one job assignment basics py · c++ · java easy
- Pairing up lab partners py · c++ · java easy
- Shortest walk visiting every node py · c++ · java hard
Digit DP
- Basics: Count numbers with a given digit sum basics py · c++ · java easy
- Raffle tickets short on ink py · c++ · java easy
- Count the digit 1 py · c++ · java medium
Search tricks Ternary search, meet in the middle.
Ternary search
- Basics: peak of a unimodal function on reals basics easy
- When is the drone closest to the beacons? py · c++ · java easy
- Peak of a mountain array easy
Meet in the middle
- Basics: subset sums of two halves basics easy
- Trail mix with two exact targets py · c++ · java easy
- Subset sum closest to a goal py · c++ · java medium
String hashing Rolling hashes and Rabin-Karp.
- Basics: prefix hashes for O(1) substring comparison basics py · c++ · java easy
- Counting phrases on a ticker tape py · c++ · java easy
- Repeated DNA Sequences py · c++ · java easy
Number theory Modular arithmetic, primes, matrix powers.
Modular arithmetic
- Basics: dividing under a prime modulus basics easy
- Yeast growth over a range of hours py · c++ · java easy
- Pow(x, n) py · c++ · java easy
Primes, divisors and GCD
- Basics: all divisors up to the square root basics py · c++ · java easy
- Festival lanterns blinking together py · c++ · java easy
- Count Primes py · c++ · java easy
Matrix exponentiation
- Basics: matrix multiply and matrix power basics easy
- Seed library with donations py · c++ · java easy
- N-th Tribonacci Number easy
Counting Combinatorics, inclusion-exclusion, Catalan numbers.
Combinatorics / inclusion-exclusion
- Basics: binomial coefficients with Pascal's triangle basics easy
- Tasting panel with every group easy
- Count distinct rearrangements of a string py · c++ · java easy
Catalan numbers
- Basics: Non-crossing handshakes around a table basics easy
- Arm-wrestling along a bench easy
- Unique Binary Search Trees py · c++ · java medium
Geometry Cross products, orientation, polygons.
- Basics: polygon area with the shoelace formula basics py · c++ · java easy
- Which triangular pen is the sheep in? py · c++ · java easy
- Maximum Points on a Line py · c++ · java medium