Practice Binary Search Tree to Greater Sum Tree
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Medium#1038
LeetCode ProblemBinary Search Tree to Greater Sum Tree
Problem Statement
In the given binary search tree, replace each original value with itself plus the sum of all original values greater than it. For each node, every value in its left subtree is smaller than that node’s value, and every value in its right subtree is larger. Return the transformed tree.
Source: Binary Search Tree to Greater Sum Tree on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
root = [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]
Output
[30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]
# Example 2
Input
root = [0,null,1]
Output
[1,null,1]
Constraints
The number of nodes in the tree is in the range [1, 100].
0 <= Node.val <= 100
All the values in the tree are unique.
Related LeetCode Problems
Practice more problems similar to Binary Search Tree to Greater Sum Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.