The tests write a tree as a level-order list (row by row, left to right) with None for a missing child: [3, 9, 20, None, None, 15, 7] is a root 3 with children 9 and 20, where 20 has children 15 and 7. All trees in this topic that are called BSTs have different values.
Change the tree so that every node's value becomes the original value plus the sum of all original values greater than it. Return the root.
For [4, 1, 6, 0, 2, 5, 7, None, None, None, 3, None, None, None, 8] the answer is [30, 36, 21, 36, 35, 26, 15, None, None, None, 33, None, None, None, 8].
Example 1
Input:
convert_bst(root) # root = [4, 1, 6, 0, 2, 5, 7, None, None, None, 3, None, None, None, 8]
Output:
[30, 36, 21, 36, 35, 26, 15, None, None, None, 33, None, None, None, 8]
Example 2
Input:
convert_bst(root) # root = [0, None, 1]
Output:
[1, None, 1]
0 <= number of nodes <= 1000000 <= val <= 10**4No results yet
Run your code to check it against the examples, or submit to run every test.