← Two Sigma Interview Insights

Two Sigma·Software Engineer·Technical Phone Screen·Intermediate

IntermediateRejected
Apr 2026

Summary

Two Sigma SWE coding round. One problem, 30 minutes, and I did not finish. The question looked like a data structures exercise on the surface but the implementation details pile up fast and I ran out of time.

Questions Asked (1)

Q1

Design and implement a simplified order matching engine that processes buy and sell orders, matching them by price-time priority and outputting fill results or the current order book state.

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

I knew the general idea going in: max heap for buys, min heap for sells, match when best bid crosses best ask.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: order types, matching rules, output format, and performance constraints. Then outline a design using a price-time priority order book (e.g., two heaps or sorted maps) and walk through the matching logic. Finally, discuss implementation details, edge cases, and trade-offs.

Pro tip: Emphasize the importance of data structure choice for achieving O(log n) insertion and O(1) best price retrieval, and mention how you would handle partial fills and order cancellation.

1. Clarify Requirements

Ask about order types (limit/market), matching rules (price-time priority), output format (fills or order book), and any performance constraints.

2. Design Data Structures

Propose using two priority queues (max-heap for bids, min-heap for asks) or balanced BSTs to maintain price-time priority efficiently.

3. Outline Matching Algorithm

Describe the step-by-step process: when a new order arrives, match against opposite side while prices cross, generating fills and updating quantities.

4. Discuss Implementation Details

Cover handling partial fills, order cancellation, and outputting the order book state. Mention time complexity for operations.

5. Address Edge Cases and Trade-offs

Talk about edge cases like self-trading, market orders, and discuss trade-offs between different data structures (e.g., heaps vs. sorted lists).

Key Points to Mention

  • Price-time priority: orders matched first by best price, then by earliest time.
  • Data structures: heaps for efficient best price retrieval, or balanced BSTs for ordered iteration.
  • Partial fills: an order can be partially executed, requiring quantity updates.
  • Order cancellation: need efficient removal from data structure (e.g., lazy deletion with heaps).
  • Output format: either list of fills or current order book snapshot.
  • Time complexity: O(log n) for insertion and cancellation, O(1) for best price, O(n) for output.

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