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
You can use a Priority Queue using Heap (maxHeap) to solve this. Perform heap n times to get the first n largest elements. Each Heap operation takes O(log N) time, so N heap operations would result in O(N log N) time.