Median from running stream of integers


I am trying to find the median from the running stream of integers. It is giving incorrect output. Please help me identify error in my code.

Hello @Kajal

You need to type cast the maxHeap.size() to int as it returns a value of type unsigned int.
Same goes with minHeap.size().
Because when you subtract maxHeap.size() - minHeap.size() if the value is negative, the result will still be positive because they both are of type unsigned int.

I have modified the code

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.