Back to DSA sheet
Number of Zero-Filled Subarrays
MediumArraysReturn the number of subarrays made up entirely of zeros. A run of length L of zeros contributes L*(L+1)/2 such subarrays.
Input format (stdin): the first line has n. The second line has n integers. Output the count.
Examples
Input: 5
1 3 0 0 2
Output: 3
[0],[0],[0,0] = 3 subarrays.
Input: 6
0 0 0 2 0 0
Output: 6
A run of 3 gives 6, plus a run of 2 gives 3... wait
Constraints
- 1 <= n <= 10^5
- -10^9 <= nums[i] <= 10^9
Sheets
NeetCode 250
number-of-zero-filled-subarrays.cpp3 sample tests
Loading editor
Test results
Run the sample tests to check your solution against expected output.
Custom input (stdin)
Output
Run your code to see its output.