The "Sum of Left Leaves" problem asks you to find the sum of all leaf nodes that are left children in a binary tree. A "leaf" is a node with no children. A "left leaf" is a leaf node that is the left child of its parent. For example, in a tree where the root 3 has a left child 9 and a right child 20 (and 20 has children 15 and 7), the only left leaf is 9 and 15.
This "Easy" level problem is a staple at Amazon, Meta, and Bloomberg. It tests a candidate's ability to perform tree traversals (DFS or BFS) and their ability to pass state through recursive calls. Specifically, it tests whether a candidate can distinguish between a general left child and a left leaf.
The pattern used is Tree Traversal (Depth-First Search or Breadth-First Search).
child.left == null && child.right == null. If it is, add its value to the sum.Consider this tree:
3
/
9 20
/
15 7
root.left.left).Always clarify the definition of a "leaf." For tree problems, practice both recursive and iterative solutions. Recursive solutions are often cleaner for trees, but iterative solutions using a stack or queue demonstrate a deeper understanding of memory management.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Depth of Binary Tree | Easy | Solve | |
| Average of Levels in Binary Tree | Easy | Solve | |
| Cousins in Binary Tree | Easy | Solve | |
| Merge Two Binary Trees | Easy | Solve | |
| Find a Corresponding Node of a Binary Tree in a Clone of That Tree | Easy | Solve |