#C5023. Balanced Binary Tree Checker
Balanced Binary Tree Checker
Balanced Binary Tree Checker
Given a binary tree represented in level order as a list of node values, determine if the tree is balanced. A binary tree is considered balanced if for every node, the height difference between its left and right subtrees is at most 1. In mathematical terms, for every node, \( |h_{left} - h_{right}| \leq 1 \).
The tree is provided as space-separated values where 'null' signifies a missing node. An empty input corresponds to an empty tree, which is considered balanced.
inputFormat
The input is given via standard input as a single line containing space-separated node values representing the binary tree in level order. Use the literal 'null' (case-sensitive) for missing nodes. An empty input indicates an empty tree.
outputFormat
Output a single line to standard output: 'True' if the binary tree is balanced, otherwise 'False'.## sample
3 9 20 null null 15 7
True