Easy General

Running Average

Receives an array of integers and a window size w. It computes the average of every consecutive block of w elements: instead of re-adding each window from scratch, it keeps a running sum and slides the window one position at a time — adding the value that enters on the right and subtracting the one that leaves on the left — so the whole pass costs O(n). Each average is rounded to two decimals. Returns an array with one average per window, in order; if w is larger than the array (or not positive) it returns an empty array, and when w equals the array length it returns a single average.

Visualization

Input

Algorithm code

Custom input

Saved inputs

References