Geeksforgeeks

Error

Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater than that node.

**Example 1:**

**Input:**
2
/ \
1 6
/ \
3 7
**Output:** 18 16 13 7 0
**Explanation:**
Every node is replaced with the
sum of nodes greater than itself.
The resultant tree is:
16
/ \
18 7
/ \
13 0

**Example 2:**

Input:2 / 1Output:2 0Explanation:The resultant tree is : 0 / 2

You don't have to read input or print anything. Your task is to complete the function **transformTree() **which takes the root of the tree as input and transforms the BST to a greater sum tree.

1 ≤ N ≤ 10^{4}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

BST to greater sum tree

...