~/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.
586 problems · advanced & competitive are listed separately
Interview roadmap
Arrays & hashing Counting, lookups, sorting with keys, prefix sums.
Complexity analysis guide
- Basics: fast membership with a set basics py · c++ · java easy
- Cross-team handshake energy py · c++ · java easy
- Count distinct values py · c++ · java easy
Hash maps and counting guide
- Basics: count with a dict, then look up basics py · c++ · java easy
- Coffee-shop loyalty stamps easy
- Two Sum py · c++ · java easy
Sorting, custom keys, coordinate compression guide
- Basics: leaderboard with a tuple sort key basics easy
- Natural order for scanned photos py · c++ · java easy
- Largest Number py · c++ · java medium
Prefix sums and difference arrays guide
- Basics: range sums with a prefix array basics py · c++ · java easy
- Uphill metres between checkpoints py · c++ · java easy
- Range Sum Query 2D Immutable py · c++ · java easy
Two pointers Scan from both ends, or fast and slow.
- Basics: pair sum in a sorted list (pointers from both ends) basics py · c++ · java easy
- Photos with a nearby GPS fix py · c++ · java easy
- 3Sum py · c++ · java medium
Stacks Matching brackets, paths, next greater element.
Stacks guide
- Basics: an undo log with a stack basics py · c++ · java easy
- Valid Parentheses py · c++ · java easy
- Implement Queue Using Stacks py · c++ · java easy
Monotonic stack guide
- Basics: nearest smaller value to the left basics py · c++ · java easy
- Messages between signal towers py · c++ · java easy
- Daily Temperatures py · c++ · java easy
Stack: path parsing guide
- Basics: balanced brackets with a stack basics py · c++ · java easy
- Where each piece of text lives py · c++ · java easy
- Simplify Path py · c++ · java easy
Math & matrices Digit arithmetic, rotating and marking grids in place.
- Basics: read a grid in a spiral basics py · c++ · java easy
- Rotate Image py · c++ · java medium
- Set Matrix Zeroes py · c++ · java medium
Sliding window Grow and shrink a window over a string or array.
- Basics: best sum of k in a row (fixed-size window) basics py · c++ · java easy
- Repeat artists in every k-song stretch py · c++ · java easy
- Longest Substring Without Repeating Characters py · c++ · java medium
Binary search Sorted lookups, rotations, searching the answer.
Binary search guide
- Basics: write lower bound yourself basics py · c++ · java easy
- Log entries in a time range py · c++ · java easy
- Binary Search py · c++ · java easy
Binary search on the answer guide
- Basics: smallest value that passes a check basics easy
- Biggest square cookies py · c++ · java easy
- Koko Eating Bananas py · c++ · java medium
Prefix sums + binary search guide
- Basics: which bucket holds position x basics py · c++ · java easy
- How far does the ticket money go? py · c++ · java easy
- Random Pick with Weight py · c++ · java medium
Sorted containers (bisect) guide
- Basics: floor and ceiling with bisect basics py · c++ · java easy
- Nearest free parking spot py · c++ · java easy
- My Calendar I py · c++ · java medium
Linked lists Reverse, merge, detect cycles, build an LRU cache.
Linked lists guide
- Basics: middle node with fast and slow pointers basics py · c++ · java easy
- Shunt the extra wagons onto a siding py · c++ · java easy
- Reverse Linked List py · c++ · java easy
LRU / LFU cache guide
- Basics: a recency list (dict + doubly linked list) basics py · c++ · java easy
- Recent files menu py · c++ · java easy
- LRU Cache py · c++ · java medium
Trees Traversals, BSTs, and answers built bottom-up.
Binary trees guide
- Basics: preorder, inorder and postorder basics easy
- Orchard: branches that need a prop py · c++ · java easy
- Diameter of Binary Tree py · c++ · java easy
Tree DP guide
- Basics: Diameter of a tree basics py · c++ · java easy
- Pruning a diseased fruit tree py · c++ · java easy
- House Robber III py · c++ · java medium
Tries Prefix trees for words and autocomplete.
- Basics: count words by prefix with a trie basics py · c++ · java easy
- Abbreviated shell commands py · c++ · java easy
- Implement Trie (Prefix Tree) py · c++ · java easy
Heaps Top-k, merging streams, scheduling by time.
Heaps and priority queues guide
- Basics: the k smallest values with heapq basics py · c++ · java easy
- Help desk by urgency easy
- Top K Frequent Elements py · c++ · java easy
Heap scheduling (deadlines, leases) guide
- Basics: hand each job to the earliest-free server basics py · c++ · java easy
- Laundromat with impatient customers py · c++ · java easy
- Task Scheduler py · c++ · java medium
Backtracking Recursion that tries, undoes and tries again.
- Basics: choose k of n (choose, explore, un-choose) basics py · c++ · java easy
- Seating plan without feuding neighbours py · c++ · java easy
- Subsets py · c++ · java easy
Intervals Merge, insert and sweep over ranges.
- Basics: do any meetings overlap? basics py · c++ · java easy
- Longest stretch with the shop open py · c++ · java easy
- Merge Intervals Roblox py · c++ · java easy
Greedy Sort, then take the locally best choice.
- Basics: feed the most children basics py · c++ · java easy
- Fewest benches along the trail py · c++ · java easy
- Non-overlapping Intervals py · c++ · java medium
Graphs Grids and networks: BFS, DFS, cycles, ordering.
BFS / multi-source BFS guide
- Basics: shortest hop counts from one node basics py · c++ · java easy
- Museum: fewest doors to an exhibit py · c++ · java easy
- Rotting Oranges py · c++ · java medium
DFS and connected components guide
- Basics: everything reachable from a node (iterative DFS) basics py · c++ · java easy
- Storm outage: neighbourhoods without a generator py · c++ · java easy
- Number of Islands py · c++ · java easy
Cycle detection guide
- Basics: does a directed graph have a cycle? basics py · c++ · java easy
- Spreadsheet: show the circular reference easy
- Find Eventual Safe States py · c++ · java medium
Bipartite graphs / 2-colouring guide
- Basics: colour by BFS depth, find the bad edges basics py · c++ · java easy
- Day and night shifts with fixed staff easy
- Is Graph Bipartite? py · c++ · java easy
Topological sort (Kahn's) guide
- Basics: check a topological order basics py · c++ · java easy
- What to rebuild, and in what order easy
- Course Schedule py · c++ · java easy
1-D dynamic programming One index of state: stairs, robbers, subsequences.
Intro DP guide
- Basics: Cheapest way up a staircase basics py · c++ · java easy
- Flower cart: station or park py · c++ · java easy
- Climbing Stairs py · c++ · java easy
Longest increasing subsequence guide
- Basics: LIS length ending at each index (O(n²) DP) basics py · c++ · java easy
- Choir line with a height gap py · c++ · java medium
- Longest Increasing Subsequence py · c++ · java medium
Weighted graphs Dijkstra, union-find, spanning trees.
Dijkstra (weighted shortest paths) guide
- Basics: the order Dijkstra settles nodes basics py · c++ · java easy
- Walk to the nearest open pharmacy py · c++ · java easy
- Network Delay Time py · c++ · java easy
Union-Find guide
- Basics: count groups with find and union basics py · c++ · java easy
- Pooled lunch money easy
- Number of Provinces py · c++ · java easy
Minimum spanning tree guide
- Basics: Prim's algorithm with a heap basics py · c++ · java easy
- Finish the irrigation network py · c++ · java easy
- Min Cost to Connect All Points py · c++ · java medium
2-D dynamic programming Grids, two strings, knapsacks, ranges.
Grid DP guide
- Basics: Count grid paths around obstacles basics easy
- Mushroom walks with an exact haul easy
- Minimum Path Sum py · c++ · java easy
String DP (edit distance, LCS) guide
- Basics: Longest common substring basics py · c++ · java easy
- Threading beads from two belts py · c++ · java medium
- Edit Distance py · c++ · java medium
Knapsack and coin change guide
- Basics: Can a subset hit the target? (0/1 subset sum) basics py · c++ · java easy
- Prize stall with limited stock py · c++ · java easy
- Coin Change py · c++ · java medium
Interval (range) DP guide
- Basics: Cheapest way to merge adjacent piles basics py · c++ · java easy
- Least wobbly hanging mobile py · c++ · java easy
- Longest Palindromic Subsequence py · c++ · java medium
Bit manipulation Masks, shifts and IP-address arithmetic.
- Basics: IPv4 addresses as 32-bit integers basics easy
- Watering rota as weekday bitmasks easy
- Cover an IP range with CIDR blocks py · c++ · java medium
Practical systems
Simulation & OOP design Model the rules precisely, keep it extensible.
Simulation
- Basics: robot on a walled grid (state + step loop) basics easy
- Rain barrel log py · c++ · java easy
- Game of Life: in place, then on an infinite board 2 levels Citadel medium
Object-oriented design and extensible simulations
- Basics: a bank account class with invariants basics easy
- Greenhouse watering rota easy
- OA: Recipe manager with versions 4 levels Anthropic medium
Stateful stores Key-value stores, file systems, banks, with history.
Time-travel key-value store
- Basics: the value as of time t (bisect on history) basics py · c++ · java easy
- Time-Based Key-Value Store Citadel py · c++ · java easy
- Library display shelves over time py · c++ · java easy
In-memory file system
- Basics: directory tree from paths basics py · c++ · java easy
- Camera card: find by extension, delete folders py · c++ · java easy
- Design In-Memory File System py · c++ · java medium
In-memory database
- Basics: records of fields in nested dicts basics easy
- Per-field undo in a record store easy
- OA: In-memory database 5 levels Anthropic medium
Bank system
- Basics: accounts with validated deposits and withdrawals basics py · c++ · java easy
- Settle a night's tab all-or-nothing easy
- OA: Bank system 4 levels Anthropic py · c++ · java medium
Iterators & parsers Lazy sequences, tokenizers and tiny interpreters.
Iterators and generators
- Basics: an iterator class that yields chunks basics easy
- Collapse repeated sensor readings easy
- OA: Weighted data batcher with checkpointing 3 levels Anthropic medium
Parsers and interpreters
- Basics: tokenize an arithmetic expression basics easy
- Parse a label printer's key=value line easy
- ML config loader: inherit, override, interpolate, validate 4 levels Anthropic medium
Streams & durability Rate counters, serialization, retrying work queues.
Rolling windows and rate counters
- Basics: count hits in the last N seconds basics py · c++ · java easy
- Café drink counts over the last N seconds py · c++ · java easy
- Key-value store with rolling QPS 3 levels Databricks medium
Serialization and durability
- Basics: length-prefixed encoding of a list of strings basics easy
- Escaped key=value settings file easy
- OA: Memoizing LRU cache that survives crashes 3 levels Anthropic medium
Fault-tolerant work queue
- Basics: expire leases with a min-heap basics py · c++ · java easy
- Round-robin print queue across customers py · c++ · java easy
- OA: Fault-tolerant work queue 3 levels OpenAI medium
Files & networks Deduplicating files, resolving names.
File deduplication
- Basics: group paths by identical content basics easy
- Clean up notes synced from two laptops easy
- Find duplicate files (size, prefix, content) 3 levels Anthropic medium
DNS resolver
- Basics: follow a CNAME chain with loop detection basics easy
- Exact and wildcard records, most specific wins easy
- DNS resolution with CNAME cycles 5 levels Anthropic hard
Concurrency
Locks Mutexes, lock ordering, readers and writers.
Lock (mutex)
- Basics: thread-safe counter basics easy
- Last croissants at the bakery easy
- Print in order with locks easy
Deadlock and lock ordering
- Basics: take several locks without deadlock basics easy
- Shared party playlist easy
- Dining philosophers without deadlock medium
Reader-writer and modal locks
- Basics: a simple reader-writer lock basics easy
- Timetable board: writers go first easy
- ModalLock and FairModalLock 3 levels OpenAI hard
Coordination Semaphores, conditions and barriers.
Semaphore
- Basics: at most k at once basics easy
- Laundromat washers easy
- Bounded blocking queue medium
Condition variable
- Basics: countdown latch basics easy
- Baggage carousel easy
- FizzBuzz across four threads medium
Barrier
- Basics: build a reusable barrier basics easy
- Street lamps that copy their neighbours easy
Pools & pipelines Thread pools, crawlers, producer/consumer buffers.
Thread pool / concurrent crawler
- Basics: parallel map with a pool basics easy
- Fastest weather station wins easy
- Image transformation pipeline with processes 3 levels Anthropic medium
Ring buffers and producer/consumer pipelines
- Basics: blocking ring buffer basics easy
- Greenhouse thermometer log easy
- Single-producer, multi-consumer ring buffer 3 levels Citadel medium
Quant & trading
Probability Expected value, sampling, randomized algorithms.
Probability and expected value
- Basics: distribution of a dice sum basics easy
- Surprise scoops: expected flavours tried easy
- Uniform 1..10 from a 1..7 die medium
Randomized algorithms
- Basics: weighted random pick basics easy
- Plant swap: nobody keeps their own cutting easy
- Random node of a linked list medium
Trading systems Order books, matching engines, market simulations.
Order books and matching engines
- Basics: top of book from resting orders basics easy
- Sweep the book with a market order easy
- One-share order book matching Optiver py · c++ · java medium
Market and strategy simulations
- Basics: position, cash and PnL from fills basics easy
- Backtest a band trader py · c++ · java easy
- Backtest a proportional momentum strategy 2 levels Optiver medium