...

/

Solution: Moving Average from Data Stream

Solution: Moving Average from Data Stream

Let’s solve the Moving Average from Data Stream problem using the Custom Data Structures pattern.

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 size 100\leq 100 ...

Access this course and 1400+ top-rated courses and projects.