#K9471. Symmetric Binary Tree Checker
Symmetric Binary Tree Checker
Symmetric Binary Tree Checker
Given the level order traversal of a binary tree, determine whether the tree is symmetric. A binary tree is symmetric if it is a mirror image of itself. Use the special marker (-1) to denote null nodes. In mathematical terms, a tree is symmetric if for every pair of nodes (t_1) and (t_2) the following holds:
$$S(t_1, t_2) = \Bigl( t_1.val = t_2.val \Bigr) \wedge S(t_1.left, t_2.right) \wedge S(t_1.right, t_2.left) $$An empty tree is considered symmetric.
inputFormat
The first line contains an integer (N) representing the number of elements in the level order traversal (including null markers). The second line contains (N) space-separated integers representing the node values. A value of -1 indicates a null node.
outputFormat
Output a single line containing "Yes" if the binary tree is symmetric, otherwise output "No".## sample
7
1 2 2 3 4 4 3
Yes