Practice
Solved learning, not judging: reveal hints when you need them, compare your reasoning with the worked solution, and step through it. There is no code submission, no verdict and no score.
Solved problems (50)
All problems →- Two prices that fit the budget exactlybeginner · two pointers · sorted array · arrays
- Two readings that add up to a targetbeginner · hashing · arrays · complement
- Has any badge been scanned twice?beginner · hashing · sets · arrays
- Push the empty slots to the endbeginner · two pointers · read/write pointers · in place
- Do the brackets close properly?beginner · stacks · strings · parsing
- The busiest stretch of k hoursbeginner · sliding window · arrays
- The best streak of daily profitsintermediate · dynamic programming · Kadane's algorithm · arrays
- Every product but your ownintermediate · prefix products · arrays
- The longest stretch without a repeated letterintermediate · sliding window · hashing · strings
- Where does a value start and end?intermediate · binary search · lower bound · sorted array
- The one ticket that never came backbeginner · math · arrays · arithmetic series
- Does the phrase read the same both ways?beginner · two pointers · strings
- Same letters, different order?beginner · hashing · counting · strings
- Where do both sides weigh the same?beginner · prefix sums · arrays
- Two walls that hold the most waterintermediate · two pointers · greedy · arrays
- Shift the schedule by k daysintermediate · arrays · in place · reversal
- Red, white and blue in one passintermediate · two pointers · partition · Dutch national flag
- Which candidate has more than half the votes?intermediate · voting algorithm · arrays · counting
- How many days until it gets warmer?intermediate · monotonic stack · stacks · next greater element
- How many stretches add up to k?intermediate · prefix sums · hashing · counting
- Buy once, sell once, profit mostbeginner · arrays · greedy · running minimum
- Keep one copy of each sorted valuebeginner · two pointers · read/write pointers · sorted array
- Merge two sorted lists into the first onebeginner · two pointers · merging · in place
- Find the first broken buildbeginner · binary search · monotonic predicate · search on answer
- The sock without a pairbeginner · bit manipulation · XOR
- Count the 1 bitsbeginner · bit manipulation · masks
- The largest tile that fits both wallsbeginner · math · Euclidean algorithm · gcd
- Run-length encode a wordbeginner · strings · two pointers · string builder
- How many ways up the stairs?beginner · dynamic programming · tabulation · Fibonacci
- Collect the most without taking neighboursintermediate · dynamic programming · state machine
- The first letter that never repeatsbeginner · strings · frequency count · hashing
- Group words that share their lettersintermediate · strings · hashing · canonical key
- Count the mirror-image substringsintermediate · strings · palindromes · expand around center
- Set bits for every number up to nbeginner · bit manipulation · dynamic programming · shifts
- The one value not in a tripleadvanced · bit manipulation · XOR · counting mod 3
- Can you hop to the last stone?intermediate · greedy · arrays · reachability
- Where to start a round trip on a fuel budgetintermediate · greedy · circular array · running sum
- Next bigger value on a ringintermediate · monotonic stack · circular array
- Where does the linked list loop back?advanced · linked lists · fast and slow pointers · cycle detection
- The cheapest walk down and rightintermediate · dynamic programming · grid · tabulation
- The k-th highest scorebeginner · heap · top-k · priority queue
- The k values seen most oftenintermediate · heap · top-k · hashing
- Combine overlapping bookingsintermediate · intervals · sorting · sweep
- How many rooms for these meetings?intermediate · intervals · sorting · sweep line
- Fewest steps across a walled gridintermediate · BFS · grid · shortest path
- Minutes until the whole office knowsintermediate · BFS · multi-source BFS · level order
- Count the separate land massesintermediate · DFS · grid · connected components
- How many separate networks?intermediate · union-find · disjoint sets · connected components
- The first cable that closes a loopintermediate · union-find · cycle detection · graphs
- An order that respects every dependencyintermediate · topological sort · Kahn's algorithm · graphs
Complexity exercises (30)
Big O explorer →By topic:
amortized
arithmetic series
average case
backtracking
best case
binary search
break
builders
call stack
constants
cubic
dynamic arrays
dynamic programming
exponential
factorial
geometric series
harmonic series
hidden cost
linear
- One loop over the input
- Two loops one after the other
- Inner loop bounded by a halving outer variable
- Stepping by three
- Sequential loops over two inputs
- Recursion that peels off one element
- Two halves plus constant work
- n appends to a doubling dynamic array
- Linear search that stops early
- Two pointers moving toward each other
- A while loop inside a for loop (sliding window)
linearithmic
logarithmic
loops
- One loop over the input
- Two loops one after the other
- A loop inside a loop
- Inner loop that depends on the outer index
- Halving until one is left
- Doubling a counter
- A linear loop around a doubling loop
- Inner loop bounded by a halving outer variable
- Stepping by three
- Loop until i² exceeds n
- Three nested loops
- Nested loop with a break
- Inner loop stepping by the outer index
matrix multiplication
merge sort
multiple inputs
nested
potential argument
primes
quadratic
recurrences
recursion
recursion tree
sieve
sliding window
sorting
space
square root
strings
trees
two pointers
worst case