Is there is any other better way of doing this ques.?

So i solved this question by first sorting the array, and then traversing the array and checking for each element that if m-arr[i] exists(by doing binary search).

And the time complexity is O(nlogn),
but is there any other better way of doing this question?

hello @rohitmathur.mathur.6

after sorting u can use two pointer approach.
time compexity will remain same but its O(1) in space.

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.