Question: Using PYTHON, Design a class with data structure properties that follows the constraints of a Least Recently Used (LRU)cache. Implement the Cache class(Your class name
Using PYTHON, Design a class with data structure properties that follows the constraints of a Least Recently Used (LRU)cache. Implement the Cache class(Your class name must be Cache())such that:
- Cache(capacity) Initialize the LRU cache with positive size capacity. Note that in our tests, capacity is between 1 and 3000.
-int get(key) returns the value of the key if the key exists, otherwise return-1.
-void put(key, value) updates the value of the key if the key exists. Otherwise, add the key- value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
