I'd never heard the term 'LinkedList + HashMap' used together as a named pattern before, so when the interviewer just dropped that phrase and stopped talking, I was genuinely lost for a second.
Start by clarifying the requirements: O(1) get and put, eviction of least recently used item when capacity is exceeded. Then explain that a hash map combined with a doubly linked list achieves O(1) for both operations, and walk through the design and implementation.
Pro tip: Mention that you would use a doubly linked list with sentinel head and tail nodes to simplify edge cases, and discuss how you would handle thread safety if needed in a concurrent environment.
Confirm that get and put must be O(1), capacity is fixed, and eviction policy is LRU. Ask about thread safety, null keys/values, and expected usage patterns.
Explain that a hash map provides O(1) access to nodes, and a doubly linked list maintains recency order. Together they allow O(1) get, put, and eviction.
Detail how get moves the accessed node to the front (most recently used), and put inserts or updates a node, moving it to the front, and evicts the tail (least recently used) if capacity is exceeded.
Discuss using sentinel nodes to avoid null checks, handling capacity 0 or 1, and updating existing keys. Mention potential thread safety with locks or concurrent data structures.
Confirm O(1) time for get and put, O(capacity) space. Walk through a simple example to verify correctness, and mention unit tests for eviction order and edge cases.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.