I am not able to find what is the problem in my code, it passes 52 out of 52 cases and fails for a big tree with many nodes. Anyone, please help me if time permits. Thanks.

```
int longestConsecutive(TreeNode* root) {
if (!root)
return 0;
int left = 1, right = 1;
if (root->left)
left = (root->val + 1 == root->left->val) + longestConsecutive(root->left);
if (root->right)
right = (root->val + 1 == root->right->val) + longestConsecutive(root->right);
return max(left, right);
}
```