The insert and average parts were fine, I had a deque in mind pretty quickly.
Use a deque to store timestamped records in chronological order, and maintain a running sum of scores. On each insert or query, evict records older than the window by comparing timestamps to the current time minus window size, then update the sum and return the average.
Pro tip: Clarify whether the window is inclusive or exclusive and whether timestamps are strictly increasing; this shows attention to edge cases and can prevent off-by-one errors.
Ask about window semantics (inclusive/exclusive), timestamp ordering, and whether scores can be negative or zero. Confirm that eviction should happen on every method call.
Select a deque (double-ended queue) to store records in order, and a running sum variable to avoid recomputing the average from scratch.
On each insert or query, remove records from the front of the deque while their timestamp is older than (current time - window size). Update the running sum accordingly.
For insert, append the new record and add its score to the sum. For getAverage, return sum / count if count > 0, else 0 (or handle empty case as specified).
State that both operations are O(1) amortized due to deque operations, and discuss edge cases like empty window, out-of-order timestamps, and large windows.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.