Doubt in hackerEarth question Last Ant On Road

Can someone please explain me the logic behind the solution of the question : Last Ant On Road | Practice Problems and also availbale here CodeChef: Practical coding for everyone. The correct answer is the “index of first mismatch chracter”(got AC with this logic : CodeChef: Practical coding for everyone) starting from beginning of the array if both +1 and -1 are present in the array.

I am unable to find any justification for that logic to be correct and also have got some counter test cases which do not support the index of first mismatch as the correct answer.

Counter test cases :
2

5

1 -1 1 -1 1

4

1 1 1 -1

thanks in advance! :slight_smile: