381. Minimum Depth
EasyBFS
Print the number of nodes on the shortest path from the root to a leaf (a node with no children).
Input format
Line 1: n (number of level-order entries) Line 2: the values in level order, -1 for a missing child
Output format
The minimum depth.
Example 1
Input
7 3 9 20 -1 -1 15 7
Output
2
Example 2
Input
9 2 -1 3 -1 4 -1 5 -1 6
Output
5
Constraints
1 ≤ nodes ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…