All problems
1123MediumArrayMath

Stretches Holding Nothing but Zeros

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2348Number of Zero-Filled Subarrays

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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