how can I make the heap in O(K) time and space?
Regarding optimising the code
hello @Senjuti256
if we have N rows in the matrix , then we need atleast O(N) time and O(N) space to build the heap , we cannot improve it furthur.
and after that we need to heafiy it k time which will make overall time complexity ->O(K Log N) and space-> O(N).
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.