LRU Cache
Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the LRUCache class with get(key) returning the value or -1 if not found, and put(key, value) to insert or update. When capacity is exceeded, evict the least recently used key.
LRU Cache

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the LRUCache class with get(key) returning the value or -1 if not found, and put(key, value) to insert or update. When capacity is exceeded, evict the least recently used key.

Example 1:
Input: {"commands":["LRUCache","put","put","get","put","get","put","get","get","get"],"values":[[2],[1,1],[2,2],[1],[3,3],[2],[4,4],[1],[3],[4]]}
Output: [null,null,null,1,null,-1,null,-1,3,4]
Input
arr ={"commands":["LRUCache","put","put","get","put","get","put","get","get","get"],"values":[[2],[1,1],[2,2],[1],[3,3],[2],[4,4],[1],[3],[4]]}

LRUCache()

Cache (LRU \u2190 \u2192 MRU) | Capacity: 2

Empty

Cache Map (0/2)

No entries

Initialize with capacity=2

Variables
VariableValue
capacity2
DepthFunction Call
Stack empty
0/10