Sale
Summer Offer: $190/yr $99/yr
00 : 00 : 00 : 00
Get this deal
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.
Suggested Answer

Trusted by 100+ professionals preparing for interviews

Trusted by 100+ professionals 50+ Company Question Banks 5+ Supported Languages

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

Get Started Free

More Backend Engineering Interview Prep

Describe a time when you contributed to improving a system's performance. What tools and methods did you use to identify and solve the performance bottlenecks?
Backend Engineering · Senior
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Link copied to clipboard