Ctrl K

First Value on the Lowest Row

Medium
You are given the root of a non-empty binary tree. Find the lowest level of the tree (the one farthest from the root) and return the value of the leftmost node on it. Note that this node does not have to be a left child: you need the leftmost node of the last level, whatever its parent.
Example 1
root=tree_node([10, 4, 7, None, 2, 9, 1]) → 2

The lowest level is 2, 9, 1. The leftmost of them is 2, even though it is the right child of 4.

Example 2
root=tree_node([5, 3, 8, None, None, 6, None, -4]) → -4

The deepest level holds a single node, -4 (5 → 8 → 6 → -4), so that is the answer.

Example 3
root=tree_node([42]) → 42
Constraints
  • 1 ≤ number of nodes ≤ 10⁴
  • -2³¹ ≤ Node.val ≤ 2³¹ - 1
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 MediumLargest Value on Each Tree Level MediumInsert a Tree Level MediumA Tree Drawn on a Grid Medium
loading Python…
Input
root=tree_node([10, 4, 7, None, 2, 9, 1])
Expected
2

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