Number of Orders in the Backlog
Medium · Heap & Priority Queue · about 25 minutes
Asked at Robinhood, Amazon, Google, Coinbase, Citadel, Plaid, Ramp, Chime, SoFi, Revolut, Brex, Mercury, Kraken.
orders[i] = [price, amount, orderType] arrive in order; orderType 0 is a buy and 1 is a sell. A buy matches the cheapest sell with price ≤ its price; a sell matches the most expensive buy with price ≥ its price. Matches execute as many units as possible; unmatched units go into the backlog. Return the total number of units left in the backlog modulo 10⁹ + 7.