Show problems as
Classic problem #2348MediumArrayMath

Number of Zero-Filled Subarrays

Real-world version: Stretches Holding Nothing but Zeros
Tracked in this browser only
Read Number of Zero-Filled Subarrays on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A log holds the readings readings.

Return how many stretches of one or more neighbouring readings hold nothing but zeros.

Examples

Example 1

Input
readings = [0, 0, 0]
Output
6

Three single zeros, two neighbouring pairs and the whole run come to six stretches.

Example 2

Input
readings = [0, 1, 0]
Output
2

Each zero stands on its own, so only the two one-reading stretches count.

Example 3

Input
readings = [0, 0, 1, 0, 0, 0]
Output
9

The run of two zeros gives three stretches and the run of three gives six.

Constraints

  • 1 <= readings.length <= 10^5
  • -10^9 <= readings[i] <= 10^9

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def zero_filled_subarray(readings: list[int]) -> int:
Java
public long zeroFilledSubarray(int[] readings)