3
// calculate required moves in postorder manner4
int traverse(TreeNode *root, int &moves) {7
// left subtree excess amount coin8
int left = traverse(root->left, moves);10
// right subtree excess amount coin11
int right = traverse(root->right, moves);13
// moves needed to neutralize the excess amount of coins of left and right15
moves += abs(left) + abs(right);17
// current subtree including current root excess amount is18
// total coins in the subtree - total nodes in the subtree19
// left and right subtree excess amount coin + root coin -120
return root->val + left + right - 1;23
int distributeCoins(TreeNode *root) {25
traverse(root, moves);