Implement LRU Cache
Design and implement a Least Recently Used (LRU) cache data structure that supports get and put operations in O(1) time complexity. The cache should evict the least recently used item when it reaches its capacity limit.
Asked at:
Shopify
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Early March, 2026
Shopify
Senior
/** Implement an LRU Cache with O(1) access behavior Let's implement a cache with a given capacity. When we insert new items after the cache is full, we should discard the least recently used items first. When an item is added or updated it is now the most recently used item aka freshest item. We should maintain O(1) access and update. Example: capacity = 3. put A, value1 put B, value2 put C, value3 get A put C, value4 put D, value5 // B is removed, and D is added. */
Late January, 2026
Shopify
Senior
Early January, 2026
Shopify
Manager
Your account is free and you can post anonymously if you choose.