Log inBook a Demo
BuildMidBackendAuto-graded

Fix a cache that evicts recently used keys

The bug produces no error and only makes things quietly slower, so it has to be noticed before it is fixed.LRUCache(capacity) should evict the least recently used entry when it overflows. It evicts the oldest inserted key instead — plain FIFO — and a get() does not count as a use, so reads never protect a hot key. The result is a cache that discards precisely the entries you are still using. Make eviction true LRU, with reads refreshing recency, and build it yourself rather than wrapping the standard library's decorator.
35 min
python

You're done when

  • Eviction removes the least recently used entry, not the oldest inserted one.
  • A get counts as a use and refreshes that key's recency.
  • The cache reproduces the expected results across the reference access sequence.

What it measures

Data structures and algorithmsCombining a map with an ordering structure so lookup, update and eviction all stay constant time.
Object-oriented programmingKeeping two internal structures consistent behind a small public interface, on every path.
Distinguishing similar behavioursSeeing exactly where LRU and FIFO diverge, which is the read that should have saved a key from eviction.

Your environment

Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards

Start this lab

35 min
Start labYou'll sign in to Anthropos to start. The lab opens in a private cloud workspace with Claude Code ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo