Problem
Ask
Submissions

Problem: Moving Average from Data Stream

Easy
15 min
Explore how to design and implement a MovingAverage class that calculates the moving average of integers from a data stream within a fixed window size. Understand the problem constraints and develop a clear approach to handle sliding window operations efficiently. Practice coding your solution in a hands-on environment to master this common interview 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

  • 103-10^3 \leq val 103\leq 10^3

  • At most 10210^2 calls can be made to next.

Problem
Ask
Submissions

Problem: Moving Average from Data Stream

Easy
15 min
Explore how to design and implement a MovingAverage class that calculates the moving average of integers from a data stream within a fixed window size. Understand the problem constraints and develop a clear approach to handle sliding window operations efficiently. Practice coding your solution in a hands-on environment to master this common interview 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

  • 103-10^3 \leq val 103\leq 10^3

  • At most 10210^2 calls can be made to next.