You are given a orders, where each orders[i] = [price_i, amount_i, orderType_i] represents an order placed:
If orderType_i is
If orderType_i is
A backlog stores orders that have not yet been executed. When a new order arrives, it is processed as follows:
If it is a buy order, check the backlog for a sell order with the lowest price that is less than or equal to the buy order’s price. If such an order exists, the two orders are matched, reducing the quantities of both orders by the minimum of their remaining amounts. This process repeats until the buy order is completely filled or no valid matching sell order remains in the backlog. Any remaining unmatched amount from the buy order is added to the backlog.
If it is a sell order, check the backlog for a buy order with the highest price that is greater than or equal to the sell order’s price. If such an order exists, the two orders are matched, reducing the quantities of both orders by the minimum of their remaining amounts. This process repeats until the sell order is completely filled or no valid matching buy order remains in the backlog. Any remaining unmatched amount from the sell order is added to the backlog.
Return the total amount of orders remaining in the backlog after all orders have been processed. Since the answer may be large, return it modulo
Constraints:
orders.length
orders[i].length
price_i, amount_i
orderType_i is either
You are given a orders, where each orders[i] = [price_i, amount_i, orderType_i] represents an order placed:
If orderType_i is
If orderType_i is
A backlog stores orders that have not yet been executed. When a new order arrives, it is processed as follows:
If it is a buy order, check the backlog for a sell order with the lowest price that is less than or equal to the buy order’s price. If such an order exists, the two orders are matched, reducing the quantities of both orders by the minimum of their remaining amounts. This process repeats until the buy order is completely filled or no valid matching sell order remains in the backlog. Any remaining unmatched amount from the buy order is added to the backlog.
If it is a sell order, check the backlog for a buy order with the highest price that is greater than or equal to the sell order’s price. If such an order exists, the two orders are matched, reducing the quantities of both orders by the minimum of their remaining amounts. This process repeats until the sell order is completely filled or no valid matching buy order remains in the backlog. Any remaining unmatched amount from the sell order is added to the backlog.
Return the total amount of orders remaining in the backlog after all orders have been processed. Since the answer may be large, return it modulo
Constraints:
orders.length
orders[i].length
price_i, amount_i
orderType_i is either