The Hostel visit problem approach is not understandable
Help in the hostel visit problem
Hey Kaushik, we have to return Kth closest hostel, so to do this we can sort the hostels distance and return arr[k-1], but here we add hostels and so this technique becomes inefficient, for such updates priority queues comes to rescue as each operation(deletion and update) is confined to logN complexity. Now we maintain a maxheap of size k so whenever query of type 2 is done,we simply return topmost element, otherwise we insert hostel’s distance in our maxheap and if size exceeds k then we pop the nodes out to make size k. The reason of popping is that we don’t actually need hostel’s more than nearest K according to the question.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.