#include <bits/stdc++.h>
/*************************************************************
Following is the Binary Tree node structure
class BinaryTreeNode {
public :
T data;
BinaryTreeNode<T> *left;
BinaryTreeNode<T> *right;
BinaryTreeNode(T data) {
this -> data = data;
left = NULL;
right = NULL;
}
};
*************************************************************/
int findlefthight(BinaryTreeNode<int>* node){
int hight = 0;
while(node){
hight++;
node = node->left;
}
return hight;
}
int findrightheight(BinaryTreeNode<int>* node){
int hight = 0;
while(node){
hight++;
node = node->right;
}
return hight;
}
int countNodes(BinaryTreeNode<int> *root) {
// Write your code here.
if(root == NULL)
return 0;
int lh = findlefthight(root);
int rh = findrightheight(root);
if(lh == rh) return (1<<lh)-1 ;
int leftNodes = countNodes(root->left);
int rightNodes = countNodes(root->right);
return 1 + leftNodes + rightNodes;
}