Please help me out solving the hostel visit question as i have tried but not able to pass test cases

Is it possible to talk on phone and can discuss the solution given ?

@gupta.ritik2002
no bro i cant because then evryone will call. you can ask here i will try to clear it

@gupta.ritik2002
right now what issue u r facing

@gupta.ritik2002
the approach for hostel visit is simple
we will maintain a max heap of size k .

a) if size of max heap is less than k then we simply push current hostel (distance)in max heap
b) otherwise we check whether top hostel(distance) of heap is less than current hostel(distance) or not.
…if current hostel distance is less that top hostel distance then we pop top hostel distance and then push current hostel distance

1 Like

@gupta.ritik2002
and the problem i gave to solve is exactly similar to hostel visit .only difference is there we have one dimensionL points and here it is two dimension (which we can convert into 1 d by distance formula)

Sir I have a simple question that why we are not maintaining the min heap of k elements

If we encounter any min distance then we compare it with root and push

@gupta.ritik2002
but min heap top value will give most nearest hostel distance (we considered so far) right?.
but we want farthest hostel so that if current hostel distance is less that farthest hostel distance we can replace farthest hostel with current hostel .

Thankyou sir I understood the problem ,now i will try implementing the concept in the ide

1 Like

@gupta.ritik2002
finally :stuck_out_tongue_winking_eye: