Skip to content

Latest commit

 

History

History
10 lines (9 loc) · 278 Bytes

File metadata and controls

10 lines (9 loc) · 278 Bytes

Problem

Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.

For example, MovingAverage m = new MovingAverage(3); m.next(1) = 1 m.next(10) = (1 + 10) / 2 m.next(3) = (1 + 10 + 3) / 3 m.next(5) = (10 + 3 + 5) / 3