Leetcode 2211 Solution
This article provides solution to leetcode question 2211 (k-radius-subarray-averages)
Access this page by simply typing in "lcs 2211" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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