Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

operations =
arguments =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Use a hash map for O(1) lookup and a doubly-linked list to track recency.

Approach

  • Hash map: key -> node.
  • Doubly-linked list: most-recent at the right, least-recent at the left. On get/put, move the node to most-recent position. On capacity overflow, evict from the left.

Why it works

The list maintains exact LRU order; the map provides O(1) access to nodes.

Code
Loading...
Complexity
Time: O(1) per operation
Space: O(capacity)
Solution
Updated: 2026-02-23

Idea

Use a hash map for O(1) lookup and a doubly-linked list to track recency.

Approach

  • Hash map: key -> node.
  • Doubly-linked list: most-recent at the right, least-recent at the left. On get/put, move the node to most-recent position. On capacity overflow, evict from the left.

Why it works

The list maintains exact LRU order; the map provides O(1) access to nodes.

Code
Loading...
Complexity
Time: O(1) per operation
Space: O(capacity)