Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Recent Cache

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Evict the least recently used key: The Recent Cache.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when LRU cache design matches the clues
  2. 2Keep this true after every move: the order runs from least recently used to most recently used
  3. 3Reach the result within O(1) average per operation

Rules and pressure

  • Target cost: O(1) average per operation
  • State rule: the order runs from least recently used to most recently used

New words in this mission

Open a term for a plain-language explanation.
cache+

A fast copy of frequently needed data. It reduces repeated work, but the system must decide how stale that copy may become.

Lesson 1 of 3

Live algorithm trace

LRU cache design

Complete execution
1 of 5
0
put 1
op
1
put 2
2
get 1
3
put 3
4
get 2

Insert key 1 as the newest entry.

1map key to value and order node
2on get, move key to newest
3on put, update or append newest
4if size exceeds capacity
5evict the oldest key
6return recorded gets
order = 1
Truth to preserve / Cost target
Truth to preserve

the order runs from least recently used to most recently used

Cost target

O(1) average per operation

A hash map finds keys, while recency order identifies the eviction victim. Reading or writing a key moves it to the most-recent end.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead