Skip to content
LC-2348 Medium LeetCode

2348. Number of Zero-Filled Subarrays

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 67% Topics: Array, Math
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

# two pointers, combinatorics
class Solution(object):
    def zeroFilledSubarray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        result = 0
        prev = -1
        for i in xrange(len(nums)):
            if nums[i]:
                prev = i
                continue
            result += i-prev
        return result

Solution from kamyu104/LeetCode-Solutions · MIT