#C5560. Balanced Binary Tree Checker
Balanced Binary Tree Checker
Balanced Binary Tree Checker
In this problem, you are given the level order representation of a binary tree, where each node's value is provided as a string and the special token (\texttt{null}) indicates a missing node. Your task is to determine whether the binary tree is height-balanced. A binary tree is said to be height-balanced if for every node, the absolute difference between the height of its left subtree and right subtree is at most 1.
The level order input is given as a space-separated string. If the input is empty, it represents an empty tree which is considered balanced.
You are required to read the input from standard input and output the result (either True
or False
) to standard output.
inputFormat
The input consists of a single line containing a space-separated list of tokens representing a binary tree in level order. Each token is either an integer or the string null
indicating an absent node. For example: 3 9 20 null null 15 7
.
outputFormat
Output a single line with either True
if the binary tree is height-balanced or False
otherwise.## sample
3 9 20 null null 15 7
True
</p>