Let's say I have a NumPy array:

```
x = np.array([0, 1, 2, 0, 4, 5, 6, 7, 0, 0])

```

At each index, I want to find the distance to nearest zero value. If the position is a zero itself then return zero as a distance. Afterward, we are only interested in distances to the nearest zero that is to the right of the current position. The super naive approach would be something like:

```
out = np.full(x.shape[0], x.shape[0]-1)
for i in range(x.shape[0]):
    j = 0
    while i + j < x.shape[0]:
        if x[i+j] == 0:
            break
        j += 1
    out[i] = j

```

And the output would be:

```
array([0, 2, 1, 0, 4, 3, 2, 1, 0, 0])

```

I'm noticing a countdown/decrement pattern in the output in between the zeros. So, I might be able to do use the locations of the zeros (i.e., `zero_indices = np.argwhere(x == 0).flatten()`)

What is the fastest way to get the desired output in linear time?