Deviopath › Go

LRU Cache

Hard · Data Structures

An LRU cache of capacity cap stores at most cap keys. Get returns the value or -1 and marks the key as recently used. Put inserts or updates; if the cache is full, evict the least recently used key.

Write Get and Put on LRU. RunLRU(cap, ops) is already written. Each op is ["get", key] or ["put", key, value]. It returns every get result.

Next: Prefix Trie