Streaming variance without storing the data
You receive prices one at a time and must report the running mean and variance at any moment, without keeping the full history in memory. The textbook "average of squares minus square of average" formula loses precision when values are large and close together.
feed 2, 4, 6
mean -> 4.0
population variance -> 2.667 # (4 + 0 + 4) / 3
Maintain the running mean and variance incrementally in O(1) time and space per update.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.