You are given the root node of a Binary Search Tree (BST). Your task is to convert the BST into a Greater Sum Tree such that every node’s value becomes the original node value plus the sum of all node values that are greater than it in the tree.
A Binary Search Tree follows these rules:
Values in the left subtree are strictly smaller than the node’s value.
Values in the right subtree are strictly larger than the node’s value.
Both left and right subtrees must also satisfy the BST property.
Your goal is to adjust the node values accordingly and return the modified root.
Input: root = [5,3,8,2,4,7,9]
Output: [24,31,17,33,30,24,9]
Explanation:
Each node value is replaced with itself + sum of values greater than it.
Input: root = [2,1,3]
Output: [5,6,3]
Accepted:
Submission: