Depth of a Level-Order Tree
A binary tree is given as a level-order array tree. Missing children are written as null, and children of a missing node are not listed at all. For example [3,9,20,null,null,15,7] is a root 3 with children 9 and 20, where 20 has children 15 and 7.
Return the depth of the tree: the number of nodes on the longest path from the root down to a leaf. An empty tree has depth 0.
Example 1
Input: tree = [3,9,20,null,null,15,7] Output: 3
Example 2
Input: tree = [1,null,2] Output: 2
Constraints
- 0 <= number of nodes <= 10^4
- -100 <= node value <= 100
Hint 1
Rebuild the tree with a queue: each real node takes the next two entries of the array as its children.
Hint 2
Then count levels with a breadth-first search, or recurse with depth = 1 + max(left, right).
Good practice for: Backend Developer, Full Stack Developer, Frontend Developer, Game Developer, Database Administrator
Run checks your code on 3 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.