Day 24 of 30-Day LeetCode Challenge

Aanchal Patial
1 min readApr 24, 2020

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.

get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
put(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.

The cache is initialised with a positive capacity.

--

--

Aanchal Patial

We never really grow up, we only learn how to act in public