Solution Review: Sum of All Nodes in a Binary Tree

Let’s take a detailed look at the previous challenge’s solution.

We'll cover the following


We’ll calculate the sum of nodes by recursion. First, the sumAllBT() function will return the sum of all the nodes in the left subtree and then the nodes in the right subtree. Finally, we’ll add the value of the current node to this sum and return the final sum.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.