You are given a list of trade transactions that represent a customer's trading activity. Each trade is provided as a list of strings in the format: ["timestamp", "symbol", "direction", "quantity", "price"]. The direction is either "B" for buy or "S" for sell. The trades are already ordered by their timestamps, and the customer starts with an initial cash balance of $1000.
Your task is to process the trades sequentially to build the customer's final portfolio. When processing:
- A buy (
"B") record reduces cash by (quantity × price) and adds the corresponding shares of the stock to the portfolio. - A sell (
"S") record increases cash by (quantity × price) and removes the shares sold from the portfolio. If the quantity is 0, remove that stock from the portfolio.
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
Output
Expected