Fixed-Capacity Cache with Least-Used Eviction

Asked at Salesforce · Coding Questions · Difficulty: Hard · Last asked Jan 28, 2026

Design a cache with a fixed capacity. When the cache is full and a new key arrives, it discards the key that has been used the fewest times, and among equally used keys the one whose last use is oldest. Both lookups and inserts must stay fast as the cache grows.

Loading the problem…