Katkat

Design LRU cache with O(1) operations

TikTokSoftware Engineer · Technical Screen

Last updated

This question evaluates a candidate's understanding of data structures and algorithm design, specifically skills in implementing constant-time cache operations, eviction policies, update handling, and concurrency/thread-safety considerations.

Design and implement an in-memory cache that evicts the least recently used entry when capacity is reached. Support get(key) and put(key, value) in O(

  1. average time. Describe the data structures you would use, how you maintain and update access order, and how you handle updates to existing keys. Discuss edge cases (e.g., capacity = 0), thread-safety considerations, and how you would test the implementation.