Solution: Moving Average from Data Stream
Explore how to implement a MovingAverage class that processes a stream of integers, maintaining a fixed-size sliding window to compute the moving average efficiently. Understand how to use a queue to store recent values and a running sum to update averages in constant time, along with analyzing the solution's time and space complexity.
We'll cover the following...
Statement
Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. Implement a class called MovingAverage that has the following methods:
Constructor (int size): This constructor initializes the object with the specified window size.
double next (int val): This method takes an integer value as input and returns the moving average of the last
sizevalues from the stream.
Constraints:
size...