I corrected the mistake.I am now outputting all answers at once; arr in now a dictionary and I cant think of further optimizations.The complexity is O(nlogn).
You're only one step away from getting AC.If you remove your code, I'll give you the final hint.
Final hint: Avoid unnecessary type conversions.
Thanks numerix!appreciate it.