~/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.
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).
6 problems
Quant & trading
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
- Price-level book from order callbacks Optiver py · c++ · java medium
- Crypto order matching Coinbase py · c++ · java easy
- OA: Marketplace trading system with order matching 3 levels Jane Street py · c++ · java hard