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.

agness | 122 |

aman1931998 | 102 |

Survivor | 100 |

uchitnitk | 96 |

lonecoder | 95 |

KshatriyaYash | 1066 |

nikhil_sojan | 1032 |

lonecoder | 1030 |

mazumderrohit8 | 899 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4492 |

Quandray | 4444 |

Login to report an issue on this page.