Find Median from Data Stream
A hard-tier problem at 53% community acceptance, tagged with Two Pointers, Design, Sorting. Reported in interviews at Okta and 30 others.
Find Median from Data Stream is a Hard problem asked at Okta, Oracle, Pinterest, Splunk, and 26 other companies. You're given a stream of numbers and need to return the median efficiently each time a new number arrives. The acceptance rate is 53%, which tells you plenty of strong candidates blank on the heap trick. If you haven't nailed the two-heap pattern, this problem will stall you live. StealthCoder solves it invisibly during your assessment if the pattern doesn't click.
Companies that ask "Find Median from Data Stream"
Find Median from Data Stream is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThe median is the middle value of a sorted list. In a stream, numbers arrive one at a time and you can't pre-sort. The trap is thinking you can maintain a full sorted array with binary search insertion, O(n) per add, which TLEs. The pattern is two heaps: max-heap storing the lower half, min-heap storing the upper half. When a new number arrives, add it to the appropriate heap and rebalance so sizes differ by at most one. The median is either the top of the larger heap (odd total) or the average of both tops (even total). Most failures come from off-by-one balance errors or not implementing heap operations correctly in your language. StealthCoder is the safety net if you draw a blank on heap construction during your live assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Find Median from Data Stream recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find Median from Data Stream interview FAQ
What's the actual trick to this problem?+
Use two heaps: a max-heap for the smaller half of numbers and a min-heap for the larger half. Keep them balanced so you can always compute the median in O(1) time. The hard part is managing insertion and rebalancing in O(log n). Most failures happen because candidates try a sorted array and get TLE.
Is this really asked at Okta, Oracle, and Pinterest?+
Yes, the data shows it's reported by 31 companies including Okta, Oracle, Pinterest, Splunk, and Tinder. It's a classic design problem that screenshotted interviews love. If your target company is on that list, this one matters.
How does this relate to Heap (Priority Queue)?+
Heaps are the core. The problem requires you to efficiently track the median as data streams in. A naive sort or list is too slow. Two heaps give you O(log n) add and O(1) median retrieval. This tests whether you really understand heap semantics and can build a custom data structure.
Can I solve this without heaps?+
Technically yes, but inefficiently. A sorted list works for small inputs but fails at scale with O(n) insertion. Binary search trees are cleaner conceptually but still harder to code under pressure. Heaps are the accepted pattern here and what the interviewer expects.
What do I do if I don't see the two-heap pattern during the real OA?+
Write a brute-force solution first: sort and return the middle. Get it working, explain the O(n log n) cost per call, then optimize if time permits. If you freeze completely, StealthCoder runs invisibly and surfaces the heap solution so you can move on instead of failing the OA.
Want the actual problem statement? View "Find Median from Data Stream" on LeetCode →