Difficulty Level : Medium
Submissions : 26
Asked In :
Marks :10
: 1 | : 0
Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.
Initially, the size of the cache is given. After that, there can be two types of operations:
Every operation must be done in O(1) time.
The first line contains 2 space separated integers, size (1 <= size <= 1000) and Q (1 <= Q <= 1e5) - size of the cache and number of operations
Next Q lines contains the descriptions of the operation, either of type "put k v" or "get k". (1 <= k <= 1000) (1 <= v <= 1000)
There will be at least one get per test case.
For every get operation encountered, print its answer.
2 9 put 1 1 put 2 2 get 1 put 3 3 get 2 put 4 4 get 1 get 3 get 4
1 -1 -1 3 4
You need to login to view your submissions.
You need to login to view all submissions.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.