Premium problem28. Distance to Previous Zero

Hard Locked

df has an integer column 'X'. For each value, count the distance back to the previous zero (or the start, whichever is closer). Return this as a Series.

Input

   X
0  7
1  2
2  0
3  3
4  4
5  2
6  5
7  0
8  3
9  4

Output

0    1
1    2
2    0
3    1
4    2
5    3
6    4
7    0
8    1
9    2
Name: Y, dtype: int64

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)