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.