← Optiver Interview Insights

Optiver·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Optiver software engineer interview with a trading systems flavor. They gave me an order matching problem that sounds straightforward until you actually have to think about the data structures under pressure.

Questions Asked (1)

Q1

Design and implement a price-based order matcher for unit-sized orders. Given an array of orders where each order is a [type, price] pair (type 1 = buy, type -1 = sell), process them in arrival order: a buy matches the cheapest resting sell at or below its price, a sell matches the most expensive resting buy at or above its price, and unmatched orders rest in the book. Return the sum of all executed trade prices. What data structures would you use, what's the time complexity, and how do you handle ties?

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

The matching logic itself clicked pretty fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints and edge cases, then propose using two heaps (max-heap for buy orders, min-heap for sell orders) to efficiently match orders. Explain the matching logic, tie-breaking rules, and analyze time and space complexity, emphasizing O(log n) insertion and O(1) peek for matching.

Pro tip: Mention that you would use a heap because it naturally provides the best price (max for buys, min for sells) in O(1) time, and discuss how to handle ties by either price-time priority or any consistent rule, showing awareness of real-world trading systems.

1. Clarify requirements and constraints

Ask about order size (unit-sized), tie-breaking rules (e.g., price-time priority), and whether partial fills are possible. Confirm that orders are processed in arrival order and that we need to return the sum of executed trade prices.

2. Choose data structures

Propose using two priority queues: a max-heap for buy orders (to get the highest bid) and a min-heap for sell orders (to get the lowest ask). Explain that heaps allow O(log n) insertion and O(1) access to the best price.

3. Define matching logic

For each incoming order, check if it can match with the opposite heap: a buy matches if the min sell price ≤ buy price; a sell matches if the max buy price ≥ sell price. Execute trades, add prices to sum, and remove matched orders from the heap.

4. Handle ties and edge cases

Discuss tie-breaking: if multiple orders have the same price, use arrival time (FIFO) or any consistent rule. Consider edge cases like empty book, no match, and multiple matches (though unit-sized orders match at most one).

5. Analyze complexity and optimize

State time complexity: O(n log n) due to heap operations. Space complexity: O(n) for storing unmatched orders. Mention potential optimizations like using a balanced BST or skip list if needed, but heaps are sufficient.

Key Points to Mention

  • Use two heaps: max-heap for buy orders, min-heap for sell orders.
  • Matching condition: buy price ≥ min sell price, or sell price ≤ max buy price.
  • Time complexity: O(n log n) for n orders; space complexity: O(n).
  • Tie-breaking: price-time priority (FIFO) or any consistent rule; explain why it matters.
  • Edge cases: empty book, no match, multiple matches (not possible with unit size).
  • Return sum of executed trade prices; ensure to add the matched price (not the order's price).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.