871. Find the Deepest Left Leaf Node

EasyTreesBinary TreeDFSBFS

Given the root of a binary tree, return the value of the deepest leaf node that is also a left child. If there is no such node, return -1. The tree is given as a level-order array with null for missing children.

Input: A level-order array of the tree.

Output: Integer — the deepest left-leaf value, or -1.

Examples

Example 1
Input: [1,2,3,4,null,5,6,null,7]
Output: 5
Explanation: 5 is the deepest left-child leaf.
Example 2
Input: [1]
Output: -1
Explanation: Root is not a left child.
Example 3
Input: [1,2,3]
Output: 2
Explanation: 2 is a left-child leaf.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →