All puzzles › LRU Cache
LRU Cache Practice Problems
5 puzzles (2 easy, 3 medium), in Python, JavaScript and C++.
Never compile the same C++ twice. Content-hash keys, least-recently-used eviction, and the two bugs this cache actually shipped with before they were caught.
The puzzles, easiest first
- Recently Used (Easy): Given the cache's keys in order of use, oldest first, and a key that was just used, return the new order.
- What Falls Off the End (Easy): Given the cache's keys in order of use, oldest first, and how many it can hold, return the keys that have to go, oldest first.
- Old Is Not the Same as Unused (Medium): Given when each entry was built, when it was last used, and how many can be kept, return the positions to evict, lowest first.
- The Same Thing Twice (Medium): Given a list of build inputs like the source and the compiler flags, return one 32-bit cache key.
- Was It Worth It? (Medium): Given a list of lookups and a cache size, count how many lookups were hits.
Practice another pattern
Or browse by subject
Browse all 676 puzzles