Offline caching (paging): design LRU and LFD cache eviction policies.
Analyze the offline caching (paging): design lru and lfd cache eviction policies..
Examples
Input: "test_input_1"
Output: "output_1"
Input: "test_input_2"
Output: "output_2"
Hints
Recall that LRU (Least Recently Used) eviction policy removes the item that hasn't been accessed for the longest time. How would you track the recency of each item in the cache efficiently?
For LFU (Least Frequently Used), consider how you would maintain and update the frequency count of each item. How can you efficiently determine which item to evict when multiple items have the same frequency?
Design a data structure that combines both LRU and LFU policies. How would you handle the trade-off between recency and frequency when deciding which item to evict? Consider using a combination of hash maps and doubly linked lists to achieve O(1) time complexity for both get and put operations.
Offline caching (paging): design LRU and LFD cache eviction policies.
Analyze the offline caching (paging): design lru and lfd cache eviction policies..