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

0% completed

Solution: Sum of Left Leaves
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]
  • 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]
  • Expected Output: 1

.....

.....

.....

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