Snap·Software Engineer·Technical Phone Screen
- Design a cache that supports LRU eviction and per-entry TTL. get(key) should return -1 if the key is expired or missing, and accessing a key should refresh its recency. put(key, value, ttl) should insert or update with a TTL and evict expired entries before falling back to LRU eviction when the cache is full. Walk through the data structures you'd use and the complexity of each operation.
“I started with the standard hashmap plus doubly linked list setup for LRU and felt pretty solid until they pushed on the TTL piece.”