Given a binary tree, check if the tree can be folded or not. A tree can be folded if left and right subtrees of the tree are structure wise same. An empty tree is considered as foldable.
First line of input contains the number of test cases T. For each test case, there will be only a single line of input which is a string representing the tree as described below:
The values in the string are in the order of level order traversal of the tree where, numbers denotes node values, and a character “N” denotes NULL child.
For the above tree, the string will be: 1 2 3 N N 4 6 N 5 N N 7 N
Print "Yes" (without quotes) if the tree is foldable and "No" ( without quotes) if it is unfoldable.
The task is to complete the function isFoldable() that takes root of the tree as input and returns true or false.
1 <= T <= 100
1 <= n <= 103
1 <= data of node <= 104
10 7 15 N 9 11 N
10 7 15 5 N 11 N
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.