PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Lead

Process a Mutable Stock-Price Log

Last updated: Jul 22, 2026

Quick Overview

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.

  • medium
  • Lead
  • Coding & Algorithms
  • Software Engineer

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.

Related Interview Questions

  • Process Calendar Events with Deletion, Pagination, and Overlap Queries - Lead (medium)
  • Solve friend recommendations and time-versioned maps - Lead (medium)
|Home/Coding & Algorithms/Lead

Process a Mutable Stock-Price Log

Lead logo
Lead
Jul 8, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
1
0

Process a Mutable Stock-Price Log

Build a small stock-price log and process a sequence of queries and updates.

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

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"]

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Lead•More Software Engineer•Lead Software Engineer•Lead Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 9,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.