Moving Average from Data Stream
Difficulty: Easy
Category: DSA
Topics: Array, Design, Queue, Data Stream
Asked at: Google, Apple, Spotify, Indeed, Amazon
You are given a class `MovingAverage` that receives a stream of integers. Initialize the object with an integer `size`, representing the size of a moving window. Implement the `next(val)` method, which accepts an integer `val` and returns the moving average of the last `size` values in the stream (including the current `val`). If the number of elements seen so far is less than `size`, compute the average of all elements received so far.
Return the moving average as a floating point number after each call to `next(val)`.