Create a Cache

Difficulty: EASYCategory: LLDFrequency: 1Asked On 2024-09-25

Problem Statement

Design and implement a Cache data structure that supports the following operations in O(1) time complexity:

🎯 Functional Requirements

Implement the following methods:

1.get(key: int) -> int
•Returns the value of the key if the key exists in the cache, otherwise return -1.
2.put(key: int, value: int)
•Inserts or updates the value.
•If the cache has reached its capacity, evict the least recently used (LRU) item before inserting the new item.


Solution

Comments