Practice Convert BST to Greater 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#538
LeetCode ProblemConvert BST to Greater Tree
Problem Statement
In the given binary search tree with distinct keys, replace each node value with its original value plus the sum of all original keys greater than it. Return the resulting tree. Left-subtree keys are strictly smaller and right-subtree keys strictly larger, recursively throughout the tree.
Source: Convert BST to Greater 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 [0, 10^4].
-10^4 <= Node.val <= 10^4
All the values in the tree are unique.
root is guaranteed to be a valid binary search tree.
Related LeetCode Problems
Practice more problems similar to Convert BST to Greater Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.