Sunday, May 9, 2021

GEEKSFORGEEKS SOLUTIONS

 CHECK FOR BST

REFER

bool isBSTUtil(Node* root, int min, int max){

        if(root == NULL)

            return true;

        if(root->data < min || root->data > max)

            return false;

        return isBSTUtil(root->left, min, root->data-1) && isBSTUtil(root->right, root->data+1, max);

    }

    bool isBST(Node* root) 

    {

        return isBSTUtil(root, INT_MIN, INT_MAX);

    }

No comments:

Post a Comment

LEETCODE JUNE 2021 DAILY CODING CHALLENGE

 LEETCODE JUNE 2021 DAILY CODING CHALLENGE JUNE 1 JUNE 2 JUNE 3 JUNE 4 JUNE 5 Maximum Performance of a Team LINK You are given two integers ...