Implement Stock Price Query APIs
Lead BankSoftware Engineer · Technical ScreenLast updated
This question evaluates skills in time-series data modeling, API and data-structure design, transactional (atomic) batch updates, concurrency control, and date/time parsing for stock price records.
You are given an initial collection of stock price records. Each record contains:
symbol: a stock name or ticker stringtimestamp: initially a calendar date at daily granularityprice: a decimal price
Design and implement an in-memory StockPriceStore. You may define the exact function signatures and return types, but the behavior must be clear and testable.
Support the following operations:
get_price(symbol, date): return the price of the given stock on the given date, or an appropriate missing-value result if no price exists.get_change(symbol, start_date, end_date): return the price change for the given stock between two dates. Use a custom formula supplied by the interviewer, for exampleformula(start_price, end_price). Handle cases where either price is missing or the formula cannot be applied.update_prices(symbol, start_date, end_date, new_prices): update the prices for the given stock over an inclusive date range and return whether the update succeeded. If any price in that range for that stock has already been updated before, the entire update should fail. The update should be atomic: either all requested prices are updated, or none are.- The timestamp granularity changes from daily to hourly. Add an operation
get_hourly_prices(symbol, day)that returns all hourly prices for the given stock within that calendar day, ordered by time.
Clarify and handle edge cases, including duplicate initial records, missing symbols, missing dates, invalid date ranges, repeated updates, partial update failures, and date/time parsing. Write representative test cases for your implementation.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.