Katkat

Implement LRU, Extend to LFU, Analyze Complexity

IntuitSoftware Engineer · Technical Screen

Last updated

This question evaluates understanding of cache eviction policies (LRU and LFU), frequency tracking, and the design of data structures that support efficient get/put operations while meeting time and space complexity constraints.

Implement an in-memory Least Recently Used (LRU) cache with capacity N that supports get(key) -> value and put(key, value). Achieve O(

  1. average time per operation using appropriate data structures; justify your choices and analyze time and space complexity. Follow-up: Modify the design to implement a Least Frequently Used (LFU) cache with O(
  2. or amortized O(
  3. operations; explain the eviction policy, how you track and update frequencies on get/put, and how you break ties by recency.