Maximum Depth of N-ary Tree

Easy

Description

Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Examples

Input:root = [1,null,3,2,4,null,5,6]
Output:3
Explanation:

Three levels deep.

Input:root = []
Output:0
Explanation:

Empty tree has no nodes, so the maximum depth is 0.

Input:root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10]
Output:4
Explanation:

The tree has 4 levels: root node 1 at level 1, nodes 2,3,4,5 at level 2, nodes 6,7,8 at level 3, and nodes 9,10 at level 4.

Constraints

  • 0 ≤ nodes ≤ 10⁴

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!