As reported: D. E. Shaw Lead screening on a HackerRank code pair (2026), after Java questions: an LRU cache, coded in the round, and a distributed cache.
This is LeetCode 146 — LRU Cache. Our write-up: /lru-cache.
Implement LRUCache:
LRUCache(capacity)— a cache holding at mostcapacitykeys.get(key)— the value ofkey, or-1if absent. Counts as a use.put(key, value)— insert or updatekey. If this exceeds the capacity, evict the least recently used key.
Both operations must run in O(1) average time.
Example
ops = ["LRUCache","put","put","get","put","get","put","get","get","get"]
args = [[2],[1,1],[2,2],[1],[3,3],[2],[4,4],[1],[3],[4]]
Output: [null,null,null,1,null,-1,null,-1,3,4]
Constraints: 1 ≤ capacity ≤ 3000; 0 ≤ key ≤ 10^4; 0 ≤ value ≤ 10^5; at most 2 · 10^5 calls.
Code runner format: one JSON value per line: ops, then args, as on LeetCode.
Follow-ups
- How would you turn this into a distributed cache?