~/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.
Order books and matching engines
Price levels, price-time priority, partial fills, cancels.
Main path: 6 problems, about 3 hours.
Notes
Recognise it when: limit and market orders, bids and asks, "best bid/offer", matching, cancels, price-level aggregation from a market-data feed.
- Book structure: for each side, a map of
price -> deque of orders(FIFO within a price gives time priority), plus sorted price levels. In Python, use heaps with lazy deletion orbisecton sorted price lists. - Matching a buy limit at price P: while the best ask ≤ P and quantity remains, fill against the front order at the best ask (the trade happens at the resting order's price). Pop filled orders, and remove empty levels. Any remainder rests on the bid side.
- Market order: match at any price, and never rest.
- Cancel / modify: keep an
order_id -> orderindex. Reducing quantity usually keeps queue priority, while increasing it or changing the price loses priority (cancel and re-add). - A price-level book from a feed (add/modify/delete messages): aggregate quantity per price, and report the top N levels.
Gotchas: crossing your own order, zero-quantity leftovers, ties at the same price (FIFO), and floats for prices (use integer ticks).
7 problems
Advanced & competitive
Order books Matching engines and market simulations (exchange and fintech assessments).
Order books and matching engines
- Top of book from resting orders basics py · c++ · java easy
- Sweep the book with a market order py · c++ · java easy
- Crypto order matching Coinbase py · c++ · java easy
- One-share order book matching Optiver py · c++ · java medium
- Price-level book from order callbacks Optiver py · c++ · java medium
- Marketplace trading system with order matching assessment 3 levels Jane Street py · c++ · java hard
More practice: 1 problem
- IPO share allocation assessment 2 levels Two SigmaPoint72 py · c++ · java medium