Build an in-memory key-value store that keeps historical values. A caller may ask for the value of a key as of a particular timestamp.
Question
## Scenario
Build an in-memory key-value store that keeps historical values. A caller may ask for the value of a key as of a particular timestamp.
## Interface
```python
class TimeMap:
def set(self, key: str, value: str, timestamp: float) -> None: ...
def get(self, key: str, timestamp: float) -> str: ...
```
## Requirements
- `set` records a version of `key` at `timestamp`.
- Timestamps for a key may arrive out of order.
- `get(key, timestamp)` returns the value associated with the greatest stored timestamp less than or equal to the requested time.
- Return `""` when the key has no qualifying version.
- If the same key and timestamp are written more than once, the most recent call replaces the earlier value.
- Keys are independent and timestamps are finite numbers.
- Aim for logarithmic lookup after the versions for a key have been ordered.
## Example
```text
set("status", "queued", 10)
set("status", "done", 30)
set("status", "running", 20)
get("status", 5) -> ""
get("status", 20) -> "running"
get("status", 25) -> "running"
get("status", 40) -> "done"
```
## Follow-ups
1. Optimize separately for monotonic writes and rare late-arriving writes.
2. Inject a clock for a convenience API that writes “now,” while keeping tests deterministic.
3. Make the store thread-safe and compare one global lock, per-key locks, and immutable snapshots.
4. Add retention, range scans, persistence, and crash recovery.
5. Explain how multiple writers should resolve equal or conflicting timestamps in a distributed deployment.The public brief is identical for people and crawlers. Account access changes tools, not the indexed description.