PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates data-structure design, command parsing, state-management, and error-handling competency for implementing an in-memory order management system, and is categorized under Coding & Algorithms with a practical application focus emphasizing efficient query support.

  • hard
  • Coinbase
  • Coding & Algorithms
  • Software Engineer

Implement a crypto order management system

Company: Coinbase

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

You are building an in-memory **crypto order management system**. You must parse commands from standard input and print outputs for query commands. ## Order model Each order has: - `orderId` (string, unique) - `symbol` (string, e.g., `BTC-USD`) - `side` (`BUY` or `SELL`) - `qty` (positive integer) - `state` ∈ `{LIVE, PAUSED, CANCELLED}` New orders start in state `LIVE`. ## Input A sequence of newline-separated commands. Your program should ignore blank lines. ### Commands - `CREATE <orderId> <symbol> <side> <qty>` - Creates a new order. If `orderId` already exists, treat it as an error (see **Errors**). - `PAUSE <orderId>` - If the order exists and is `LIVE`, change it to `PAUSED`. - `RESUME <orderId>` - If the order exists and is `PAUSED`, change it back to `LIVE`. - `CANCEL <orderId>` - If the order exists and is not already `CANCELLED`, change it to `CANCELLED`. - `GET <orderId>` - Print the current state as: `<orderId> <state>`. - `COUNT <state>` - Print how many orders are currently in that state as a single integer. ## Errors For invalid commands or invalid transitions (e.g., `RESUME` on a `LIVE` order, or referencing an unknown `orderId`), print: - `ERROR` (You may assume command tokens are space-separated.) ## Output Print one line per `GET` and `COUNT` command, and also one line (`ERROR`) for each command that errors. ## Constraints - Up to 200,000 commands. - `orderId` length ≤ 64. ## Notes Design your data structures so that `GET` and `COUNT` are efficient, and state transitions do not require scanning all orders.

Quick Answer: This question evaluates data-structure design, command parsing, state-management, and error-handling competency for implementing an in-memory order management system, and is categorized under Coding & Algorithms with a practical application focus emphasizing efficient query support.

You are given a list of newline-style command strings for an in-memory crypto order management system. Process the commands in order and return the lines that would be printed. Each order has: - orderId: unique string - symbol: string such as BTC-USD - side: BUY or SELL - qty: positive integer - state: one of LIVE, PAUSED, CANCELLED Rules: - New orders start in state LIVE. - Blank lines must be ignored. - Successful CREATE, PAUSE, RESUME, and CANCEL commands produce no output. - GET <orderId> outputs: "<orderId> <state>". - COUNT <state> outputs the number of orders currently in that state. - Any invalid command, malformed command, invalid side/state/qty, duplicate orderId, unknown orderId, or invalid state transition must output "ERROR". Valid commands: - CREATE <orderId> <symbol> <side> <qty> - PAUSE <orderId> only valid when the order is LIVE - RESUME <orderId> only valid when the order is PAUSED - CANCEL <orderId> only valid when the order exists and is not already CANCELLED - GET <orderId> - COUNT <state> Your goal is to design the processing so that GET and COUNT are efficient and state transitions do not scan all orders.

Constraints

  • 1 <= number of commands <= 200000
  • orderId length <= 64
  • qty must be a positive integer for CREATE
  • Average O(1) processing per command is expected

Examples

Input: (["CREATE ord1 BTC-USD BUY 5", "CREATE ord2 ETH-USD SELL 3", "GET ord1", "COUNT LIVE", "PAUSE ord1", "GET ord1", "COUNT PAUSED", "CANCEL ord2", "COUNT CANCELLED", "RESUME ord1", "GET ord1"],)

Expected Output: ["ord1 LIVE", "2", "ord1 PAUSED", "1", "1", "ord1 LIVE"]

Explanation: Two orders are created as LIVE. ord1 is paused and later resumed. ord2 is cancelled. GET and COUNT return the current states and totals.

Input: (["CREATE a BTC-USD BUY 10", "CREATE a BTC-USD BUY 1", "RESUME a", "PAUSE missing", "PAUSE a", "PAUSE a", "CANCEL a", "CANCEL a", "GET a", "COUNT LIVE"],)

Expected Output: ["ERROR", "ERROR", "ERROR", "ERROR", "ERROR", "a CANCELLED", "0"]

Explanation: This covers duplicate CREATE, invalid RESUME from LIVE, unknown orderId, invalid PAUSE on an already PAUSED order, and invalid CANCEL on an already CANCELLED order.

Input: (["", " ", "COUNT LIVE", "CREATE b BTC-USD HOLD 5", "CREATE c BTC-USD BUY 0", "CREATE d BTC-USD SELL x", "CREATE e BTC-USD SELL 2 extra", "COUNT BROKEN", "GET z"],)

Expected Output: ["0", "ERROR", "ERROR", "ERROR", "ERROR", "ERROR", "ERROR"]

Explanation: Blank lines are ignored. The remaining commands test invalid side, non-positive qty, non-integer qty, malformed CREATE, invalid COUNT state, and GET on an unknown order.

Input: (["CREATE x BTC-USD BUY 1", "CREATE y ETH-USD SELL 2", "CREATE z SOL-USD BUY 3", "PAUSE x", "PAUSE z", "COUNT LIVE", "COUNT PAUSED", "CANCEL x", "COUNT PAUSED", "COUNT CANCELLED", "RESUME z", "COUNT LIVE", "GET x"],)

Expected Output: ["1", "2", "1", "1", "2", "x CANCELLED"]

Explanation: The counts change as x and z move between LIVE, PAUSED, and CANCELLED. The final GET confirms that x remains CANCELLED.

Input: ([],)

Expected Output: []

Explanation: No commands produce no output.

Hints

  1. Use a hash map from orderId to its current state so GET and state transitions are constant time on average.
  2. Maintain running counts for LIVE, PAUSED, and CANCELLED; update the counts whenever an order changes state.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement a Coin-Constrained Jump Strategy - Coinbase (hard)
  • Implement an In-Memory Database - Coinbase (hard)
  • Implement Game Physics and Block Mining - Coinbase (hard)
  • Compute Total Manual Distance - Coinbase (medium)
  • Implement a Flappy Bird Jump Agent - Coinbase