Reported March 2025
Amazonheap priority queue

All About Medians

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Amazon's asking about medians in March 2025, and you're taking the OA in the next 48 hours. This problem tests whether you can find or maintain a median efficiently under constraint. The trick isn't the math, it's the data structure. Most candidates either brute-force sort repeatedly or miss that you need two heaps to track the middle value in real time. StealthCoder will spot the heap pattern instantly if you blank on the approach.

Pattern and pitfall

Median problems almost always hinge on dual heaps: a max-heap for the lower half and a min-heap for the upper half. The common pitfall is trying to keep a sorted array and search for the median by index, which tanks on repeated insertions. Amazon specifically likes this because it mirrors real-world stream processing. If the problem asks you to find the median after each insertion or query, you need O(log n) per operation, not O(n log n). Balance the heap sizes so the median is always at a heap root. StealthCoder catches the moment you start coding a naive sort and redirects you to the two-heap pattern, giving you the edge on the live OA.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill All About Medians cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as find median from data stream. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

All About Medians FAQ

What's the actual trick Amazon is testing here?+

Two heaps: max-heap for left half, min-heap for right half. Keep sizes balanced so the median is at a root, not buried. O(log n) insertion, O(1) query. That's what they want. Sorting repeatedly fails.

Do I need to implement a heap from scratch?+

No. Most languages have a heap library or priority queue. Python has heapq, Java has PriorityQueue. Use it. They're testing algorithm design, not heap internals. If you implement custom, you're wasting time.

How do I handle even vs. odd counts?+

Decide before you code: either the median is always the smaller of the two roots, or you average them for even counts. Stick to one rule. Common error: flip-flopping mid-implementation and breaking ties.

Is this still asked at Amazon in 2025?+

Yes. Median of a stream is a classic Amazon problem. It shows up under different names (find median, maintain median, online median), but the heap pattern is constant.

How do I prepare in 24 hours?+

Code the two-heap solution once, test on even and odd inputs, trace through one manual example. You don't need to drill; you need to own the pattern. Muscle memory over volume.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it