Number of Zero-Filled Subarrays

Given an integer array nums, return the number of subarrays filled with 0. A subarray is a contiguous non-empty sequence of elements within an array.

30:00

Number of Zero-Filled Subarrays
medium
Free written solution
Topics
Companies

Given an integer array nums, return the number of subarrays filled with 0. A subarray is a contiguous non-empty sequence of elements within an array.

Example 1:
Input: {"nums":[1,3,0,0,2,0,0,4]}
Output: 6
Constraints:
  • 1≤nums.length≤1051 \leq \text{nums.length} \leq 10^5

  • −109≤nums[i]≤109-10^9 \leq \text{nums[i]} \leq 10^9

  • Here the answer fits in a 32-bit int (LeetCode returns a 64-bit long).

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[1,3,0,0,2,0,0,4]}

Count subarrays made only of 0s in 8 elements. Every such subarray ends at some 0.

run = 0
n = 8

nums · bars = zero-filled subarrays ending at i

0

1

2

3

4

5

6

7

1
3
0
0
2
0
0
4

total

0

Variables
VariableValue
n8
DepthFunction Call
Stack empty
0/15