BackmediumHashing Uber Razorpay

Insert Delete Random Fast Solution

Problem Statement

A stock portfolio manager performs add/remove operations on a list of stock prices. After all operations, find the total portfolio value. Operations: '1 val' = buy stock at price val, '2 val' = sell stock at price val.

Example 1
Input
4 1 500 1 750 2 500 1 200
Output
950

Explanation: Buy 500, buy 750, sell 500, buy 200. Total=750+200=950.

Constraints

  • 1 <= ops <= 10^5
  • -10^9 <= val <= 10^9
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free