Price-Time Priority Limit Order Book With Cancellations
Last updated: November 29, 2026
Quick Overview
Implement an in-memory limit order book for one instrument that accepts BUY and SELL limit orders and cancels, matches crossing orders at the resting order's price using price-time priority, and returns the fills produced by each submission.
Deutsche Bank
November 29, 20260
0
0 solved
Implement an in-memory limit order book for one instrument that accepts BUY and SELL limit orders and cancels, matches crossing orders at the resting order's price using price-time priority, and returns the fills produced by each submission.
Deutsche Bank's electronic trading businesses (for example the Autobahn platform for FX and rates) depend on matching and internalisation logic that must be correct and fast. An onsite coding round uses an order book to see whether the candidate picks the right data structures, handles partial fills, and thinks about cancels without O(n) scans.
What the Interviewer Expects
- Use a max-heap for bids and a min-heap for asks keyed by price then arrival sequence
- Fill at the resting order's price and support partial fills
- Leave any unfilled remainder resting on the book
- Handle cancels efficiently, for example with lazy deletion
- Discuss complexity and determinism
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support order amendments, and which amendments lose time priority?
- How would you return the top five price levels with aggregated size quickly?
- What changes for market orders and immediate-or-cancel orders?
- How would you make this suitable for a low-latency C++ or Java production engine?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Operations: submit(order_id, side, price, qty) returns a list of fills (aggressor_id, resting_id, price, qty); cancel(order_id) returns whether something was cancelled. Rules: a BUY matches asks...
High-Level Design
bids: heap of(-price, seq, id)so the highest price and then earliest seq is on top.asks: heap of(price, seq, id).orders: dict from id to[side, price, remaining], the single sou...