-Hostels visits _heap challange

one testcase gives timelimt
please guide me

@kumar_07
Your approach is not optimised. Your type 2 query takes O(k) time to print the kth element and it takes O(log n) time to insert a new element into your heap where n is the size of the heap. Instead try to change the approach so that the kth element can be printed in O(1) time and insertion can be done in O(log k) time. You can do this by making a max heap of size k. Try to think of this approach and let me know if you need any help.

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.