#C7484. Binary Tree Single Child Checker
Binary Tree Single Child Checker
Binary Tree Single Child Checker
Given a binary tree, determine whether every internal node has exactly one child. An internal node is defined as a node that has at least one child. In this problem, for any node, if both the left and right children exist, i.e. (left \neq null ) and (right \neq null ), then the condition is violated. Otherwise, if every internal node has exactly one child (or if the tree is empty or contains a single node), output 'Yes'; if any internal node has two children, output 'No'.
inputFormat
Input is provided as a single line representing the level order traversal of the binary tree. Each token is either an integer (representing a node's value) or 'N' (indicating a missing/null node). For example, the input "10 5 N 1" corresponds to a tree with root 10, a left child 5 (which in turn has a left child 1), and no right child.
outputFormat
Output a single line containing either 'Yes' if every internal node in the binary tree has exactly one child, or 'No' otherwise.## sample
10 5 N 1
Yes