#K9701. Symmetric Binary Tree

    ID: 39088 Type: Default 1000ms 256MiB

Symmetric Binary Tree

Symmetric Binary Tree

Given a binary tree represented in level order as a list of integers (with -1 indicating a null node), determine if the tree is symmetric around its center. A tree is symmetric if it is a mirror of itself, i.e., for every node, the left subtree is a mirror reflection of the right subtree. In mathematical notation, a binary tree T is symmetric if:

isMirror(T,T)=true\text{isMirror}(T, T) = \text{true}

Note: The tree is constructed using the indexing scheme where for a node at index (i), its left child is at (2i+1) and right child at (2i+2).

inputFormat

Input is provided via a single line from standard input containing space-separated integers. These integers represent the level order traversal of the binary tree, where -1 marks a null node. An empty input indicates an empty tree.

outputFormat

Output a single line to standard output containing either 'True' or 'False'. 'True' should be printed if the binary tree is symmetric; otherwise, 'False'.## sample

1 2 2 3 4 4 3
True