Backend Engineering
Senior
programming
LeetCode #146 - LRU Cache
Design and implement a data structure that allows you to add key-value pairs and retrieve the value of a given key. If the key does not exist, return -1. If the cache reaches its capacity, it should invalidate the least recently used item before inserting a new item.
Input: An integer capacity and a list of operations in the format ['put(key, value)', 'get(key)', ...]
Output: Return the result of get operations in order.
Constraints: 1 <= capacity <= 3000 and all keys are unique.
Input: An integer capacity and a list of operations in the format ['put(key, value)', 'get(key)', ...]
Output: Return the result of get operations in order.
Constraints: 1 <= capacity <= 3000 and all keys are unique.
Suggested Answer