#C4817. Maximum Depth of a Binary Tree
Maximum Depth of a Binary Tree
Maximum Depth of a Binary Tree
Given the root of a binary tree, determine its maximum depth. The maximum depth is defined as the number of nodes along the longest path from the root node down to the farthest leaf node.
You are provided with the tree in level-order format, where the special value null
represents an absent child node. For example, the input 3 9 20 null null 15 7
represents the binary tree below:
3 / \ 9 20 / \ 15 7
The maximum depth of this tree is \(3\), since the longest root-to-leaf path is: 3 \(\to\) 20 \(\to\) 15 (or 7).
inputFormat
The input is a single line containing a sequence of values separated by spaces. These values represent the nodes of the binary tree in level-order. Use the keyword null
to denote a missing node. For example: 3 9 20 null null 15 7
.
Input is provided via standard input (stdin).
outputFormat
Output a single integer representing the maximum depth of the binary tree. The answer should be printed to standard output (stdout).
## sample3 9 20 null null 15 7
3