Is This a Binary Search Tree?

  • + 1 comment

    Getting ""Error: Could not find or load main class Solution"" error for the below Java 8 code. The same code runs in IntelliJ.

     boolean checkBST(Node root) {
            return checkBST(root, Long.MIN_VALUE, Long.MAX_VALUE);
        }
    
        boolean checkBST(Node root, long minVal, long maxVal){
            if (root == null)
                return true;
            if (root.data >= maxVal || root.data <= minVal)
                return false;
            return checkBST(root.left, minVal, root.data) && checkBST(root.right, root.data, maxVal);
        }