SOLVED & EXPLAINED | Sum of Left-Most-Nodes – Binary Tree

Challenge:

The input for this challenge will provide an array of numbers in the above “breadth-first” format, and use 0’s for non-nodes. Can you print out the sum of the Leftmost side of the Tree?

Tip: A number located at position i in an array will have it’s left child located at the position 2i+1 in the array.

Test case example:
leftmostNodesSum([2, 7, 5, 2, 6, 0, 9])
// = 11
Go down the left-hand side of the tree to get the sum: 2+7+2 = 11. You can take a look at the image of the tree above.
——————————–
function leftmostNodesSum(array) {
// your code here
}

console.log(leftmostNodesSum([2, 7, 5, 2, 6, 0, 9]))
———————————

——
Join free Membership Community – https://tinyurl.com/geekspecials
Connect on LinkedIn – https://www.linkedin.com/in/eloghene-otiede
——-

Leave a Reply