Problem Brief
Calculate Net Profit
OA
A quantitative trading firm aims to develop a tool to track the net profit/loss of the firm at any point in time. This tool processes a list of events, where each event falls into one of four categories:
quantity shares of stock at the market price.quantity shares of stock at the market price.stock by price amount, which can be positive or negative.The tool should return a list of numbers corresponding to each QUERY event.
Function Description
Complete the function calculateNetProfit in the editor.
calculateNetProfit has the following parameter:
String[] events: an array of strings describing the events
Returns
long[]: the answers to the "QUERY" events
My deepest, sincere, and boundless gratitude to an amazing friend for all their help. 🩵
1Example 1
Input
events = ["BUY googl 20", "BUY aapl 50", "CHANGE googl 6", "QUERY", "SELL aapl 10", "CHANGE aapl 2", "QUERY"]
Output
[0, 0]
Explanation
Hallo ~
Output is just placeholder, but the example input is complete~
As alwasy, will update more once come across more sources on the internet...
Constraints
Limits and guarantees your solution can rely on.
- 1 ≤ n ≤ 10^5
- | events[] | ≤ 21
- For query, SELL
stockquantity, it is guaranteed that there are enough shares owned. - 1 ≤ quantity ≤ 10^3
- The absolute value of a change in the price of any stock at any event will not exceed 10³.