Given a Binary Tree, write a function to check whether the given Binary Tree is a prefect Binary Tree or not. A Binary tree is Perfect Binary Tree in which all internal nodes have two children and all leaves are at same level.
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the number of edges of the tree. The next line contains the edges of the tree.
Print "Yes" (without quotes) if the binary tree is perfect binary tree.
Print "No" (without quotes) if the binary tree is not a perfect binary tree.
1<=data of node<=10^5
10 20 L 10 30 R 20 40 L 20 50 R 30 60 L 30 70 R
18 15 L 18 30 R
1 2 L 2 4 R 1 3 R 3 5 L 3 6 R
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.