As reported: Arista Networks SDE-2 round 1 (2025), coding question: LeetCode 981.
This is LeetCode 981 — Time Based Key-Value Store.
Implement TimeMap:
TimeMap()— an empty store.set(key, value, timestamp)— storesvalueforkeyattimestamp.get(key, timestamp)— returns the value set forkeywith the largest timestamp ≤timestamp, or""if there is none.
Example
["TimeMap","set","get","get","set","get","get"]
[[],["foo","bar",1],["foo",1],["foo",3],["foo","bar2",4],["foo",4],["foo",5]]
-> [null,null,"bar","bar",null,"bar2","bar2"]
Constraints: 1 ≤ key.length, value.length ≤ 100 (lowercase letters and digits); 1 ≤ timestamp ≤ 10^7; the timestamps of set calls are strictly increasing; at most 2·10^5 calls.
Code runner format: LeetCode's design format — line 1 the method names, line 2 their arguments. Implement the TimeMap class; the harness prints the list of results.