Find Bottom Left Tree Value

MediumTreeslevel order

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Given the root of a non-empty binary tree, return the value of the **leftmost node on the deepest level**. The deepest level is the one farthest from the root; among the nodes on that level, pick the one that appears first when the level is read from left to right. Note that this node need not be a left child. If the deepest level has a single node that is a right child, that node is the answer. A level-order traversal solves this in O(n) time.

Examples

Input: root = [2,1,3]
Output: 1
The deepest level holds 1 and 3; 1 is leftmost.
Input: root = [1,2,3,4,null,5,6,null,null,7]
Output: 7
The deepest level contains only 7.
Input: root = [1,null,2]
Output: 2
The only node on the deepest level is the right child 2.

Constraints

  • 1 <= number of nodes <= 10^4
  • -2^31 <= Node.val <= 2^31 - 1
  • Values may repeat

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More level order problems