Process a Mutable Stock-Price Log
Company: Lead
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
# Process a Mutable Stock-Price Log
Build a small stock-price log and process a sequence of queries and updates.
```python
def process_stock_log(
initial_prices: list[list[str]],
operations: list[list[str]],
) -> list[str]:
...
```
Each initial record is `[ticker, date, price]`, where `price` is a positive integer encoded as a string. Initial `(ticker, date)` pairs are unique. Operations have these forms:
- `["GET", ticker, date]`: output the price, adding `" (updated)"` if that existing record has ever been changed by `UPDATE`; output `"NONE"` if it is missing.
- `["UPDATE", ticker, date, price]`: replace an existing price or create a new record. A newly created record is not marked updated; replacing an existing record marks it updated.
- `["CHANGE", ticker, start_date, end_date]`: output the percentage change from the start price to the end price as a sign followed by two decimals and `%`, such as `+25.00%` or `-12.50%`. Output `"NONE"` if either record is missing.
- `["COMPARE", ticker1, ticker2, start_date, end_date]`: compute `CHANGE` for both tickers and output the two results joined by `" | "` in ticker order.
Dates are opaque strings: equality, not calendar arithmetic, is required. Return outputs from `GET`, `CHANGE`, and `COMPARE` in encounter order.
## Constraints
- At most `200_000` initial records and operations in total.
- Prices fit in a signed 64-bit integer and are always greater than zero.
- Ticker and date strings are non-empty ASCII strings.
## Example
```text
Input:
initial_prices = [["ACME", "2026-01-01", "100"], ["ACME", "2026-02-01", "125"]]
operations = [
["GET", "ACME", "2026-01-01"],
["CHANGE", "ACME", "2026-01-01", "2026-02-01"],
["UPDATE", "ACME", "2026-01-01", "110"],
["GET", "ACME", "2026-01-01"],
["GET", "OTHER", "2026-01-01"]
]
Output: ["100", "+25.00%", "110 (updated)", "NONE"]
```
Quick Answer: Process a mutable stock-price log with lookups, updates, percentage-change queries, and pairwise ticker comparisons. The problem tests correct state changes, update provenance, missing records, exact percentage formatting, large operation streams, and clear treatment of dates as opaque identifiers.