What is wrong with this code?
Shreya, you are using wrong approach in building the tree, if not given, you should use native approach to build your tree, as,
if(root==NULL)
{
return new node(data);
}
if(data<=root->data)
{
root->left=insertInBST(root->left,data);
}
else
{
root->right=insertInBST(root->right,data);
}
return root;
Only change this approach, and then try to submit the code.
but what is wrong with that approach?
Actually, whenever you are given the array only, you need to see that if array is in sorted order or not, then only your array to Bst approach will be valid… otherwise you need to use only the native approach for building the tree.