Find the cumulative profit/loss after processing all trades.
[
{
"date": 1,
"type": "buy",
"price": 20,
"quantity": 10,
},
{
"date": 2,
"type": "buy",
"price": 40,
"quantity": 20,
},
{
"date": 3,
"type": "sell",
"price": 42,
"quantity": 7,
},
{
"date": 4,
"type": "buy",
"price": 40,
"quantity": 5,
}, {
"date": 5,
"type": "sell",
"price": 3,
"quantity": 20,
}]
Idea is pick the correct date for max profit and produce the end result. Its possible there could be more shares to sell.
Please suggest what kind of datastructure to chose, PriorityQueues, how to manage the quantity along with price as some dates couldn't have enough shares to chose.