i did this question using heapsort, then why is it giving memory limit exceeded ?? what’s the better solution
Instead of heapsort, use a max heap that maintains K elements and whenever there is a number that is less than the top of the heap, remove the top and insert that element, after looping through the entire list you will have the answer at the top of the heap.
I have used a max heap(priority_queue) yet it is throwing a MLE.