Replace with sum of nodes

How to solve this questions
Please give me just hint.
We can add all elements in right but how will we go back to its parent

To solve this question we begin with the basic O(n^2) approach:
we traverse the whole tree for each node and keep track of the sum of the nodes that are greater that than node.
But we can do this in single traversal O(n) approach.
Think of it. Something related to modification of inorder traversal.

Reply if resolved :slight_smile: