Ctrl K

Sum of the Bottom Level

Medium
You get the root of a binary tree. Find the nodes that lie farthest from the root and return the sum of their values.
Example 1
root=tree_node([3, 9, 20, None, None, 15, 7]) → 22

The deepest level is level 2, holding 15 and 7. Their sum is 22.

Example 2
root=tree_node([4, None, 8, 2, 5]) → 7

The root has only a right child 8, whose children are 2 and 5. They are the deepest: 2 + 5 = 7.

Example 3
root=tree_node([10]) → 10

The only node is the deepest level by itself.

Constraints
  • The tree has between 1 and 10⁴ nodes
  • 1 ≤ Node.val ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Tree Seen From the Right MediumTree Columns, Top Down MediumFirst Value on the Lowest Row MediumLargest Value on Each Tree Level MediumInsert a Tree Level Medium
loading Python…
Input
root=tree_node([3, 9, 20, None, None, 15, 7])
Expected
22

Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.