Given a binary tree, count number of nodes in it. For example, count of nodes in below tree is 4.
Your task is to complete the function getSize() which accepts root node of the tree, and returns the size.
The input line contains T, denoting the number of testcases. Each testcase contains two lines. The first line contains E, number of edges. The second line contains E+1 nodes of the binary tree separated by space. The left and right nodes of tree are referred as such 1 2 L 1 3 R i.e 2 is left of 1 and 3 is right of 1.
For each testcase in new line, print the number of nodes.
Since this is a functional problem you don't have to worry about input, you just have to complete the function getSize().
1 <= T <= 30
1 <= E <= 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
Testcase 1: First case represents a tree with 3 nodes and 2 edges where root is 1, left child of 1 is 2 and right child of 1 is 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.