The baseline tracker was already given so you're not building from scratch, which I appreciated.
Start by clarifying the data structures and constraints: the rolling window, how records are stored, and what 'active window' means. Then propose a design that supports O(1) update by maintaining a hash map from conversation ID to its position in the window (e.g., a deque or circular buffer), and handle eviction by removing from the map. Discuss trade-offs like memory overhead and concurrency, and walk through the update logic step-by-step.
Pro tip: Mention that you'd use a lazy deletion or timestamp check to avoid scanning the entire window on each update, and that you'd consider thread-safety if the tracker is accessed concurrently. This shows you think about real-world performance and reliability.
Ask about the window size, whether it's time-based or count-based, expected update frequency, and concurrency needs. Confirm that update should only affect records still in the window.
Propose a combination: a deque (or circular buffer) to maintain order and evict old records, a hash map from conversation ID to the record's node/position for O(1) access, and a running sum for O(1) get_average.
On update, look up the conversation ID in the hash map. If not found (evicted), do nothing. If found, adjust the running sum by the difference between new and old score, and update the record in place.
When adding a new record, evict the oldest if the window is full, remove it from the hash map, and subtract its score from the running sum. Ensure update doesn't interfere with eviction.
Cover memory overhead of the hash map, potential race conditions if concurrent, and how to handle duplicate updates or invalid scores. Mention alternatives like a balanced BST if order statistics are needed.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.