Given the root of a Binary Search Tree (BST), convert it into a Greater Sum Tree (GST).
In a Greater Sum Tree, the value of each node is updated to be the sum of its original value plus the sum of all keys in the original BST that are greater than the node’s original value.
Recall that a Binary Search Tree satisfies the following conditions:
The left subtree of a node contains only nodes with keys strictly less than the node’s key.
The right subtree of a node contains only nodes with keys strictly greater than the node’s key.
Both the left and right subtrees must also be binary search trees.
Constraints:
The number of nodes in the tree is in the range
Node.val
All the values in the tree are unique.
Given the root of a Binary Search Tree (BST), convert it into a Greater Sum Tree (GST).
In a Greater Sum Tree, the value of each node is updated to be the sum of its original value plus the sum of all keys in the original BST that are greater than the node’s original value.
Recall that a Binary Search Tree satisfies the following conditions:
The left subtree of a node contains only nodes with keys strictly less than the node’s key.
The right subtree of a node contains only nodes with keys strictly greater than the node’s key.
Both the left and right subtrees must also be binary search trees.
Constraints:
The number of nodes in the tree is in the range
Node.val
All the values in the tree are unique.