Object-Oriented Programming · Microsoft · Medium
Part 1 — LRU Cache with a Hash Map and a Doubly Linked List Two O(1) requirements pull in opposite directions: get needs instant lookup by key, while eviction needs to know which key has gone untouched the longest. A single structure cannot do both, so we combine two: a hash map from key to node, and a doubly linked list that keeps every live key in recency order. The map answers "where is this key?", the list answers "who is the coldest?". The crucial trick is that touching…
Checking your access…