Cracking the Coding Interview: Trees – Is This a Binary Search Tree?

Here’s my solution to the challenge: https://www.hackerrank.com/challenges/ctci-is-binary-search-tree

bool isBST(Node* node, int min, int max) {
    if(node == NULL)
        return true;
    if(node->data data > max)
        return false;
    return isBST(node->left, min, node->data-1) && isBST(node->right, node->data+1, max);
}

bool checkBST(Node* root) {
    return isBST(root, INT_MIN, INT_MAX);
}

All my solutions to HackerRank challenges can be found here: https://github.com/sdulaney/hackerrank

Leave a Comment