24 · Heaps & Priority Queues

#295 Find Median from Data Stream

Hardsolve on LeetCode ↗

frequently reported atPayPalWalmartIntuitAmazonByteDance / TikTokApple

the problem

In plain words

Design MedianFinder with addNum(num) and findMedian() returning the median of all numbers added so far (average of the two middle values when the count is even).

in addNum(1), addNum(2), findMedian(), addNum(3), findMedian()

out 1.5, 2.0

  • -10⁵ ≤ num ≤ 10⁵
  • At least one number before findMedian
  • At most 5·10⁴ calls

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

Design: implement every operation. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #703
    2. #4
      Median of Two Sorted Arrays
      Hardin Binary Search