#K59107. Symmetric Binary Tree

    ID: 30791 Type: Default 1000ms 256MiB

Symmetric Binary Tree

Symmetric Binary Tree

You are given a binary tree represented by its level-order traversal. In the input, the nodes of the tree are provided as space-separated values and the character 'N' denotes a null node. An empty string represents an empty tree. The tree is said to be symmetric if its left subtree is a mirror reflection of its right subtree. Formally, a binary tree T is symmetric if and only if

T=mirror(T)T = \text{mirror}(T)

Your task is to determine whether the given tree is symmetric. This problem tests your understanding of tree data structures and recursive algorithms.

inputFormat

The first line of input contains an integer T representing the number of test cases. Each of the following T lines contains a string representing the level-order traversal of a binary tree. Each node value is separated by a space and 'N' represents a null node. Note that an empty string represents an empty tree.

outputFormat

For each test case, output a single line containing either 'Yes' if the tree is symmetric or 'No' otherwise.## sample

5
1 2 2 3 4 4 3
1 2 2 N 3 N 3
1 2 2
1 N N

Yes

No Yes Yes Yes

</p>