Maximum Depth of Binary Tree

EasyTrees
Next
TreeDFSRecursion

Find the maximum depth of a binary tree: the number of nodes along the longest path from the root down to the farthest leaf. Build the tree from the level-order input yourself, then solve the problem.

Input

A single line giving the tree in level order, with the word null for a missing child (for example 3 9 20 null null 15 7).

Output

Print the maximum depth.

Constraints

1 <= number of nodes <= 10^4

Example 1
Input
3 9 20 null null 15 7
Output
3

The longest path is 3 -> 20 -> 15, which has 3 nodes.

Hints

Maximum Depth of Binary Tree - Easy Trees Problem | Skill Shiksha