dsa2 min read
LFU Cache — HashMap + Frequency Buckets + DLL
Implement an LFU cache with O(1) get/put using three hash maps: key→val, key→freq, freq→OrderedDict.
Read →
webcoderspeed.com
5 articles
Implement an LFU cache with O(1) get/put using three hash maps: key→val, key→freq, freq→OrderedDict.
Design a data structure supporting inc/dec and getMaxKey/getMinKey in O(1) using a doubly linked list of frequency buckets.
Implement a doubly linked list with sentinel head and tail nodes for clean O(1) insertions and deletions.
Implement LRU Cache from scratch using a doubly linked list with sentinel nodes and a hash map for O(1) operations.
Design a browser history with visit, back, and forward operations using a doubly linked list for O(1) navigation.