As reported: Qualcomm Engineer (C++), technical round 2 (2025): a twisted version of LRU Cache — explain the logic, write pseudo-code, then follow-up questions on each part.
Design LRUCache:
LRUCache(capacity)— a cache holding at mostcapacitykeys.get(key)— the value if present (and mark the key most recently used), else-1.put(key, value)— insert or update the key as most recently used; if the size exceedscapacity, evict the least recently used key.
Both operations in O(1) average time.
This is LeetCode 146 — LRU Cache.
Example
["LRUCache","put","put","get","put","get","put","get","get","get"]
[[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: two lines — the operation names, then their arguments (LeetCode's design-problem format). The harness prints the list of results.