Skip to content

Practice Number of Orders in the Backlog

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1801
LeetCode Problem

Number of Orders in the Backlog

Problem Statement

Process orders [price,amount,type] in input order; type 0 buys and type 1 sells. Each amount represents that many individual orders at the same price. A buy matches the lowest-priced waiting sell when that price is no greater than its own; a sell matches the highest-priced waiting buy when that price is no lower than its own. Remove matched units and keep unmatched units waiting. Return the remaining total units modulo 10^9 + 7.

Source: Number of Orders in the Backlog on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
orders = [[10,5,0],[15,2,1],[25,1,1],[30,4,0]]
Output
6

# Example 2

Input
orders = [[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]
Output
999999984

Constraints

1 <= orders.length <= 10^5
orders[i].length == 3
1 <= pricei, amounti <= 10^9
orderTypei is either 0 or 1.

Related LeetCode Problems

Practice more problems similar to Number of Orders in the Backlog.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.