Given a binary tree, find height of it.
The above tree has a height of 3.
Note: Height of empty tree is considered 0.
The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains number of edges. The second line contains relation between nodes.
For each testcase, in a new line, print the height of tree.
You don't have to take input. Complete the function height() that takes node as parameter and returns the height.
1 <= T <= 100
1 <= Number of nodes <= 100
1 <= Data of a node <= 1000
1 2 L 1 3 R
10 20 L 10 30 R 20 40 L 20 60 R
Testcase1: The tree is
So, the height would be 2.
Testcase2: The tree is
So, height would be 3.
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.