Google | Onsite | Mean of last N integers in stream excluding K largest
Anonymous User
4043

There is a stream of integers. Every time you see a new element in the stream, return the mean value of the last N elements, excluding the largest K elements.

Example:
N = 5
K = 2
elements so far = [20, 2, -2, 0, 10, 1, 5, -2, 0]

last N elements: [10, 1, 5, -2, 0]
largest K elements: [10, 5]
result = (1+(-2)+0)/3 = -0.3333333

I could not find a neat approach but only a suboptimal one.

Comments (14)