Time Limit exceeding

Time Limit exceeding please check

Hi @souravmunjal2000
You are facing TLE because of the cost of sorting the array again and again.If number of queries are large enough, then TLE will be faced.
Try to solve the problem using priority_queue /heaps.
Pop k-1 elements from heap and get the kth nearest distanced hostel and add them back to the heap.
I hope this helps you solve your problem.
Please mark the thread resolved if so :slight_smile: