#K38152. Symmetric Binary Tree Check
Symmetric Binary Tree Check
Symmetric Binary Tree Check
You are given a binary tree represented in level-order traversal. The tree nodes are provided as a sequence of values where the value null
represents an absent node.
Your task is to determine if the tree is symmetric. A binary tree is symmetric if the left subtree is a mirror reflection of the right subtree. Formally, a tree is symmetric if for every node, the following condition holds:
\( \text{isMirror}(L,R) = (L.val = R.val) \land \text{isMirror}(L.left,R.right) \land \text{isMirror}(L.right,R.left) \)
Note: An empty tree is considered symmetric.
inputFormat
The input is read from standard input (stdin) as a single line containing space-separated tokens representing the level-order traversal of the binary tree. Each token is either an integer or the string null
(without quotes) representing a missing node.
For example: 1 2 2 3 4 4 3
outputFormat
Print to standard output (stdout) a single line: true
if the tree is symmetric, or false
if it is not.
1 2 2 3 4 4 3
true