Design and implement an LFU cache (LeetCode 460); at least implement get() and explain the approach.
Asked in the R2 Coding/HLD stage. Only 25-30 minutes remained after a 30-minute HLD discussion of a past project's database design tradeoffs.
Implement lfu_cache(capacity, operations). Each operation is ['put', key, value] or ['get', key]. Return the values from all get operations, using -1 for missing keys. When full, evict the least frequently used key. If frequencies tie, evict the most recently used tied key.
def lfu_cache(capacity, operations):