#include <bits/stdc++.h>
using
namespace
std;
struct
Node
{
Node *left, *right;
int
val;
};
Node *newNode(
int
val)
{
Node *temp =
new
Node();
temp->val = val;
temp->left = temp->right = NULL;
return
temp;
}
int
maxPathLenUtil(Node *root,
int
prev_val,
int
prev_len)
{
if
(!root)
return
prev_len;
int
cur_val = root->val;
if
(cur_val == prev_val+1)
{
return
max(maxPathLenUtil(root->left, cur_val, prev_len+1),
maxPathLenUtil(root->right, cur_val, prev_len+1));
}
int
newPathLen = max(maxPathLenUtil(root->left, cur_val, 1),
maxPathLenUtil(root->right, cur_val, 1));
return
max(prev_len, newPathLen);
}
int
maxConsecutivePathLength(Node *root)
{
if
(root == NULL)
return
0;
return
maxPathLenUtil(root, root->val-1, 0);
}
int
main()
{
Node *root = newNode(10);
root->left = newNode(11);
root->right = newNode(9);
root->left->left = newNode(13);
root->left->right = newNode(12);
root->right->left = newNode(13);
root->right->right = newNode(8);
cout <<
"Maximum Consecutive Increasing Path Length is "
<< maxConsecutivePathLength(root);
return
0;
}