#C9349. Binary Tree Height Calculation
Binary Tree Height Calculation
Binary Tree Height Calculation
You are given a binary tree represented in level order traversal. Each node's value is provided as a token in a single line, separated by spaces. The special token null
indicates that there is no node present at that position. An empty input represents an empty tree.
Your task is to compute the height of the binary tree. The height \(H\) is defined as the number of nodes on the longest path from the root to a leaf. Formally, if the tree is empty then \(H=0\), otherwise \(H = \max(H_{left}, H_{right}) + 1\), where \(H_{left}\) and \(H_{right}\) are the heights of the left and right subtrees respectively.
Input is read from standard input and output should be written to standard output.
inputFormat
The input consists of a single line of space-separated tokens representing the level order traversal of the binary tree. Use the token null
for missing nodes. An empty line means the tree is empty.
outputFormat
Output a single integer representing the height of the binary tree.
## sample
0