Untitled
unknown
plain_text
5 months ago
472 B
15
Indexable
Write a function to compute the moving average of a list of integers with a given window size k. The moving average is the mean of the last k elements in a sliding window. def moving_average(arr: List[int], k: int) -> List[float]: pass Input: arr = [1, 2, 3, 4, 5] k = 3 Output: [2.0, 3.0, 4.0] # Averages for windows [1,2,3], [2,3,4], [3,4,5] Input: arr = [5, 10, 15, 20, 25, 30] k = 4 Output: [12.5, 17.5, 22.5] Input: arr = [1, 2] k = 5 Output: [ ]
Editor is loading...
Leave a Comment