Back to problems

Implement Cache and Count Components

Object-Oriented Programming · Amazon · Medium

Part 1: Implement an LRU Cache Hash Map + Doubly Linked List A cache must answer two different questions quickly: "does this key exist?" and "which key was used least recently?" Neither a hash map nor a linked list alone answers both. The hash map gives instant lookup by key, while the doubly linked list keeps the entries ordered by recency. The key insight is to store each hash-map value as a direct reference to its corresponding linked-list node. Then moving, updating, or…

Checking your access…