WRONG ANSWER Error

I have written the code and it’s working perfectly for the given testcase.
Please look into the code as I am facing wrong answer error while I submit the code.

@mananaroramail,
Your tree construction is wrong. The nodes have to be added to tree in the order in which they are given.

If I don’t sort the array then how can I make a function for deleting the nodes in a BST. Also if I don’t sort the array then it violate the very basic property of a BST.

@mananaroramail,
you need to write an “add” function which will add the nodes according to the order given.
I have given a start
void add(node root,int item) {
if(root.data<item) {
if(root.right==null) {
node node =new node();
node.data=item;
root.right=node;
}else {
add(root.right,item);
}
}else { … Please complete the function.

This approach worked but I am still facing run errors while submitting the code. Please look into the code.

@mananaroramail,
1
56
961 925 815 342 102 70 864 753 610 148 422 209 350 481 485 885 850 41 78 688 816 104 651 475 61 89 244 194 708 184 512 888 116 386 728 884 874 124 456 776 730 905 95 359 90 264 607 511 261 788 536 581 463 504 200 402
10
512 850 184 244 264 485 815 261 961 124

This test case will give nullpointer exception.

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.