Back to Google
Coding rounds
Google coding rounds
5 timed coding challenges drawn from real loops. Submit a solution to see your test pass rate and AI feedback.
←All coding rounds
faang 50:00+160 XP
LRU Cache
Design a data structure for a Least Recently Used (LRU) cache with capacity `k`. Implement `get(key)` and `put(key, value)` in O(1) average time. When capacity is exceeded, evict the least recently used key. A JS `Map` preserves insertion order, which you can exploit for recency.
Examples
key 2 evicted by put(3,3)
in: cap=2; put(1,1); put(2,2); get(1); put(3,3); get(2)
out: 1 then -1
javascript
Loading editor...