Given an unbalanced rooted tree, how would you replace each node's value with the sum of all the values in its subtree that are smaller than the node's value?
Example
Input:
Output:
Input:
1 2 3 4 5 6 7 | . 60 / \ 50 10 / \ 80 70 | 40 |
Output:
1 2 3 4 5 6 7 | . 100 / \ 40 0 / \ 40 0 | 0 |
Read full article from (5) Given an unbalanced rooted tree, how would you replace each node's value with the sum of all the values in its subtree that are smaller than the node's value? - Quora