Reported September 2026
Googlesliding window

Sliding Window Average Excluding the Largest K Values

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

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

The mistake that sinks a first attempt on this Google OA, reported in September 2026, is re-sorting every window from scratch. It passes the samples and then dies on large input. The task is a sliding window average that drops the k largest values, so you need a running window sum minus a running sum of the top k. Duplicates count as separate elements, and k can be 0. If you freeze on the data structure choice, StealthCoder runs invisibly during the live assessment and gives you a working solution as a safety net. Know the trick first and you probably won't need it.

The problem

Given an integer array values, an integer windowSize, and a non-negative integer k, compute one average for every contiguous window of length windowSize.
Within each window, ignore the k elements with the largest values, counting equal values as separate elements. Average the remaining windowSize - k elements, and return the averages in left-to-right window order.
The inputs are guaranteed to satisfy 0 <= k < windowSize <= values.length. When k = 0, ignore no elements and average the entire window.
Follow-up
How would the approach change if the input were very large or arrived as a stream?

Function
slidingWindowAverageExcludingLargestK(values: int[], windowSize: int, k: int) → double[]

Examples
Example 1
values = [1,3,2,6,4]
windowSize = 3
k = 1
return = [1.5,2.5,3.0]
The windows are [1,3,2], [3,2,6], and [2,6,4]. Removing the largest value from each leaves [1,2], [3,2], and [2,4], whose averages are 1.5, 2.5, and 3.0.
Example 2
values = [2,-2,4]
windowSize = 2
k = 0
return = [0.0,1.0]
Because k = 0, both values remain in each window. The averages of [2,-2] and [-2,4] are 0.0 and 1.0.
Example 3
values = [5,5,1,2]
windowSize = 3
k = 2
return = [1.0,1.0]
In [5,5,1], both occurrences of 5 are ignored. In [5,1,2], 5 and 2 are ignored. The only retained value is 1 in both windows.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Brute force sorts each window: O(n * w log w). It's correct and usually too slow. The better approach keeps the window split into two multisets: the top k values and the rest. Track the sum of the rest. When the window slides, remove the outgoing value from whichever side holds it, insert the incoming value, then rebalance so the top set has exactly k elements. Two heaps with lazy deletion work, or a sorted structure with order statistics. The pitfall is duplicates. If you track by value instead of by index, removing one 5 can wipe out the wrong copy. Store (value, index) pairs or use counts. Also handle k = 0 as an empty top set, and use long for sums to avoid overflow. If the rebalancing logic gets tangled mid-assessment, StealthCoder is the hedge that hands you a clean version while you stay in control of the submission.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Sliding Window Average Excluding the Largest K Values 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 passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Sliding Window Average Excluding the Largest K Values FAQ

What's the actual trick in this Google OA problem?+

Don't recompute each window. Maintain the window as two groups: the k largest and everything else. Keep a running sum of the non-top group, divide by windowSize - k, and rebalance after each slide. That turns the repeated sort into logarithmic updates.

How hard is this really?+

Medium-hard. The sliding window part is easy. The difficulty is deleting an arbitrary element from a heap-like structure and handling duplicates correctly. Candidates who only know the plain fixed-window sum pattern usually get stuck on the removal step.

Can I just sort each window to pass?+

It'll pass the small examples and likely time out on large hidden cases. Sorting each window costs O(w log w) per step. Use it as a correctness baseline, then switch to the two-group approach if you have time.

How do I handle duplicate values?+

Treat equal values as separate elements, as the problem says. Track entries as (value, index) pairs or use counts with lazy deletion. In Example 3, both 5s must be ignored when k = 2, so a set that collapses duplicates will give wrong answers.

What about the follow-up on huge or streaming input?+

The sliding approach already works on a stream, since it only needs the current window in memory. Memory is O(windowSize). For very large windows, mention a balanced tree or order-statistic structure, and say you'd emit each average as it's computed.

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

OA at Google?
Invisible during screen share
Get it