Moving Average from Data Stream
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) / 3Analysis
Solution
Queue (Implemented with LinkedList)
Another simpler implementation using LinkedList as Queue
Using ArrayDeque
Using fixed length Array (Circular Queue)
Another implementation
Last updated