Interview Query

Moving Window

Start Timer

0:00:00

Upvote
16
Downvote
Save question
Mark as completed
View comments (34)
Next question

Given a list of numbers nums and an integer window_size, write a function moving_window to find the moving window average.

Example 1:

Input:

nums = [1,2,3,4,5,6]
window_size = 3

Output:

def moving_window(input, window_size) -> [1, 1.5, 2, 3, 4, 5]

Example 2:

Input:

nums = [1,2,3,4,5,6]
window_size = 4

Output:

def moving_window(input, window_size) -> [1, 1.5, 2, 2.5, 3.5, 4.5]
.
.
.
.
.


Comments

Loading comments