1/42
Loading...
📱Smartphone App Manager!
📱 Think of your phone's recent apps! • Open an app → moves to front • Low memory → closes oldest app • Find specific app → instant lookup This is exactly what LRU Cache does!
🔒
Loading...
📱 Think of your phone's recent apps! • Open an app → moves to front • Low memory → closes oldest app • Find specific app → instant lookup This is exactly what LRU Cache does!
Implement an LRU (Least Recently Used) cache. The cache is initialized with a positive integer capacity and supports get(key) and put(key, value) operations. When adding a new item to a full cache, the least recently used item should be removed.
capacity = 3
put("A", 1)
put("B", 2)
put("C", 3)
get("A")
put("D", 4)get("A") → 1
캐시 상태: D, A, B (C 제거됨)Getting A updates it as recently used. When adding D, the oldest item C is evicted due to capacity overflow.