fork(1) download
  1. t=input()
  2. z=0
  3. for i,e in enumerate(t):
  4. if e:
  5. while z:t[i-z]=e+z if l>e else e-z;z-=1
  6. l=e
  7. else:z+=1
  8. print t
Success #stdin #stdout 0.01s 9016KB
stdin
[1, 0, 0, 0, 5, 6, 0, 4, 0, 0, 1]
stdout
[1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]