Implement LRUCache with O(1) Operations and Thread Safety
PinterestData Scientist · OnsiteLast updated
This question evaluates a candidate's ability to implement a constant-time LRU cache and reason about thread-safety and concurrent access, testing data structure design and concurrency competencies in the Coding & Algorithms domain.
Scenario
High-traffic API needs constant-time eviction cache.
Question
Implement an LRUCache supporting get(key) and put(key,val) in O( 1). Describe thread-safety considerations for concurrent access.
Hints
Combine hash map with doubly-linked list; lock striping or concurrent linked hash map for threads.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.