less than 1 minute read

Given a binary search tree root, replace every node’s value v by its value plus the sum of all other values in the tree that are greater than v.

Constraints

  • n ≤ 100,000 where n is the number of nodes in root

https://binarysearch.com/problems/Enlarge-BST

Examples

Example 1

Input

  • root =

Output

  • answer =

Solution

Leave a comment