Back to problems

Implement Cache and Rotate Matrix

Object-Oriented Programming · Amazon · Medium

Task 1: LRU Cache Approach: Hash Map + Doubly Linked List An LRU cache needs two operations to be fast: get should return a value by key immediately, and put should insert or update a key while evicting the least recently used item when the capacity is exceeded. A hash map alone gives $$O(1)$$ lookup, but it does not preserve access order. A doubly linked list preserves order and allows $$O(1)$$ removal/insertion at either end, but searching for a key would take $$O(n)$$.…

Checking your access…