Start by clarifying requirements: TTL semantics (per-item expiration), capacity eviction policy (LRU), and how get_average should behave (e.g., average of remaining TTLs or original TTLs). Then design a data structure combining a hash map for O(1) key lookup, a doubly linked list for LRU ordering, and a min-heap or time-ordered structure for TTL expiration, while maintaining running sum and count for average. Discuss trade-offs and edge cases before coding.
Pro tip: Mention that TTL eviction can be lazy (on access) or active (background thread), and that lazy eviction simplifies implementation but may leave expired items until accessed; also note that get_average should likely exclude expired items, so you need to purge them first.
Ask about TTL semantics (absolute vs sliding), eviction policy details (LRU on get/put), and whether get_average includes expired items. Confirm expected time complexities and concurrency needs.
Use a hash map for O(1) key access, a doubly linked list for LRU order, and a min-heap or balanced BST keyed by expiration time for TTL. Maintain running sum and count of TTLs for average.
For get: check existence, TTL validity, update LRU, and return value. For put: insert/update, set TTL, evict LRU if over capacity, and remove expired items. For get_average: purge expired items then return sum/count.
Address empty cache, expired items on get, updating TTL on put, and capacity=0. Analyze time complexity: O(1) for get/put (amortized with heap), O(log n) for TTL operations, and O(1) for average after purge.
Consider using a timing wheel for efficient TTL management, lazy vs active expiration, and thread-safety. Mention that maintaining average of original TTLs vs remaining TTLs changes implementation.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.