Can someone please explain me the logic behind the solution of the question : https://www.hackerearth.com/problem/algorithm/last-ant-on-road/description/ and also availbale here https://www.codechef.com/UEMC2017/problems/UEMCOSA/. The correct answer is the “index of first mismatch chracter”(got AC with this logic : https://www.codechef.com/viewsolution/16006362) 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!