Trees: Is This a Binary Search Tree?

Sort by

recency

|

803 Discussions

|

  • + 0 comments

    Missing stubs for all Java variants

  • + 0 comments

    include // for INT_MIN and INT_MAX

    // Helper function to check the BST condition bool checkBSTUtil(Node* root, long long minVal, long long maxVal) { // Base case: If the node is null, it's a valid BST by definition if (root == nullptr) { return true; }

    // Check if the current node's value is within the valid range
    if (root->data <= minVal || root->data >= maxVal) {
        return false;
    }
    
    // Recursively check the left and right subtrees
    return checkBSTUtil(root->left, minVal, root->data) && 
           checkBSTUtil(root->right, root->data, maxVal);
    

    }

    // Function to check if a tree is a BST bool checkBST(Node* root) { return checkBSTUtil(root, LONG_MIN, LONG_MAX); }

  • + 0 comments

    C# bugged as well. There's no internal methods to process the BST so, if we do it ourselves is going to be properly constructed in all cases, but then it will fail the test cases.

  • + 0 comments

    C# bugged as well. There's no internal methods to process the BST so, if we do it ourselves is going to be properly constructed in all cases, but then it will fail the test cases.

  • + 0 comments

    C# bugged as well. There's no internal methods to process the BST so, if we do it ourselves is going to be properly constructed in all cases, but then it will fail the test cases.