Practice the most popular front-end questions asked in coding interviews with Frontend Churn

00:00:00

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.

Consider the binary tree

```
[1]
/ \
[2] [3]
```

```
Output: [3, 4]
```

- Left branch sum =
`[1]-[2]`

=`3`

- Right branch sum =
`[1]-[3]`

=`4`

- Output:
`[3, 4]`

```
The number of nodes in the tree is in the range [0, 5000].
-1000 <= BinaryTree.value <= 1000
```

Click to reveal

Try creating a helper function that takes into account a `Global Sums`

array and a `Running Sum`

variable to keep into account the summations of values

Click to reveal

Check if the node you're currently at is a leaf node or node. Can it help you reaching the base case?

Uploaded by: Manu Arora

Share this problem on