Match Limit Orders in a Price-Time Priority Book

Last updated: November 29, 2026

Quick Overview

Implement a single-symbol limit order book that accepts buy and sell limit orders and cancels, matches crossing orders at the resting order's price with price-time priority, and reports fills and the current best bid and ask.

Akuna Capital
Coding & Algorithms
Software Engineer
Akuna Capital
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Implement a single-symbol limit order book that accepts buy and sell limit orders and cancels, matches crossing orders at the resting order's price with price-time priority, and reports fills and the current best bid and ask.

Akuna Capital is an options market maker, so engineers on trading and exchange-simulation teams are expected to know how a matching engine behaves. The interviewer checks that you get priority rules, partial fills and cancels right, and that you pick data structures with clear complexity rather than scanning the whole book.

What the Interviewer Expects
  • State matching rules: trade at the resting price, best price first, earliest order first at a price
  • Use heaps (or sorted price levels) for both sides with O(log n) insert and match
  • Handle partial fills on both the aggressor and the resting order
  • Support cancel without an O(n) heap search, for example lazy deletion
  • Return fills as (aggressor, resting, price, qty) so results are testable
  • Discuss how a production C++ book would differ (price-level arrays, intrusive lists)
Key Topics to Cover
order book
heaps
lazy deletion
price-time priority
matching engine
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you support order modify, and when does a modify lose time priority?
  • How would you add market orders and immediate-or-cancel orders?
  • If prices are ticks in a narrow band, what structure beats a heap?
  • How do you produce top-of-book and depth updates for downstream consumers?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Orders are (id, side, price, qty). A buy crosses when its price is at or above the best ask, a sell when at or below the best bid. Trades print at the resting order's price. Within a price, the ea...

High-Level Design

Keep two heaps: bids as (-price, seq, id) and asks as (price, seq, id), where seq is an arrival counter that breaks ties by time. A dict orders[id] = [side, price, remaining] is the source of ...


Submit Your Answer
Markdown supported

Related Questions