Algorithms and Data Structures: TheAlgorist.com
System Design: SystemsDesign.Cloud
Low Level Design: LowLevelDesign.io
Frontend Engineering: FrontendEngineering.io
Problem Statement:Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the following operations: get and put.
get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
put(key, value) - Set or insert the value if the key is not already present. When the cache reaches its capacity, it should invalidate the least frequently used item before inserting a new item. For the purpose of this problem, when there is a tie (i.e., two or more keys that have the same frequency), the least recently used key would be evicted.
Both get and put must be O(1).
Java and Python Solution:
This is a Premium Content.
Please subscribe to Low Level Design course to access the content.
If you have any feedback, please use this form: https://thealgorists.com/Feedback.
Follow Us On LinkedIn