Deviopath › JavaScript

LRU Cache

Hard · Data Structures

Finish the LRUCache class. It stores at most capacity key/value pairs.

- get(key) returns the value, or -1 if the key is missing. Reading a key makes it the most recently used.

- put(key, value) adds or updates a key and makes it the most recently used. If the cache is now over capacity, remove the least recently used key.

The function runLRU is already written: it replays a list of operations and returns null for every put and the result for every get.

Next: Event Emitter