346. Moving Average from Data Stream

Design a data structure that supports:

  • MovingAverage(size): Initialize the object with a window size size.
  • next(val): Append val to the stream and return the average of the last size values (or all values seen so far if fewer than size).

The moving average is the arithmetic mean of the values currently in the window.

Examples
Input: [["MovingAverage","next"],[[1],[-50]]]
Output: [null,-50]
Hints
Related Problems

346. Moving Average from Data Stream

Design a data structure that supports: