Quick Overview

This question evaluates a software engineering competency in modifying and extending a C++ client/server trading system, focusing on state management, input validation, API integration, and maintaining invariants for order lifecycle.

Implement Order Modification Feature

Company: Hudson River Trading

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

You are given an existing C++ trading system with a client/server architecture. The current system already supports two request types: - `AddOrder(order_id, symbol, side, price, quantity)` - `CancelOrder(order_id)` The server keeps all active orders in memory, keyed by `order_id`. Add support for a new request: - `ModifyOrder(order_id, new_price, new_quantity)` Requirements: 1. If the order does not exist or has already been canceled, the modification must be rejected. 2. `symbol` and `side` cannot be changed by a modify request. 3. A successful modification updates only `price` and `quantity` for the existing order. 4. `new_price` and `new_quantity` must both be positive; otherwise reject the request. 5. The order must remain associated with the same `order_id` after modification. 6. Integrate the new request into the existing client/server flow in the same style as the existing add/cancel functionality. Implement the feature and explain what parts of the codebase you would inspect or reuse before making changes.

Overview: This question evaluates a software engineering competency in modifying and extending a C++ client/server trading system, focusing on state management, input validation, API integration, and maintaining invariants for order lifecycle.

Read the full Hudson River Trading Software Engineer interview experience this question came from

Process add, cancel, modify, and snapshot operations for an in-memory order map. Return operation results and snapshots.

Constraints

  • Operations are lists whose first item is add, cancel, modify, or snapshot.
  • A successful modify only changes price and quantity.
  • Snapshots return active orders sorted by order_id.

Examples

Input: ([["add",1,"AAPL","B",100,10],["modify",1,101,8],["snapshot"]],)

Expected Output: ['accepted', 'accepted', [[1, 'AAPL', 'B', 101, 8]]]

Explanation: Modify updates price and quantity but preserves id, symbol, and side.

Input: ([["modify",9,10,1],["add",9,"MSFT","S",12,5],["cancel",9],["modify",9,13,4]],)

Expected Output: ['rejected', 'accepted', 'accepted', 'rejected']

Explanation: Missing and canceled orders reject modification.

Hints

  1. Keep active orders keyed by order_id.
  2. Reject modifications for missing/canceled orders or non-positive replacement values.

Loading coding console...