LRU Cache — Design with O(1) Get and Put
Implement an LRU (Least Recently Used) cache with O(1) get and put using a doubly linked list and hashmap. Full 5-language solutions.
1575 articles
Implement an LRU (Least Recently Used) cache with O(1) get and put using a doubly linked list and hashmap. Full 5-language solutions.
Implement an LFU cache with O(1) get and put. Uses two hashmaps and per-frequency doubly linked lists to track access frequency and recency simultaneously.
Design a simplified Twitter where users post tweets and follow each other, with getNewsFeed returning the 10 most recent tweets from followed users using a min-heap merge.
Implement a file system that creates paths and associates values with them. Uses a Trie or HashMap to map full paths to values with O(L) operations.
Design a hit counter that counts hits in the last 5 minutes using a deque-based sliding window or circular buffer with O(1) amortised operations.