Audit Order Lifecycle Events Against an Exchange State Machine

Last updated: November 29, 2026

Quick Overview

Given a time-ordered log of order events (NEW, ACK, REJECT, PARTIAL, FILL, CANCEL_REQ, CANCELED, CANCEL_REJECT) with quantities, replay them through an order state machine and report final states, filled quantities and every invalid transition.

Akuna Capital
Coding & Algorithms
Software Engineer
Akuna Capital
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a time-ordered log of order events (NEW, ACK, REJECT, PARTIAL, FILL, CANCEL_REQ, CANCELED, CANCEL_REJECT) with quantities, replay them through an order state machine and report final states, filled quantities and every invalid transition.

Akuna Capital's trading systems must track each order's exact state so that position and risk numbers are right, and a fill that arrives after a cancel request is a classic real-world race. The interviewer checks that you encode states as a table instead of nested ifs and that you think about the cancel/fill race.

What the Interviewer Expects
  • Define states and allowed transitions explicitly as a table
  • Treat unknown order ids and terminal states correctly
  • Track size and filled quantity, flag overfills and wrong FILL events
  • Allow fills while a cancel is pending
  • Record violations without crashing the replay
Key Topics to Cover
state machines
simulation
hash maps
trading systems
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 add order replace (cancel/replace) with a new quantity?
  • If events can arrive out of order across two sessions, what changes?
  • How would you turn this into live position tracking?
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

Events are (order_id, event, qty). NEW carries the order size; PARTIAL and FILL carry fill quantity. An order goes PENDING_NEW to LIVE on ACK, then LIVE to FILLED, or to PENDING_CANCEL and then CANCEL...

High-Level Design

Store transitions as a dict state -> {event: next_state}, with None meaning the order is not yet known. Replay events in order. If the pair is not in the table, log a violation and leave the state u...


Submit Your Answer
Markdown supported