Find Bottom Left Tree Value

Medium Topics Company Tags

Find the deepest level of the binary tree and return the value of the leftmost node on that level. A node's depth is the number of edges from the root, so the root has depth 0. The answer depends on position, not on which value is numerically smallest.

Examples use level-order arrays. After the root, each present node contributes left and right child entries in queue order. null marks a missing child, and trailing missing entries may be omitted.

Example 1:

Find Bottom Left Tree Value, example 1: illustration of the example

Input: root = [8,6,2,9,null,1,0]

Output: 9

Explanation: The deepest row contains [9,1,0]. Its leftmost value is 9, even though the other values are smaller.

Example 2:

Find Bottom Left Tree Value, example 2: illustration of the example

Input: root = [4,null,7,3,5]

Output: 3

Explanation: The deepest row contains [3,5], both in the root's right subtree. The leftmost node on that row has value 3.

Example 3:

Find Bottom Left Tree Value, example 3: illustration of the example

Input: root = [-2]

Output: -2

Explanation: The root is the only node, so it is also the leftmost node on the deepest level.

Constraints:

  • The tree contains between 1 and 10000 nodes.
  • -2147483648 <= Node.val <= 2147483647


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.