As reported: Walmart Senior Software Engineer round 2, LLD (virtual, Bangalore, Oct 2025): LeetCode LFU Cache — the approach was discussed and then coded.
Implement LFUCache(capacity) with:
get(key)— the value if present (and count a use), else-1.put(key, value)— insert or update (counts a use). When inserting into a full cache, evict the key with the lowest use count; among ties, the least recently used one.
Both operations must run in O(1) average time.
This is LeetCode 460 — LFU Cache.
Example
["LFUCache","put","put","get","put","get","get","put","get","get","get"]
[[2],[1,1],[2,2],[1],[3,3],[2],[3],[4,4],[1],[3],[4]]
-> [null,null,null,1,null,-1,3,null,-1,3,4]
Constraints: 1 ≤ capacity ≤ 10^4; 0 ≤ key ≤ 10^5; 0 ≤ value ≤ 10^9; at most 2·10^5 calls.
Code runner format: two lines — the method names, then their arguments (LeetCode's format). Implement the LFUCache class; the harness prints the list of return values.