DIY: LFU Cache
We'll cover the following...
Problem statement
Your task is to build an LFU(least frequently used) cache. You will build a structure that initializes a cache with a fixed capacity that allows read and write operations. When the cache reaches its maximum size, replace the least frequent entry with the new one.
Coding exercise
You have to implement the functions put(key, value)
and get(key)
. The function put(key, value)
takes key
and value
as parameters and assigns the value against the provided key. If the key already exists, it updates the value against that key. The function get(key)
takes key
as a parameter and fetches the value that is stored against that key.
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy