Back to problems

Implement Moving Average from Data Stream

Algorithm · ByteDance · Easy

Design a class that reports the moving average of a stream of integers. Implement MovingAverage: The constructor receives an integer size that sets the sliding window capacity. next(int val) accepts the next integer from the stream and returns the average of the most recent size values. If fewer than size values have been seen, return the average of all values seen so far. Example Explanation: next(1) returns 1.0 because only one value is in the window. next(10) returns 5.5…

Checking your access…