#1825

Finding MK Average

master · 1765 · lc hard +32 · 38.7% accepted · 528 likes · top 18%

Description

Implement MKAverage for a data stream with parameters m and k:

- MKAverage(int m, int k) — initializes the object.

- void addElement(int num) — adds num to the stream.

- int calculateMKAverage() — if fewer than m elements received, return -1; otherwise take the last m elements, discard the k smallest and k largest, and return the integer floor of the average of the rest.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16