FastPrepOrder Matching Engine
Problems/Order Matching Engine

Order Matching Engine

Jane Street logoJane Street● MediumNEW GRADFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in three Jane Street trading desk operations interview reports posted from 2021 to 2026. A graduate candidate had an order-book trade matching question in a final round, along with drawing how a trade flows through the firm. Another candidate was asked to build a matching engine, in VBA, at an unstated stage. A third graduate candidate described an in-person paired pseudo-code exercise on order-book content. None of the reports gave the order types, the input format or the expected output.

We chose limit orders only, price-time priority, trades at the resting price, the order layout, the fill format, the limits and all examples. The reports did not describe cancels or other order types, so we left them out.

Our version is about 75% the same as the reported question.

An exchange keeps an order book of buy and sell orders for one stock. Orders arrive one at a time. Each order is orders[i] = [orderId, side, price, quantity], where side is 0 for a buy and 1 for a sell. Orders arrive in the order they appear in orders.

When an order arrives, it trades against orders already resting in the book, using price-time priority:

  • A buy can trade with resting sells whose price is at most its own price. It takes the lowest-priced sell first.
  • A sell can trade with resting buys whose price is at least its own price. It takes the highest-priced buy first.
  • Among resting orders with the same price, the one that arrived earlier trades first.
  • Each trade is at the resting order's price, for the smaller of the two remaining quantities.
  • The incoming order keeps trading until it is fully filled or nothing it can trade with is left. Any quantity left over then rests in the book.

Record each trade as a fill [buyOrderId, sellOrderId, price, quantity]. Return all fills in the order they happen.

Function

matchOrders(orders: int[][]) → int[][]

Examples

Example 1

orders = [[1,1,101,5],[2,1,100,3],[3,0,99,4],[4,0,101,6]]return = [[4,2,100,3],[4,1,101,3]]

Orders 1 and 2 are sells, and they rest in the book. Order 3 buys at 99, but the cheapest sell is 100, so it rests too. Order 4 buys 6 at up to 101. It first takes all 3 from order 2 at 100, the cheapest sell, then 3 from order 1 at 101. Order 1 keeps 2 in the book.

Example 2

orders = [[10,0,50,2],[11,0,50,2],[12,1,50,3]]return = [[10,12,50,2],[11,12,50,1]]

Buys 10 and 11 have the same price, and order 10 arrived first, so the sell fills it first: 2 units. The last unit goes to order 11.

Example 3

orders = [[5,0,30,4],[6,0,32,1],[7,1,29,3]]return = [[6,7,32,1],[5,7,30,2]]

The sell of 3 at 29 first meets the highest buy, order 6 at 32, and trades 1 unit at 32, the resting price. It then trades 2 units with order 5 at 30. Order 5 keeps 2 in the book.

Example 4

orders = [[1,0,10,1],[2,1,11,1]]return = []

The buy at 10 is below the sell at 11, so the orders never cross and there are no fills.

Constraints

  • 1 <= orders.length <= 5000
  • orders[i].length == 4
  • 1 <= orderId <= 109, and all orderId values are different.
  • side is 0 or 1.
  • 1 <= price, quantity <= 106

More Jane Street interview questions

  • Code Editor FoldingONSITE INTERVIEW · Seen Oct 2026
  • Exact-Sixty Dice Game ValueONSITE INTERVIEW · Seen Oct 2026
  • Expected Value of Modified DiceONSITE INTERVIEW · Seen Oct 2026
  • Spaceship Equipment LoadoutONSITE INTERVIEW · Seen Oct 2026
  • Two-Tower Strategy GameONSITE INTERVIEW · Seen Oct 2026
  • Wizard Scroll Allocation StrategyONSITE INTERVIEW · Seen Oct 2026
  • Sort TradesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Order Book Data ValidationONSITE INTERVIEW · Seen Nov 2025
  • Biggest Daily Move and Longest Rising StreakOA · ONSITE INTERVIEW · Seen Apr 2021
  • Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
  • Delayed Job SchedulerWalmart Labs · ONSITE INTERVIEW
  • Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
  • Notification Deduplication WindowGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Implement a Min-Priority QueueAmazon · ONSITE INTERVIEW
  • Helpdesk Ticket ProcessingThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Execute Tasks by PrioritySnowflake · ONSITE INTERVIEWSnowflake interview questions
  • Priority Job Scheduler with CooldownsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Trip Booking with the Earliest Free DriverRippling · ONSITE INTERVIEWRippling interview questions
  • Reusable Number AllocatorDropbox · ONSITE INTERVIEWDropbox interview questions

Interview reports that mention this question

  • Jane Street TDOE UK Coding Round: 15 Experiences (Part 3 of 10)
  • Jane Street TDOE Interviews: 165 Experiences (Part 1 of 10)
  • Jane Street TDOE New Grad Interview Questions: 11 Experiences

Jane Street interview experiences

  • Jane Street TDO UK and Hong Kong: 22 Experiences (Part 10 of 10)
  • Jane Street TDOE US Final Round: 11 Experiences (Part 5 of 10)
  • Jane Street TDO Phone Math Round: 26 Experiences (Part 9 of 10)
All Jane Street interview questionsSee Jane Street hiring insights
Saved
class Solution {
    public int[][] matchOrders(int[][] orders) {
      // Write your code here.
    }
}
Checking account…