I don't getting the desired result . may you please help me


this is my code. i think it’s have to work properly but it showing me null pointer exception and i don’t know why.

Hi Aditya,
When you are constructing the tree from the array, the child nodes will be 2i+1 (left child) and 2i+2 (right child) and in the remove function don’t use the return type void but make it as a node and when child doesn’t exist return NULL.


i have update my code. it’s now showing the correct sample output . but in submission it shows wrong answer

Hi Aditya,
Add the following code snippet to your remove function:
if (node == null) {
return;
}
After that your remove function is complete. Also, since the array is not given in the form of inorder traversal of the tree, you need to make the tree using the add function in your code.

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.