As reported: Goldman Sachs Superday rounds (2025–2026), one of the most repeated questions: LeetCode 146 in a DSA round with two Associates; "design an LRU cache" in another Associate Superday DSA round, followed by a short discussion of cache trade-offs; as the system design round of an Analyst loop (with resume questions); as an LLD of an LRU cache plus HLD questions — optimising DB writes, replication, archival, scaling, indexing (Associate, 2025); and in a design round of an Analyst loop (2025).
Design a cache with a fixed capacity: get(key) returns the value or -1; put(key, value) inserts or updates and, when the cache is over capacity, evicts the least recently used key. Both must run in O(1) average time.
This is LeetCode 146 — LRU Cache.
Example 1
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]]
-> [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: LeetCode's design format: the first line lists the calls (starting with the constructor LRUCache), the second line their arguments; implement the class LRUCache; the harness prints one JSON array with each call's result (null for calls that return nothing).