Sir please check my code


i dont know where iam failing

Hello @pankajsingh,

The wrong output is due to incorrect way building BST in this problem.
sort(arr,arr+n);
node* root=buildbst(arr,0,n-1);
This will change the actual root of the tree.

Solution:
You have given the pre-order of the tree itself.
So, taking the first element of the input as the root, build the BST.

Hope, this would help.
Give a like if you are satisfied.

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.