Given a binary tree, count number of nodes in it. For example, count of nodes in below tree is 4.

1

/ \

10 39

/

5

Your task is to complete the function **getSize()** which accepts root node of the tree, and returns the size.

**Input:**

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.

**Output:**

For each testcase in new line, print the number of nodes.

**User Task:**

Since this is a functional problem you don't have to worry about input, you just have to complete the function **getSize()**.

**Constraints:**

1 <= T <= 30

1 <= E <= 100

1 <= Data of a node <= 1000

**Example:
Input:**

2

2

1 2 L 1 3 R

4

10 20 L 10 30 R 20 40 L 20 60 R

**Output:**

3

5

**Explanation:
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.

vamsikrishna55 | 162 |

Vagesh Verma | 158 |

UrGuru | 133 |

abducodes | 127 |

Akhil varma | 114 |

abducodes | 683 |

harshtyagi36 | 322 |

Akhil varma | 267 |

arpit_anshuman | 258 |

highway_to_hell | 252 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.