Search⌘ K
AI Features

Moving Average from Data Stream

Explore how to implement a MovingAverage class that computes the moving average of integers in a sliding window. Understand the use of custom data structures, handle a stream of inputs, and practice efficient coding techniques to solve common interview problems.

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 size values from the stream.

Constraints:

  • 11 \leq ...