FreeCareerPath
Build the PrimitiveMedium

LRU Cache

Implement `LRUCache(capacity)` with `get(key)` returning the value or `-1`, and `put(key, value)`. When the cache is full, evict the least recently used entry. Both operations must be O(1). Neither structure alone is enough: a map gives O(1) lookup but no ordering, a list gives ordering but O(n) lookup. Combine them — the map stores key to node, the doubly linked list holds recency order, and a `get` counts as a use.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "LRU Cache" are saved to your account — logging in takes a few seconds.

LRU Cache — FreeCareerPath