Copied to Clipboard
Sum of Left Leaf Nodes
Easy Accuracy: 49.98% Submissions: 22357 Points: 2

Given a Binary Tree of size N. Find the sum of all the leaf nodes that are left child of their parent of the given binary tree.

Example 1:

     /   \
    2     3
Output: 2

Example 2:

Input : 
        /  \
       2    3
     /  \     \
    4    5     8 
  /  \        /  \
 7    2      6    9
Output: 13
sum = 6 + 7 = 13

Your Task:
You don't need to read input or print anything. Your task is to complete the function leftLeavesSum() which takes the root node of the tree as input and returns the sum of all the left leaf nodes present in the given binary tree.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).

1<=Number of nodes<=105

Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Sum of Left Leaf Nodes

Output Window