Stack Bash - Master data structures and algorithms

Sum of all nodes in Binary Tree

Easy
Given a binary tree that contains nodes with numbers, calculate the sum of all the nodes in the tree.
For example, let's say you're given the following binary tree:
Binary Tree Example
Your fuction should return 27, the sum of all nodes.

Try it

Solution

9 Essential Trees & Graphs Coding Interview Problems

Master Trees & Graphs by trying the coding challenges below.
  1. 1.Inorder TraversalEasy
  2. 2.Tree SumEasy
  3. 3.Tree HeightEasy
  4. 4.LCAMedium
  5. 5.Max Path SumHard
  6. 6.Search mazeMedium
  7. 7.Number of islandsMedium
  8. 8.Kth SmallestMedium
  9. 9.Sort K ArraysHard

Want to confidently pass your next coding interview?

Stack Bash helps new and veteran software engineers master data structures and algorithms for technical interviews.