Question: A cache is a limited storage that stores key - value pairs, implementing a eviction policy to manage its size. Least Frequently Used ( LFU
A cache is a limited storage that stores keyvalue pairs, implementing a eviction policy to manage its size. Least Frequently Used LFU cache removes the least frequently accessed key when the capacity is reached. You need to implement the Least Frequently Used LFU cache with the capacity N You are also given Q operations of the following type: key, Get the value of the key from the cache. If the value does not exist in the cache, return key, value. Update the value of the key if present, or insert the key if not already present. When the cache reaches its capacity, it should invalidate and remove the leas frequently used key before inserting a new item. For this problem, when there is a tie two or more keys with the same frequency the smallest key should be removed. For each operation of type print the required value. Function description Complete the function Solve This function takes the following parameters and returns the required array of results: N Represents the capacity of the cache Q Represents the number of operations on the cache operations Represents the operations on the cache Input formet for custom testing Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code The first ine contains N denoting the capacity of the cache. The next line contains O denoting the number of operations on the cache.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
