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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!