We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Let me try to understand your case with an example. The heap elements can be:
- 1 12 5 13 20 6 7
Assuming we are required to delete 13, what my code does is swap the last element, 7 with the fourth element, 13. Now the heap is:
- 1 12 5 7 20 6
Here, 7 is the child of 12. The heap property is violated. So, either 7 must swim() or 12 must sink() But my code does not cover this case. So you are absolutely correct. Thank you. I will update my code accordingly.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
QHEAP1
You are viewing a single comment's thread. Return to all comments →
Let me try to understand your case with an example. The heap elements can be: - 1 12 5 13 20 6 7
Assuming we are required to delete 13, what my code does is swap the last element, 7 with the fourth element, 13. Now the heap is: - 1 12 5 7 20 6
Here, 7 is the child of 12. The heap property is violated. So, either 7 must
swim()
or 12 mustsink()
But my code does not cover this case. So you are absolutely correct. Thank you. I will update my code accordingly.