Take an example ==> (1,3,-1,-3,2,5,6,7,-5)
"How much time it will take to select a number say k which is neither k-th minimum nor k-th maximum"
take k = 2 ,which is neither 2nd min nor 2nd min , right ...
Complexity to find k smallest or largest elements in an array by min heap is ==>
1. Make a min heap = O(n)
2. remove K elements = O(k logn) , so, total O(n + k logn) .
Similarly , using max heap = O(n + k logn) to find max. k elements ...
Hence, total will be O(n + klogn) (sry i wrote k logk , as i treated it different question) .
Space complexity is higher, as we need 2 heaps now .