Given a Binary Tree, compute the sum of all the branches in the tree. 1 branch is the path from the root to a leaf.
We are going to use recursion to solve this problem. But it is important to understand what a branch is.
Consider the binary tree
 / \  
sumarray variable, that will keep count on the total sum value that is being calulated.
runningSumto the global
sumsand initialize it to an empty array.
branchSumsHelper(tree, runningSum, sums)helper method that we will use to recurse.
left subtreeand no
right subtree. This means that the node we are currently at is a
leaf node, push it to the
sumsarray and return from the recursion.
branchSumsHelper(tree.left, newRunningSum, sumsArray)and
branchSumsHelper(tree.right, newRunningSum, sumsArray)
runningSumvariable takes care of the current sum that we are adding, hence, we compute the running sum as
newRunningSum = runningSum + tree.value;
O(n)- Because the tree can be a skewed tree.