Build an LRU Cache

medium
Unit 18 · Datetime II0/1 to milestone

Implement a class LRUCache(capacity) with O(1) get(key) (returns -1 if missing) and put(key, value). When full, put evicts the least recently used key. Both get and put count as a "use".

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Build an LRU Cache · TechGradify