TLE error for one case. Suggest any change

Logic is right, but the TLE thing is coming up for one test case. What other way can you suggest in this approach I followed?

hello @neelkanthpoosa

ur solution has o(n^2) time complexity thats why it is showing tle.

use map to reduce its complexity

refer this-

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.