Getting tle in this ques
You have used a min heap for this problem. Using a max heap will be more efficient. Just think about it and try using a max heap.
So, maintain a k sized max heapā¦if size of heap becomes > k pop the top elementā¦the top element at any moment will be the kth nearest distanceā¦