Company: Project44 Sde backend_24march
Difficulty: medium
A trading system processes a sequence of events to track a firm's net profit or loss over time. Each event is one of the following: BUY stock quantity: buy the given number of shares of a stock at its current market price SELL stock quantity: sell the given number of shares of a stock at its current market price CHANGE stock price: update the market price of a stock by the given amount (positive or negative) QUERY: request the current net profit or loss since trading began Process the events in the order given and return a list of values produced by each QUERY event, in the same order. Example Suppose there are n = 7 events: events = ["BUY googl 20", "BUY aapl 50", "CHANGE googl 6", "QUERY", "SELL aapl 10", "CHANGE aapl -2", "QUERY"] Output: [120, 40] Explanation: Events Portfolio Profit so far BUY googl 20 googl 20 0 BUY aapl 50 googl 20 aapl 50 0 CHANGE googl 6 googl 20 aapl 50 120 QUERY 120 SELL aapl 10 googl 20 aapl 40 120 CHANGE aapl -2 googl 20 aapl 40 40 QUERY googl 20 aapl 40 4