Given a Binary Tree, find diameter of it.
+The diameter of a tree is the number of nodes on the longest path between two leaves in the tree. The diagram below shows two trees each with diameter nine, the leaves that form the ends of a longest path are shaded (note that there is more than one path in each tree of length nine, but no path longer than nine nodes).
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 the relation between nodes.
For each testcase, in a new line, print the diameter.
You need to complete the function diameter() that takes node as parameter and returns the diameter.
1 <= T <= 30
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
The diameter is of 3 length.
Testcase2: The tree is
The diameter is of 4 length.
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.