I have got an array containing unique elements. I need to find out the first n largest elements in the array in the least complexity possible. The solution that I could thin
The usual trick to select the n largest elements is to maintain a min-priority queue.
Total complexity: O(N log n) where N is the total number of elements in the array.
I leave to you as an exercise the implementation details (first step is to learn about priority queues, and implement one).