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?