I knew LRU cold going in, doubly linked list plus a hashmap, done.
Start by clarifying requirements and constraints, then propose a design using a hash map for O(1) access and a doubly linked list for recency ordering, with a separate pinned list or flag to exclude pinned items from eviction. Discuss trade-offs, edge cases, and potential optimizations, and be prepared to outline code or pseudocode.
Pro tip: Demonstrate awareness of concurrency and memory overhead: mention that pinning can be implemented with a counter per key to handle multiple pins, and discuss thread-safety mechanisms like locks or lock-free structures if needed.
Ask about expected cache size, pin/unpin semantics (e.g., multiple pins per key), concurrency needs, and eviction policy details. Confirm that all operations must be average O(1).
Propose a hash map mapping keys to nodes, and a doubly linked list for recency order. For pinned items, either maintain a separate list or mark nodes as pinned and exclude them from eviction.
Detail get, put, pin, unpin: get moves node to front if not pinned; put adds/updates and evicts from tail if over capacity, skipping pinned nodes; pin increments a counter and moves node to pinned list; unpin decrements and moves back if zero.
Argue O(1) average time for all operations. Discuss edge cases: evicting when all items pinned, pinning non-existent key, unpinning unpinned key, and cache full of pinned items.
Compare separate pinned list vs. flag approach. Mention concurrency considerations, memory overhead, and possible optimizations like lazy eviction or using a single list with skip pointers.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.