← 返回 atlassian 的题目列表Commodity Price Checkpoints
类型:qbank
Maintain commodity or stock prices keyed by timestamp, return the current maximum, then add checkpointed historical reads. The follow-up assigns checkpoint IDs on update and asks for the price effective at or before a requested checkpoint.
Requirements
Base operations:
upsertCommodityPrice(timestamp, price)
getMaxCommodityPrice()
If a timestamp already exists, update its price; otherwise insert it.
getMaxCommodityPrice() returns the maximum current price across all timestamps.
Follow-up operations:
upsertCommodityPrice(timestamp, price) -> checkpointId
getCommodityPrice(timestamp, checkpoint) -> price
Each update assigns a new checkpoint ID.
Historical reads return the value from the most recent checkpoint less than or equal to the requested checkpoint for that timestamp.
Notes
Candidates identify the base prompt as the same family as LC 2034 when confirmed in the source material.
Lazy heap invalidation handles current max/min cleanly; checkpoint reads need per-timestamp version histories or a snapshot/MVCC-style structure.
Preparation
Implement current max with hash maps plus heaps, including timestamp updates.
Add per-key sorted checkpoint histories and write tests for querying before the first update, exactly at a checkpoint, and between checkpoints.