← 返回 atlassian 的题目列表Stream Moving Average with Recent-Value Weighting
类型:qbank
Given a stream of numeric values and a window size, compute the moving average over the last N items. Follow-ups ask for a weighted moving average that emphasizes recent values and whether it can be done without storing all prior values.
Requirements
Process an integer or numeric stream online.
Given a window size N or X, return the average of the most recent window.
Maintain enough state to update the average as new values arrive.
Follow-ups include:
Recent values should carry higher weights than older values.
Avoid storing all historical values.
Explain what state is still necessary for exact fixed-window behavior.
Notes
Candidates explicitly describe this as a coding round for MLE/MLSE; it is not a model-building exercise.
Clarify whether the weighted follow-up is an exact finite-window weighted average or an exponentially weighted moving average. The latter has a much smaller state footprint.
Preparation
Implement a queue plus running sum for fixed-window average.
Implement both finite weighted-window and exponential moving average variants, and be ready to explain the memory difference.