Doubt in hackerEarth question Last Ant On Road

Can someone please explain me the logic behind the solution of the question : and also availbale here The correct answer is the “index of first mismatch chracter”(got AC with this logic : 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 :


1 -1 1 -1 1


1 1 1 -1

thanks in advance! :slight_smile: