Data Structures19 sections · 729 units
Open in Course

Problem - Find Median from Data Stream

Two heaps in action

Design a data structure that supports:

  • addNum(num): add an integer from the stream
  • findMedian(): return the median of all elements so far

You're solving the classic two-heaps problem. It tests whether you can maintain the invariants correctly during insertion.