Moving Average from Data Stream
Easy · Queue & Deque · about 10 minutes
Asked at Meta, Google, Spotify, Amazon, Twitch.
Implement MovingAverage, which averages the most recent values of a stream over a fixed-size window.
MovingAverage(size)sets the window size.next(val)takes invaland returns the mean of the latestsizevalues seen; while fewer thansize
values have arrived, it averages all of them.