Given a binary tree containing n nodes. The problem is to get the sum of all the leaf nodes which are at minimum level in the binary tree.
Input : 1 / \ 2 3 / \ / \ 4 5 6 7 / \ 8 9 Output : 11 Leaf nodes 4 and 7 are at minimum level. Their sum = (4 + 7) = 11.
Approach: Perform iterative level order traversal using queue and find the first level containing a leaf node. Sum up all the leaf nodes at this level and then stop performing the traversal further.
Sum = 11
Time Complexity: O(n).
Auxiliary Space: O(n).
- Print Leaf Nodes at a given Level
- Difference between sums of odd level and even level nodes of a Binary Tree
- Connect Nodes at same Level (Level Order Traversal)
- Find depth of the deepest odd level leaf node
- Delete leaf nodes with value as x
- Delete leaf nodes with value k
- Sum of all leaf nodes of binary tree
- Print all leaf nodes of an n-ary tree using DFS
- Determine the count of Leaf nodes in an N-ary tree
- Print all nodes that are at distance k from a leaf node
- Count Non-Leaf nodes in a Binary Tree
- Product of all leaf nodes of binary tree
- Maximum sum of leaf nodes among all levels of the given binary tree
- Remove nodes on root to leaf paths of length < K
- Root to leaf path with maximum distinct nodes
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.