Inventory Revenue Across Supply, Sell, and Return Logs
Problem statement
Process string operations:
[supply,item,count,price]adds units at a unit price.[sell,item,count]sells a guaranteed available quantity, consuming cheapest units first, and emits the consumed price total.[return,item,count,originalSalePrice,newPrice]restores returned units at newPrice; originalSalePrice identifies the prior sale lot and emits no output.
Return sell revenues in order.
Function
inventoryRevenue(operations: String[][]) → long[]Examples
Example 1
operations = [["supply","apple","2","5"],["supply","apple","1","3"],["sell","apple","2"],["return","apple","1","5","4"],["sell","apple","2"]]return = [8,9]The first sale consumes prices 3 and 5; the second consumes 4 and 5.
Example 2
operations = [["supply","x","1","7"],["sell","x","1"]]return = [7]The one supplied unit is sold.
Constraints
1 <= operations.length <= 100000- Counts and prices are positive integers.