Written by Anurag Goel
This article first appeared on AlgoSimplified. That URL is canonical. The full lesson has the complete Java class, follow-up sketches, exercises and a short quiz. This is a shorter cut of the same design. The problem A cache with fixed capacity. get(key) returns the value (or a miss) and marks the key as recently used. put(key, value) inserts or updates; if the cache is full, it evicts the least recently used key. Both operations must be O(1). A hash map gives O(1) lookup but no ...