Moving Average From Data Stream
easy
Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. Implement the MovingAverage class: 1. MovingAverage(int size) Initializes the object with the size of the window size. 2. double next(int val) Returns the moving average of the last size values of the stream.
Constraints
1. 1 <= size <= 1000 2. -10^5 <= val <= 10^5
Format
Input
Input is managed for you
Output
Output is managed for you
Example
Sample Input
3
1
10
3
5
Sample Output
1.0
5.5
4.66667
6.0
Question Video