Getting NZEC in FROGV

https://ideone.com/64PMJ8 <====solution

https://www.codechef.com/problems/FROGV <==== problem

NZC- runtime error.

Thanks! any idea of reason why i am getting NZEC, is there any flaw in my logic?

See ur for loop.Ur for loop starts from 0,and u have written arr[i-1]->arr[-1]

@vivek_1998299 https://www.codechef.com/viewsolution/17610706 -TLE error

:frowning: i have tried like 10 times by now ! i guess my algorithms must be wrong…

Obviously it will time out,it is O(N) per query -> O(N*N).U could do this,sort the things based on x cordinate(keeping track of which index they prev were).Now U could just divide them to connected components,like (1,2,3),(5,6),(7,8,9) could be connected(ie all are reachable),so for query u just have to check if their components are same.

If u dont understand u can refer the editorials.