2302. Count Subarrays With Score Less Than K

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

On This Page

LeetCode problem 2302

class Solution:
    def countSubarrays(self, nums: List[int], k: int) -> int:
        res = s = j = 0
        for i, v in enumerate(nums):
            s += v
            while s * (i - j + 1) >= k:
                s -= nums[j]
                j += 1
            res += i - j + 1
        return res