Solved problems
50 original problems so far. Each has hints you reveal one at a time, the reasoning behind the solution, why it is correct, what it costs, the same solution in four languages, and a walkthrough you can run on your own inputs. Nothing is graded: there is no submission and no verdict.
| Problem | Difficulty | Technique | Time |
|---|---|---|---|
| Two prices that fit the budget exactly | beginner | two pointers, sorted array | O(n) |
| Two readings that add up to a target | beginner | hashing, arrays | O(n) expected |
| Has any badge been scanned twice? | beginner | hashing, sets | O(n) expected |
| Push the empty slots to the end | beginner | two pointers, read/write pointers | O(n) |
| Do the brackets close properly? | beginner | stacks, strings | O(n) |
| The busiest stretch of k hours | beginner | sliding window, arrays | O(n) |
| The best streak of daily profits | intermediate | dynamic programming, Kadane's algorithm | O(n) |
| Every product but your own | intermediate | prefix products, arrays | O(n) |
| The longest stretch without a repeated letter | intermediate | sliding window, hashing | O(n) expected |
| Where does a value start and end? | intermediate | binary search, lower bound | O(log n) |
| The one ticket that never came back | beginner | math, arrays | O(n) |
| Does the phrase read the same both ways? | beginner | two pointers, strings | O(n) |
| Same letters, different order? | beginner | hashing, counting | O(n) expected |
| Where do both sides weigh the same? | beginner | prefix sums, arrays | O(n) |
| Two walls that hold the most water | intermediate | two pointers, greedy | O(n) |
| Shift the schedule by k days | intermediate | arrays, in place | O(n) |
| Red, white and blue in one pass | intermediate | two pointers, partition | O(n) |
| Which candidate has more than half the votes? | intermediate | voting algorithm, arrays | O(n) |
| How many days until it gets warmer? | intermediate | monotonic stack, stacks | O(n) |
| How many stretches add up to k? | intermediate | prefix sums, hashing | O(n) expected |
| Buy once, sell once, profit most | beginner | arrays, greedy | O(n) |
| Keep one copy of each sorted value | beginner | two pointers, read/write pointers | O(n) |
| Merge two sorted lists into the first one | beginner | two pointers, merging | O(m + n) |
| Find the first broken build | beginner | binary search, monotonic predicate | O(log n) checks |
| The sock without a pair | beginner | bit manipulation, XOR | O(n) |
| Count the 1 bits | beginner | bit manipulation, masks | O(number of 1 bits) ≤ O(width) |
| The largest tile that fits both walls | beginner | math, Euclidean algorithm | O(log min(a, b)) iterations |
| Run-length encode a word | beginner | strings, two pointers | O(n) |
| How many ways up the stairs? | beginner | dynamic programming, tabulation | O(n) |
| Collect the most without taking neighbours | intermediate | dynamic programming, state machine | O(n) |
| The first letter that never repeats | beginner | strings, frequency count | O(n) |
| Group words that share their letters | intermediate | strings, hashing | O(n · L log L) expected |
| Count the mirror-image substrings | intermediate | strings, palindromes | O(n²) worst case |
| Set bits for every number up to n | beginner | bit manipulation, dynamic programming | O(n) |
| The one value not in a triple | advanced | bit manipulation, XOR | O(n) |
| Can you hop to the last stone? | intermediate | greedy, arrays | O(n) |
| Where to start a round trip on a fuel budget | intermediate | greedy, circular array | O(n) |
| Next bigger value on a ring | intermediate | monotonic stack, circular array | O(n) |
| Where does the linked list loop back? | advanced | linked lists, fast and slow pointers | O(n) |
| The cheapest walk down and right | intermediate | dynamic programming, grid | O(rows · columns) |
| The k-th highest score | beginner | heap, top-k | O(n log k) |
| The k values seen most often | intermediate | heap, top-k | O(n + m log k) |
| Combine overlapping bookings | intermediate | intervals, sorting | O(n log n) |
| How many rooms for these meetings? | intermediate | intervals, sorting | O(n log n) |
| Fewest steps across a walled grid | intermediate | BFS, grid | O(rows · columns) |
| Minutes until the whole office knows | intermediate | BFS, multi-source BFS | O(rows · columns) |
| Count the separate land masses | intermediate | DFS, grid | O(rows · columns) |
| How many separate networks? | intermediate | union-find, disjoint sets | O(n + m · α(n)) |
| The first cable that closes a loop | intermediate | union-find, cycle detection | O(n + m · α(n)) |
| An order that respects every dependency | intermediate | topological sort, Kahn's algorithm | O(n + m) |
Techniques covered: BFS · DFS · Dutch national flag · Euclidean algorithm · Fibonacci · Kadane's algorithm · Kahn's algorithm · XOR · anagrams · arithmetic series · arrays · binary search · bit manipulation · canonical key · circular array · complement · connected components · counting · counting mod 3 · cycle detection · disjoint sets · dynamic programming · expand around center · fast and slow pointers · flood fill · frequency count · gcd · graphs · greedy · grid · hashing · heap · in place · intervals · level order · linked lists · lower bound · masks · math · merging · monotonic predicate · monotonic stack · multi-source BFS · next greater element · palindromes · parsing · partition · prefix products · prefix sums · priority queue · queue · reachability · read/write pointers · reversal · running minimum · running sum · search on answer · sets · shifts · shortest path · sliding window · sorted array · sorting · stack · stacks · state machine · string builder · strings · sweep · sweep line · tabulation · top-k · topological sort · two pointers · union-find · voting algorithm.