I'd done LRU before so the concept wasn't the issue.
Start by clarifying the requirements: fixed capacity, O(1) get and put, and LRU eviction. Then propose a hash map for O(1) access and a doubly linked list (or a list with a timestamp/order field) to track recency, explaining how get and put update the order. Walk through the logic for eviction when capacity is exceeded, and discuss trade-offs of using a list versus a linked list.
Pro tip: Mention that using a plain list with a timestamp or order field can simplify implementation but may degrade to O(n) for updates; a doubly linked list ensures O(1) but requires careful pointer manipulation. Also, consider thread-safety if the store might be used concurrently.
Confirm that both get and put count as recent use, and that eviction happens when capacity is exceeded. Ask about expected operation frequency and whether thread-safety is needed.
Propose a hash map for O(1) key lookup and a doubly linked list (or a list with order tracking) to maintain recency. Explain why a singly linked list or plain array is insufficient for O(1) updates.
Describe how get moves the accessed node to the front (most recent) and returns the value. For put, if key exists, update value and move to front; if new, insert at front and evict the least recent (tail) if capacity is full.
Discuss eviction when capacity is reached, handling of null values, and behavior when capacity is zero or one. Mention that eviction should remove the least recently used key from both the map and the list.
State that both get and put are O(1) with a doubly linked list, but using a plain list may be O(n) for updates. Discuss trade-offs: simplicity vs. performance, and potential concurrency issues.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.