Design a Least Recently Used (LRU) cache with a fixed capacity that supports get and put in O(1) average time. When the cache exceeds its capacity, evict the least recently used entry.
capacity = 2; put(1,1); put(2,2); get(1)1put(3,3) (evicts key 2); get(2)-1Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →A chain of nodes, each pointing to the next. No random access like an array, but insertion and deletion at a known position is O(1), and many classic problems come down to careful pointer rewiring.
Read the full Linked List guide →
Original problem on LeetCode ↗