Delete nodes from BST

TestCase 2 & 5 are passing but rest are not. Could you correct the code. I tried but I am not getting it

@yashomar95, Here is the corrected code. You can avoid using if as it will only increase computation. Use else if. Also I deleted some unnecessary conditions and removed the parent node entirely as it was throwing errors.

So,the approach I used earlier using the parent is not suitable if the parent is null ?

It was throwing nullpointer exception when parent was null. So I would say this is a better approach and more suitable.

Please mark your doubts as resolved, if your doubt is resolved. :slight_smile:

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.