arrow_back Back to Challenges

#295 Find Median from Data Stream

Hard Acceptance 0%
description

Problem Description

The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values. Implement the MedianFinder class: - `MedianFinder()` initializes the MedianFinder object. - `void addNum(int num)` adds the integer num from the data stream to the data structure. - `double findMedian()` returns the median of all elements so far.

checklist Constraints

-10^5 <= num <= 10^5
There will be at least one element before calling findMedian.
At most 5 * 10^4 calls to addNum and findMedian.

science Examples

Case #1

In: ["MedianFinder","addNum","findMedian","addNum","findMedian"] [[],[1],[],[2],[]]
Out: [null,null,1.0,null,1.5]

Case #2

In: ["MedianFinder","addNum","addNum","addNum","findMedian"] [[],[1],[2],[3],[]]
Out: [null,null,null,null,2.0]

Mastery Tags

Heap Sorting

Hiring Companies

Amazon Google Meta
code

Integrated IDE

code_blocks
Coding
psychology
Aptitude