1801. Number of Orders in the Backlog
https://leetcode.com/problems/number-of-orders-in-the-backlog
Description
You are given a 2D integer array orders, where each orders[i] = [pricei, amounti, orderTypei] denotes that amountiorders have been placed of type orderTypei at the price pricei. The orderTypei is:
0if it is a batch ofbuyorders, or1if it is a batch ofsellorders.
Note that orders[i] represents a batch of amounti independent orders with the same price and order type. All orders represented by orders[i] will be placed before all orders represented by orders[i+1] for all valid i.
There is a backlog that consists of orders that have not been executed. The backlog is initially empty. When an order is placed, the following happens:
If the order is a
buyorder, you look at thesellorder with the smallest price in the backlog. If thatsellorder's price is smaller than or equal to the currentbuyorder's price, they will match and be executed, and thatsellorder will be removed from the backlog. Else, thebuyorder is added to the backlog.Vice versa, if the order is a
sellorder, you look at thebuyorder with the largest price in the backlog. If thatbuyorder's price is larger than or equal to the currentsellorder's price, they will match and be executed, and thatbuyorder will be removed from the backlog. Else, thesellorder is added to the backlog.
Return the total amount of orders in the backlog after placing all the orders from the input. Since this number can be large, return it modulo 109 + 7.
Example 1:

Example 2:

Constraints:
1 <= orders.length <= 105orders[i].length == 31 <= pricei, amounti <= 109orderTypeiis either0or1.
ac
Last updated
Was this helpful?