void test() {
    int A[] = {1,3,5,-1,5,-1,-6,2,3,-4,9,-1,1,9,-1,7,5,0,8,-7,9,-2,-1,7};
    std::vector<int> input(A, A + sizeof(A) / sizeof(int));
    print(input.begin(), input.end());
    std::cout<<std::endl;

    std::cout<<longestConsecutive(input)<<std::endl;
}
 int longestConsecutive(TreeNode* root, int& maxlen) {
     int llen, rlen, currlen = 1;
     if (!root) return 0;
     if (!root->left && !root->right) {
         maxlen = max(maxlen, 1);
         return 1;
     }
     if (root->left) {
         llen = longestConsecutive(root->left, maxlen);
         if (root->val == root->left->val - 1) {
             currlen = max(currlen, llen+1);
         }
     }
     if (root->right) {
         rlen = longestConsecutive(root->right, maxlen);
         if (root->val == root->right->val - 1) {
             currlen = max(currlen, rlen+1);
         }
     }
     maxlen = max(maxlen, currlen);
     return currlen;
 }
void unitTestLongestConsecutive()
{
    {
        std::cout << "Length of consequetive: " << longestConsecutive({0, -1}) << "\n";
    }
//
//    {
//        std::cout << "Length of consequetive: " << longestConsecutive({-3,2,8,5,1,7,-8,2,-8,-4,-1,6,-6,9,6,0,-7,4,5,-4,8,2,0,-2,-6,9,-4,-1}) << "\n";
//    }

//    {
//        std::cout << "Length of consequetive: " << longestConsecutive({1,3,5,2,4}) << "\n";
//    }
//    {
//        std::cout << "Length of consequetive: " << longestConsecutive({1,2,0,1}) << "\n";
//    }
//    {
//        std::cout << "Length of consequetive: " << longestConsecutive({100, 4, 200, 1, 3, 2}) << "\n";
//    }
}
int main()
{
	vector<int> num = {100,4,200,1,3,2};
	cout << longestConsecutive(num) << endl;
}
 int longestConsecutive(TreeNode* root) {
     int maxlen = 0;
     longestConsecutive(root, maxlen);
     return maxlen;
 }
        void Main()
        {
			print(longestConsecutive(createVector({ 100, 4, 200, 1, 3, 2 })));
        }