Its not doing anything great or mysterious.
The output of this program comes as
[4, 3, 2, 1, 1]
[0, 0, 0, 0, 0]
For first loop it assigns the value as length -i .. and then i +1..
You can simply take a pen paper and get the same desired result in no time.
or if you want to calculate values at each step you can simply debug the program.
Thanks
Sourabh