Back to problems

Implement LRU cache and prime products array

Object-Oriented Programming · Snapchat · Medium

Task 1 — LRU Cache The standard LRU cache must support get and put in $$O(1)$$ average time. The central challenge is tracking recency: after every read or write, the affected key becomes the most recently used item, and when the cache exceeds capacity, the least recently used item is evicted. A hash map alone gives fast key lookups but does not preserve ordering. A doubly linked list alone preserves ordering but makes lookup linear. Combining the two gives the best of both…

Checking your access…