← 返回 google 的题目列表Sliding Window Average After Removing the Largest K Values
类型:online_judge
Given an integer array nums, a window length w, and a non-negative integer k, process every contiguous sliding window of exactly w elements:
Ignore (remove) the k largest elements in the window. If duplicates exist, removing any k occurrences is valid.
Compute the average of the remaining w - k elements.
Return the averages in left-to-right window order.
Requirements:
0 <= k < w <= len(nums).
If k = 0, remove nothing.
The denominator is always w - k.
Return exact averages; print each result with 6 decimal places.
Example 1
Input:
nums = [1, 5, 2, 4, 3]
w = 3
k = 1
Output:
1.500000 3.000000 2.500000
Constraints
1 <= len(nums) <= 2 * 10^5
-10^9 <= nums[i] <= 10^9
Aim for O(log w) update time per sliding-window move rather than re-sorting each window.
Example
Input
5 3 1
1 5 2 4 3
Output
1.500000 3.000000 2.500000