The Deepest Leaves Sum interview question tasks you with finding the sum of the values of the nodes that are at the maximum depth of a binary tree. This Deepest Leaves Sum coding problem involves two steps: identifying the maximum depth and then summing the nodes at that depth.
Companies like Google and TikTok ask this to test your tree traversal skills. It evaluates if you can use Breadth-First Search (BFS) or Depth-First Search (DFS) to track level-specific information. It’s a great problem for discussing the trade-offs between BFS (which naturally processes level by level) and DFS (which requires tracking the maximum depth found so far).
This follows the Breadth-First Search, Depth-First Search, Binary Tree interview pattern.
Tree:
1
/
2 3
/ \
4 5 6
/
7
For problems involving "the last level" or "all nodes at depth X," BFS is almost always more intuitive. It avoids the need to maintain global state or reset variables as you would in DFS.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Maximum Level Sum of a Binary Tree | Medium | Solve | |
| Print Binary Tree | Medium | Solve | |
| Maximum Width of Binary Tree | Medium | Solve | |
| Find Bottom Left Tree Value | Medium | Solve | |
| Reverse Odd Levels of Binary Tree | Medium | Solve |