Hostel Visit - Problem

Hy
My code is passing not passing last test case because of TLE , can you suggest me any optimisation I can apply to get kth element from heap without loosing any element.

code : https://ide.codingblocks.com/s/679410

Hi @akshatjain4545
For every query of type 1, insert elements until the size of the heap becomes ‘k’.
Then for every query of type 1 after reaching the size k for heap(max-heap) we will check if the current element is smaller than the root of the heap or not. If it is not smaller then we ignore it else we remove the root of the heap and push the new element in the heap. (What this will do is maintain a heap of size k which will contain k nearest coordinates for the dean) .
For every query of type 2 just print the root of the heap.

reference code

@talhashamim001
Thanks sr great approach to only insert only required element
:grin:

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.

1 Like