#K53692. 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 is considered symmetric if the left subtree is the mirror reflection of the right subtree. Formally, a binary tree is symmetric if for every node, the left subtree is a mirror of the right subtree, i.e. $$L = mirror(R)$$ where (L) and (R) denote the left and right subtree respectively. Missing nodes are represented by the string null
. Your task is to determine whether the input binary tree is symmetric and output True
if it is, or False
otherwise.
Example:
For the input 1 2 2 3 4 4 3
(which corresponds to the binary tree below):
1 / \ 2 2 / \ / \ 3 4 4 3
The output should be True
.
inputFormat
The input is given as a single line from standard input (stdin) containing the level order traversal of the binary tree. Node values are separated by spaces, and the string null
is used to denote an absent child. An empty input indicates an empty tree.
outputFormat
Output a single line to standard output (stdout): True
if the binary tree is symmetric, and False
otherwise.## sample
1 2 2 3 4 4 3
True
</p>