Generic LRU Cache
Medium · Data Structures
Implement the generic class LRUCache<K, V> (least recently used cache) with a fixed capacity (always at least 1).
- get(key) returns the value or undefined. A successful get marks the key as most recently used.
- put(key, value) inserts or updates the key and marks it as most recently used. If a NEW key is added while the cache is full, first remove the least recently used key.
- keys() returns all keys ordered from least recently used to most recently used.
The driver runLRU(capacity, ops) is already written. It returns null for put, the value (or null) for get, and the key list for keys.
Next: Singly Linked List