hardJS ES6+#142

LRU cache with Map

Prompt

Implement class LRUCache(capacity):

  1. get(key) → value, or -1 if missing; a hit makes the key most-recently-used
  2. put(key, value) → inserts/updates; over capacity evicts the least-recently-used entry
  3. Both operations O(1)

Hint: a JS Map remembers insertion order — that's the whole trick.

Hints

Solution

Your Code

20 min

Tests

Click Run to test your code