whats wrong with this approach
Replace with sum of greater nodes
You can simply create a function :
void BSTsum(node *root)
{
int sum=0;
modifysum(root,&sum);
}
and then modifysum function will be somewhere similar as,
void modifysum(node *root,int *sum)
{
if(root==NULL)
{
return;
}
modifysum(root->right,sum);
*sum=*sum+root->data;
root->data=*sum;
modifysum(root->left,sum);
}
This is the basic approach you can follow, we have used*sum to indicate the changes in the values,
thanks !!
but whats wrong with my approach ?? can u tell the mistakes ??@ yuktimutreja01
For other cases, your code was not producing correct results,as in your code, you have used, ar2[i]=350;, but the other test cases will not have such values, thats why…