2090. K Radius Subarray Averages

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2090

class Solution:
    def getAverages(self, nums: List[int], k: int) -> List[int]:
        s = 0
        res = [-1] * len(nums)
        for i, v in enumerate(nums):
            s += v
            if i >= k * 2:
                res[i - k] = s // (k * 2 + 1)
                s -= nums[i - k * 2]
        return res