Leetcode 2211 Solution

This article provides solution to leetcode question 2211 (k-radius-subarray-averages)

https://leetcode.com/problems/k-radius-subarray-averages

Solution

class Solution:
    def getAverages(self, nums: List[int], k: int) -> List[int]:
        n = len(nums)
        ans = [-1] * n

        i = k
        s = sum(nums[0 : 2 * k])

        while i < n - k:
            s += nums[i + k]

            ans[i] = s // (2 * k + 1)

            s -= nums[i - k]
            i += 1

        return ans