USACO Bronze 2018 Angry Cows

Hello I looked at the official solution of this problem on USACo.guide and I don’t get why and how using 1 and -1 allows us to traverse the array right and left