Unlock-Competitive

Can u please explain why am i getting run error in this code.

Well you should declare arr[N] once you know N.
Declare it after getting N.
That’s why you are getting runtime error.

I hope i have cleared your doubt. You may close the thread if so :smile:

But still i am getting time limit exceeded error.
Can u help me with that

You are doing it in O(n^2) time when constraints are 10^5.
Think of a better approach.

can u suggest me of a better approach?

Use map to memorize locations.
Its easy to understand. See here how

thanks for ur help.This was a nice approach