I have been given an array of elements and an inbuilt function which can sort 5 elements at a time. How do I use only this function to obtain the largest 3 elements of the array with the least number of calls to this function?
The approach I have tried is dividing the array in groups of 5 each, applying the function on each group, and applying the function on the maximums obtained from each group.
This approach fails when the highest and second highest happen to be present in the same group. Is there a better approach to do this?