We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
A medium design problem, graded against 6 test cases (3 of them hidden).
Build a working data structure to an API - LRU caches, rate limiters, and iterators.
Reach for it when you see: "Design a class supporting these operations in O(1)" - an API rather than a single function.
More Designproblems →Maintain a map from key to two parallel lists: sorted `times` and matching `values`. Because `set` timestamps for a key strictly increase, appends keep `times` sorted. For `get`, binary search for the rightmost timestamp `<= query` (an upper-bound search, then step back one). If that index is before the start, or the key is unknown, return the empty string.
The full reference solution in every supported language stays in the editor above - reveal it there once you have had a real attempt.
These apply to the pattern as a whole, not just this problem.