python intermediate 2026-11-17 को समाप्त

LRU cache

Build LRUCache(capacity), a cache that forgets the least recently used key when it is full.

  • get(key) returns the value, or None when the key is missing. Reading a key makes it the most recently used.
  • put(key, value) stores the value (updating counts as use). When the cache is over capacity, drop the least recently used key.
  • Both operations should be O(1).

Acceptance criteria

  • Don't use functools.lru_cache.
  • The tests at the bottom print All tests passed.

Hint: collections.OrderedDict has move_to_end() and popitem(last=False).

अब तक 0 लोगों ने हल किया।

python
एडिटरCtrl + Enter

            
        

जब टेस्ट "All tests passed" दिखाते हैं, तो चैलेंज इस ब्राउज़र में हल के रूप में चिह्नित हो जाता है।

अपना समाधान समीक्षा के लिए भेजें