Count Complete Tree Nodes

Given a complete binary tree, A, find the total number of nodes in the tree.


Input Format:

The first and the only argument of input contains a reference to the root of the complete binary tree.

Output Format:

Return an integer representing the number of nodes in the complete binary tree.

Constraints:

1 <= Number of nodes in the binary tree <= 1e5

Examples:

Input 1:
    
        1
       / \
      2   3

Output 1:
    3

Input 2:

        1
       / \
      2   3
     / \
    4   5

Output 2:
    5
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Count Complete Tree Nodes on Interview Code Editor
Sign Up
to access hints and editorial solutions for Count Complete Tree Nodes

Discussion


Loading...
Click here to start solving coding interview questions