713. Subarray Product Less Than K

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

On This Page

LeetCode problem 713

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