We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I'll give you guys a hint. You need a min-heap and a max-heap.
Min-heap will contain the maximum half of the numbers from the array. Max-heap will contain the minimum half of the numbers from the array.
So the top value from the min-heap will be the minimum number from the max half of the array. The top value from the max-heap will be the maximum number from the min half of the array.
So you pretty much have the middle values of the array, therefore can calculate the median. So think about it, what can you change to make it work with odd number of values?
Heaps: Find the Running Median
You are viewing a single comment's thread. Return to all comments →
I'll give you guys a hint. You need a min-heap and a max-heap.
Min-heap will contain the maximum half of the numbers from the array. Max-heap will contain the minimum half of the numbers from the array.
So the top value from the min-heap will be the minimum number from the max half of the array. The top value from the max-heap will be the maximum number from the min half of the array.
So you pretty much have the middle values of the array, therefore can calculate the median. So think about it, what can you change to make it work with odd number of values?