β back to unit
Medium
# queues medium
The Moving Average
One weird reading shouldn't panic anyone β the smart display shows the AVERAGE of the last k readings. π
You get the readings and window size k. Starting from the moment the window is full, print each window's average (they always come out whole), space-separated.
Example:
Input: readings = [1, 3, 5, 7, 9], k = 2
Output: 2 4 6 8
Once the window holds 2 readings, each average is the running total divided by 2: (1+3)/2=2, (3+5)/2=4, (5+7)/2=6, (7+9)/2=8.
π‘ need a hint?
q-moving-average.pyπ given lines are locked β write your code in between
loading...