Replace sum of greater nodes

how to solve this provblem

@Faizan-Ali-1395131367301898
There are several ways to go about this problem.
One of the easiest ways is to take the input array and modify it before making a tree out of it. Modify the array by taking the cumulative sums right to left. By doing this we are just using a simple property of BST that its inorder traversal is sorted. Then simply make a tree out of the resultant array.