Optiver logo

Optiver Hard Interview Questions

5 hard-level practice questions for Optiver technical interviews

Optiver software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Hard Verified Question #1

1. Capital Gains Tax Calculator


Category: String coding problem
You are given a chronologically sorted list of stock transactions. Each transaction is a list of strings in the format `[<timestamp>, <type>,...
Input: Array of strings
Output: Computed result
Want to practise this one?
Create a free account to open the full question and practise Optiver questions with AI.
Sign up free
coding Hard Verified Question #2

2. Plane Cargo Allocator


Category: Algorithm coding problem
A shipping terminal receives orders and must route cargo to available docks. Each dock has a fixed dispatch time and a remaining load capacity. An...
Input: List
Output: Computed result
coding Hard Verified Question #3

3. [CodeSignal] Fibonacci Storage System


Category: Graph coding problem
A research facility stores artifacts in underground vaults. Each vault has multiple tiers, indexed from 0 (deepest) upward. The capacity of each tier...
Input: Graph (nodes and edges)
Output: Computed result
coding Hard Verified Question #4

4. [CodeSignal] Fixed Price Purchase Optimizer


Category: Algorithm coding problem
A procurement team must purchase n identical components one at a time. For each component, the quoted market price is drawn independently and...
Input: Given input
Output: Integer
coding Hard heap #1

1. [Heap] — Schedule trading messages without violating per-session ordering


Background
Optiver's trading infrastructure must coordinate outbound exchange messages while preserving ordering within each exchange session. This exercise models a deterministic scheduler that balances message urgency and release times without allowing a later message to overtake an earlier message in the same session.
Problem statement
Implement a single-threaded MessageScheduler. Each message has a globally unique identifier, a session identifier, a release timestamp, and an integer priority.
Messages within a session form a FIFO queue in enqueue order. Only the first non-cancelled, undispatched message in each session may compete for dispatch. Consequently, a message whose release time has passed can still be blocked by an earlier message in its session.
The scheduler's clock initially equals 0. Calling dispatch(now, limit) sets its clock to now; dispatch timestamps must be nondecreasing. Enqueueing and cancellation do not advance the clock.
For each slot in a dispatch call:
  • Consider the head message of every nonempty session whose release_time <= now.

  • Choose the message with the highest priority.

  • Break priority ties by earlier release time, then by earlier global enqueue order.

  • Remove and return the chosen message. Its session's next message immediately becomes the head and can compete for the next slot in the same call.


Stop after returning limit messages or when no session head is eligible. Dispatch does not advance time beyond now, and there is no service duration.
Cancellation removes a pending message logically. If it was a session head, the next non-cancelled message immediately becomes the head. Cancelling an unknown, already-cancelled, or already-dispatched identifier returns false.
Support up to 200,000 operations efficiently. Do not scan every session on each dispatch or search linearly through a session to cancel a message.
Function or class signature
  • MessageScheduler() — initialize an empty scheduler.

  • enqueue(message_id: str, session_id: str, release_time: int, priority: int) -> None

  • cancel(message_id: str) -> bool

  • dispatch(now: int, limit: int) -> list[str]


Example 1:
Input, on a fresh scheduler:
[
  ["enqueue", "A1", "alpha", 10, 1],
  ["enqueue", "A2", "alpha", 0, 100],
  ["enqueue", "B1", "beta", 0, 5],
  ["dispatch", 0, 10],
  ["dispatch", 9, 10],
  ["dispatch", 10, 1],
  ["dispatch", 10, 10]
]
Output, one result per operation:
[null, null, null, ["B1"], [], ["A1"], ["A2"]]
Explanation: At time 0, A2 is blocked by A1, despite having priority 100 and release time 0. Only B1 can run. At time 9, A1 is still unreleased. The first call at time 10 dispatches A1 and reaches its limit; the next call dispatches A2.
Example 2:
Input, on a fresh scheduler:
[
  ["enqueue", "X1", "x", 20, 9],
  ["enqueue", "X2", "x", 5, 4],
  ["enqueue", "Y1", "y", 5, 4],
  ["enqueue", "Z1", "z", 3, 4],
  ["cancel", "X1"],
  ["dispatch", 5, 2],
  ["cancel", "X1"],
  ["dispatch", 5, 2]
]
Output, one result per operation:
[null, null, null, null, true, ["Z1", "X2"], false, ["Y1"]]
Explanation: Cancelling X1 exposes X2. At time 5, the three session heads all have priority 4. Z1 wins first because its release time is 3; X2 wins next because it was enqueued before Y1, and both have release time 5. A second cancellation of X1 returns false.
Constraints:
  • At most 200,000 total method calls and at most 200,000 enqueued messages.

  • Message and session identifiers are nonempty strings of at most 32 ASCII characters.

  • Message identifiers are unique across the entire lifetime of a scheduler, including after cancellation or dispatch.

  • 0 <= release_time, now <= 10^18; -10^9 <= priority <= 10^9.

  • 0 <= limit <= 200,000; successive dispatch timestamps are nondecreasing.

  • Release times need not increase within a session, and a newly enqueued message may already be released.

  • All calls are single-threaded. Inputs satisfy the stated constraints.


Follow-up:
The scheduler runs indefinitely, but only P messages are pending at any moment. How would you guarantee O(P + 1) retained space after every operation, while preserving efficient cancellation and dispatch even when cancelled messages have release times far in the future?
Want to practise this one?
Create a free account to open the full question and practise Optiver questions with AI.
Sign up free

Start practicing Optiver questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free