Coding

Find the median from a continuous data stream.

Implement a data structure that allows you to add integers from a continuous data stream and find the median of all elements so far efficiently.

Input: addNum(2), addNum(3), findMedian(), addNum(4), findMedian()

Output: 2.5 then 3.0

Explanation: After adding 2 and 3, the median is 2.5. After adding 4, the sorted stream is [2, 3, 4], making the median 3.0.

Was asked at

Practice this question with AI

First session is free - no credit card required.

Go Premium

More interviews, more skills, more success.

No answers yet

Be the first to share your approach to this question

Practice More Questions