root of a binary search tree: for every node, all keys in its left subtree are smaller than its key and all keys in its right subtree are larger. All keys are distinct.
Replace each node's key with the sum of its original key and every original key in the tree that is larger. The shape of the tree stays the same. Return the root of the updated tree (None for an empty tree).root=tree_node([6, 2, 9, None, 4]) → [15, 21, 9, None, 19]
9 is the largest key and stays 9. 6 gets 9 added and becomes 15, 4 gets 6 and 9 (19), and 2 gets all the others (21).
root=tree_node([-3, None, 5]) → [2, None, 5]
5 stays the same and -3 becomes -3 + 5 = 2.
root=tree_node([]) → None
Node.val ≤ 10⁴root=tree_node([6, 2, 9, None, 4])
[15, 21, 9, None, 19]
Run checks the first 3 tests in your browser. Submit checks all 55 tests on the server, hidden ones included.