Reported September 2026
Amazonheap priority queue

Running Delivery Time 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

The mistake that sinks a first attempt on this Amazon OA, reported in September 2026, is re-sorting the prefix after every insert. It passes the sample and dies on big input. Running Delivery Time Medians asks for the median after each new value, with the lower median on even counts. That's the classic two-heap pattern, a max-heap for the lower half and a min-heap for the upper half. If you know it, it's twenty minutes of work. If you blank, StealthCoder is the safety net that runs invisibly during the live OA and hands you the structure.

The problem

Given an array deliveryTimes, process the values from left to right. After each new delivery time arrives, output the median of all delivery times seen so far.
When the number of seen values is even, use the lower median, meaning the larger value in the lower half after sorting.
Return an array containing the median after each insertion.

Function
runningDeliveryMedians(deliveryTimes: int[]) → int[]

Examples
Example 1
deliveryTimes = [5,17,100,11]
return = [5,5,17,11]
The sorted prefixes are [5], [5,17], [5,17,100], and [5,11,17,100]. Their lower medians are 5, 5, 17, and 11.

Constraints
deliveryTimes are processed from left to right.
After each new value is inserted, record the median of all values seen so far.
When the number of seen values is even, use the lower median: the larger value in the lower half after sorting.
Return one median for each insertion.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is two heaps. Keep a max-heap for the lower half and a min-heap for the upper half. Push each new value into the max-heap, then move its top into the min-heap. If the min-heap ends up bigger than the max-heap, move its top back. Now the max-heap holds either the same count as the min-heap or one more. Its top is always your lower median, which matches the even-count rule here. The common pitfall is returning the average of the two middles, or taking the min-heap top on even counts. Check the example: after [5,17], the answer is 5, not 11. Another trap is languages with only a min-heap, where you must negate values for the max-heap. Each insert costs O(log n). If the heap rebalancing logic slips mid-assessment, StealthCoder is the hedge that gives you a working version in real time.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Running Delivery Time 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Amazon reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Running Delivery Time Medians FAQ

What's the trick to Running Delivery Time Medians?+

Use two heaps. A max-heap holds the smaller half and a min-heap holds the larger half. Keep the max-heap equal in size or one bigger. Then the max-heap top is the median every time, including the lower median on even counts.

How hard is this problem really?+

It's a medium to hard, mostly because of the data structure idea. Once you know two heaps, the code is short. Without it, people reach for sorting every step, which is O(n^2 log n) overall and times out.

Why is the even-count answer 5 for [5,17]?+

The problem defines the lower median as the larger value in the lower half after sorting. With [5,17], the lower half is [5], so the answer is 5. Averaging gives 11, which is wrong here.

Can I use insertion into a sorted list instead?+

You can use binary search to find the spot, and it's correct. But inserting into an array shifts elements, so it's O(n) per insert. For small inputs it passes. For large ones, the two-heap approach at O(log n) per insert is safer.

How do I prepare for this in 48 hours?+

Write the two-heap running median from scratch twice. Then change it to return the lower median and test with odd and even lengths, duplicates, and a single element. If your language lacks a max-heap, practice the negation trick.

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