Given a binary tree of size N, you have to count number of nodes in it. For example, count of nodes in below tree is 4.
First line of input contains the number of test cases T. For each test case, there will be only a single line of input which is a string representing the tree as described below:
The values in the string are in the order of level order traversal of the tree where, numbers denote node values, and a character “N” denotes NULL child.
For the above tree, the string will be: 1 2 3 N N 4 6 N 5 N N 7 N
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 <= N <= 104
1 2 3
10 5 9 N 1 3 6
Testcase 2: Given Tree is :
\ / \
1 3 6
There are six nodes in the tree .
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes