Katkat

Implement LRUCache with O(1) Operations and Thread Safety

PinterestData Scientist · Onsite

Last 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.