Grokking Tree Coding Patterns for Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Sum of Left Leaves (easy)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given the root of a binary tree, return the sum of all left leaves.

A leaf is a node that does not have any child nodes, and a left leaf is a leaf that is the left child of its parent.

Examples

Example 1:

  • Input: root = [3,5,10,null,null,8,7]
Image
  • Expected Output: 13
  • Justification: The leaf nodes are 5, 8, and 7, but only 5 and 8 are left leaf nodes. So, sum of left leaf nodes are 5 + 8 = 13.

Example 2:

  • Input: root = [5, 3, 8, 2, 4, null, 6, 1]
Image
  • Expected Output: 1
  • Justification: The only left leaf node is 1 (left child of 2). So, the answer is 1.

Example 3:

  • Input: root = [1, null, 5, null, 4]
Image
  • Expected Output: 0
  • Justification: The tree doesn't have any left leaf node.

Constraints:

  • The number of nodes in the tree is in the range [1, 1000].
  • -1000 <= Node.val <= 1000

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible