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.
Examples
01 · 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
1 <= deliveryTimes.length <= 2 * 10^50 <= deliveryTimes[i] <= 10^9
More Amazon problems
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Maximum Non-Adjacent House ValueONSITE INTERVIEW · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
public int[] runningDeliveryMedians(int[] deliveryTimes) {
// write your code here
}deliveryTimes[5,17,100,11]
expected[5,5,17,11]
sign in to submit