Skip to content
GeeksSmith

Implement LRU (Least Recently Used) Cache

Problem Statement

Design and implement a data structure for Least Recently Used (LRU) Cache supporting `get(key)` and `put(key, value)` in O(1) time complexity.

Target Complexity

Time:

O(1) for both get() and put()

Space:

O(capacity) memory allocation

Interview Talking Points:
  • Explain how JavaScript `Map` preserves insertion order, allowing clean O(1) eviction via `map.keys().next().value`.
  • Explain the traditional Doubly Linked List + HashMap implementation required in language-agnostic interviews.
Solution Editor (JavaScript)
Ready to run
Test Results
Evicts least recently used item when capacity is exceeded
Test #1