Challenge
Process events [timestamp, value] in the supplied order. After each event at time t, return the arithmetic mean of the events already processed whose timestamps lie in (t-window, t]. The left boundary is excluded. Equal timestamps are allowed; later events at that timestamp are not yet visible. Return the sequence of means.
Input and output contract
0 ≤ n ≤ 1,800; integer timestamps in nondecreasing order; |value| ≤ 10,000; window is a positive integer. Values are equally weighted, not weighted by elapsed time. Empty input returns []. Numeric comparison allows 1e-7 absolute or 1e-9 relative error. w denotes the maximum active event count.
All tests follow this contract. You do not need to validate malformed input. Return the requested result from rolling_moving_average; printed output is not your answer. Standard-library tools are allowed. Implement your solution in Python 3.12.
Target complexity: O(n) time; O(w) auxiliary space plus O(n) output
Return values are checked by type. Use the exact function name. Print output is not your answer. Tests have time and memory limits.
Public examples
Arguments
[[[0, 10], [2, 20], [2, 40], [5, 30]], 3]
Expected return
[10.0, 15.0, 23.333333333333332, 30.0]
Arguments
[[], 5]
Expected return
[]
Arguments
[[[1, 8], [4, 2]], 3]
Expected return
[8.0, 2.0]
Hint
Keep a queue and running sum. Expire events with timestamp ≤ t-window before adding the current event.
The worked solution unlocks after completion, or with Premium access.