Please Help me get the logical mistake here:

I am first making an array of pairs<x coordinate,id of frog> and sort it accn to first parameter.
After that i amking a dp array , index of which is frog id and value is the id of leftmost frog which it can communicate to.

Now for each query i iteratively checks whether the value of the dp array at index of sender frog id matches with recipent frog id and breaks when -1 is encountered.

I can’t figure out why you are you starting j from n-1. As queries could also go up to 105 So I think your code will give TLE.
Here is my solution.


as hello_hell mentioned, you code will be too slow even if it works.

here is my submission.

i did very same thing as you did… i made sets of the pairs and checked in query if two query points lie in same set, if yes YES else NO.

1 Like