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 number of testcases T. For each testcase, there will be two lines, first of which containing the number of edges (between two nodes) in the tree. Next line contains N pairs (considering a and b) with a 'L' (means node b on left of a) or 'R' (means node b on right of a) after a and b.
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 L 7 9 R 10 15 R 15 11 L
10 7 L 7 5 L 10 15 R 15 11 L
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.