A stretch of the array that slides right, keeping its sum or its counts up to date as values enter and leave. Each value enters once and leaves once: O(n).
This interactive visualization needs JavaScript.