Given an array arr = {5, 16, 4, 7}, we can sort it through sort(arr, arr+sizeof(arr)/sizeof(arr[0])).
so now the array arr = {4, 5, 7, 16}
Yes, there is one with O(NlogN) time.Since the sorting takes O(NlogN) time anyway, this will not affect overall time complexity.
Time Complexity: O(NlogN)
Space Complexity:O(N)
where N=number of elements in input array
Algorithm: