#K75827. Full Binary Tree Check

    ID: 34506 Type: Default 1000ms 256MiB

Full Binary Tree Check

Full Binary Tree Check

Given the level order traversal of a binary tree (using (-1) to indicate a null node), determine whether the tree is a full binary tree. A full binary tree is defined as a binary tree in which every node has either 0 or 2 children.

Input is provided as an integer (n) followed by (n) integers representing the tree in level order. If the tree is empty (or the first element is (-1)), it is considered a full binary tree. Output the string "Yes" if the tree is full, otherwise output "No".

inputFormat

The first line contains an integer (n), the number of elements in the level order traversal. The second line contains (n) space-separated integers representing the nodes of the tree in level order. A value of (-1) indicates a null node.

outputFormat

Output a single line with the string "Yes" if the given tree is a full binary tree; otherwise, output "No".## sample

7
1 2 3 4 5 6 7
Yes