Finding Mk Average

hard
You are given a stream of numbers calculate its MKAverage.

The MKAverage is calculated using these steps:
1. If the number of the elements in the stream is less than m you should consider the MKAverage to be -1. Otherwise, copy the last m elements of the stream to a separate container.
2. Remove the smallest k elements and the largest k elements from the container.
3. Calculate the average value for the rest of the elements rounded down to the nearest integer.

Implement the MKAverage class:

1. MKAverage(int m, int k) Initializes the MKAverage object with an empty stream and the two integers m and k.
2. void addElement(int num) Inserts a new element num into the stream.
3. int calculateMKAverage() Calculates and returns the MKAverage for the current stream rounded down to the nearest integer.

Input Format

Input is managed for you

Output Format

Output is managed for you

Constraints

1. 3 <= m <= 10^5
2. 1 <= k*2 < m
3. 1 <= num <= 10^5

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
3 1
addElement 3
addElement 1
calculateMKAverage
addElement 10
calculateMKAverage
addElement 5
addElement 5
addElement 5
calculateMKAverage
exit
Output
-1
3
5
Previous
Shortest Subarray With Sum At Least K
Next
Guess Number Higher Or Lower

Related Questions