InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

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.


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


Input 1:
       / \
      2   3

Output 1:

Input 2:

       / \
      2   3
     / \
    4   5

Output 2:
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


Click here to start solving coding interview questions