Design time-based key-value store
Company: Navan
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Design an in-memory key-value store that supports time-based lookups.
## Operations
Implement a class (or module) with the following methods:
1. `set(key, value, timestamp)`
- Stores the string `value` for string `key` at integer `timestamp`.
- Multiple values may be stored for the same key at different timestamps.
2. `get(key, timestamp)`
- Returns the value associated with `key` for the **largest stored timestamp `t` such that `t <= timestamp`**.
- If there is no such timestamp for the key, return an empty string (or `null`, but be consistent).
## Notes / Constraints
- Timestamps for `set()` calls on the same key are non-decreasing.
- Aim for efficient `get()` queries.
- You may assume ASCII strings for keys/values.
## Example
- `set("room", "A", 10)`
- `set("room", "B", 20)`
- `get("room", 5) -> ""`
- `get("room", 10) -> "A"`
- `get("room", 15) -> "A"`
- `get("room", 20) -> "B"`
- `get("room", 25) -> "B"`
Quick Answer: This question evaluates competency in designing time-indexed in-memory key-value stores, including handling ordered timestamps and achieving efficient lookups through suitable data structures and algorithms.