#K40377. Balanced Binary Tree Check
Balanced Binary Tree Check
Balanced Binary Tree Check
Given a binary tree, determine whether it is height-balanced. A binary tree is balanced if for every node, the absolute difference between the height of its left subtree and its right subtree is at most \(1\), i.e., \(|h_L - h_R| \le 1\). The tree is provided in level order traversal, and missing nodes are indicated by the keyword null
.
Your task is to decide if the given tree is balanced.
inputFormat
The input is a single line containing the level order traversal of the binary tree. Node values are separated by spaces, and the keyword null
represents missing nodes.
Example: 3 1 5 null 2 4 6
outputFormat
Output true
if the tree is balanced, otherwise output false
.
1
true
</p>