Given a binary tree, find the depth of the shallowest leaf node. A leaf is a node with no children, and depth is measured as the number of edges from the root to that leaf (so the root alone has depth 0).
Use a level-order (BFS) traversal so that as soon as the first leaf is encountered, its depth is returned without exploring deeper levels.
Input
root: the root node of a binary tree, given in level-order array form where null marks a missing child
Output
The minimum depth as an integer.
Examples
Example 1
Inputroot = [1, 2, 3]
Output1
Explanation: Both children of the root are leaves at depth 1, so the shallowest leaf depth is 1.
Example 2
Inputroot = [1, 2, 3, 4, 5, null, 6]
Output2
Explanation: Node 3 has only a right child (6), so 3 is not a leaf. Nodes 4, 5, and 6 are leaves at depth 2.
Example 3
Inputroot = [1]
Output0
Explanation: The root itself is a leaf, so the minimum depth is 0.
Constraints
The tree contains at least one node.
A node is a leaf only when both its left and right children are null.