Replace with sum of greater nodes

for any inorder more than one number of BST are possible so they will have a different preorder so how did the question come to a conclusion to a particular BST ???

Are you confuse about constructing tree?

yes in question it is not clearly mention
but after seeing the sample input you can observe that
middle element is root node
right part is right subtree and left part is left subtree

implementation will be like this

Node* BuildTree(int*inorder,int s, int e){
	if(s>e)
		return NULL;
	int mid = (s+e)/2;
	Node*root = new Node(inorder[mid]);
	if(s==e)
		return root;

	root->right = BuildTree(inorder,s,mid-1);
	root->left = BuildTree(inorder,mid+1,e);
	
	return root;
}

i did it in this way

but can this problem be solved by doing operation on BST and is yes what should be the approach

this will give correct output but
this is not actually what you have to do

you have given a bst and then change the value of nodes in it

Reference 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.