You are asked to design a simple order management system for a trading platform.
Each order is associated with an orderId, an orderType ("buy" or "sell"), and a price.
An order is considered active unless it is canceled.
Implement the OrderManagementSystem class:
OrderManagementSystem(): Initializes the order management system.void addOrder(int orderId, string orderType, int price): Adds a new active order with the given attributes. It is guaranteed that orderId is unique.void modifyOrder(int orderId, int newPrice): Modifies the price of an existing order. It is guaranteed that the order exists and is active.void cancelOrder(int orderId): Cancels an existing order. It is guaranteed that the order exists and is active.vector<int> getOrdersAtPrice(string orderType, int price): Returns the orderIds of all active orders that match the given orderType and price. If no such orders exist, return an empty list.Note: The order of returned orderIds does not matter.
Example 1:
Input:
["OrderManagementSystem", "addOrder", "addOrder", "addOrder", "getOrdersAtPrice", "modifyOrder", "modifyOrder", "getOrdersAtPrice", "cancelOrder", "cancelOrder", "getOrdersAtPrice"]
[[], [1, "buy", 1], [2, "buy", 1], [3, "sell", 2], ["buy", 1], [1, 3], [2, 1], ["buy", 1], [3], [2], ["buy", 1]]
Output:
[null, null, null, null, [2, 1], null, null, [2], null, null, []]
Explanation
OrderManagementSystem orderManagementSystem = new OrderManagementSystem();[2, 1].[2].[].Constraints:
1 <= orderId <= 2000orderId is unique across all orders.orderType is either "buy" or "sell".1 <= price <= 109addOrder, modifyOrder, cancelOrder, and getOrdersAtPrice does not exceed 2000.modifyOrder and cancelOrder, the specified orderId is guaranteed to exist and be active.orderId so you can quickly modify or cancel them.(orderType, price) to efficiently answer queries.["OrderManagementSystem","addOrder","addOrder","addOrder","getOrdersAtPrice","modifyOrder","modifyOrder","getOrdersAtPrice","cancelOrder","cancelOrder","getOrdersAtPrice"] [[],[1,"buy",1],[2,"buy",1],[3,"sell",2],["buy",1],[1,3],[2,1],["buy",1],[3],[2],["buy",1]]