Hard · System Design
Find Median from Data Stream
Given a stream of integers nums, implement MedianFinder with addNum(num) and findMedian(); call findMedian after each addNum and return the list of medians, where an even count's median is the mean of its two middle values.
Examples
Example 1
{
"nums": [1, 2, 3, 4, 5]
}Output: [1, 1.5, 2, 2.5, 3]
Example 2
{
"nums": [5, 15, 1, 3]
}Output: [5, 10, 5, 4]
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.