educative.io

How can we modify two heap approach to handle negative numbers

I have a question regarding ’ Find the Median of a Number Stream’ max and min implementation. I was wondering if we can use same approach for negative numbers. for example: [3,-1,-2] the median should be -2 but this approach will return 3.

If correctly implemented, the max heap, min heap implementation works for all numbers, positive, negative, rational, real etc.